New lines removed when creating a note with url-scheme

Hello!, when a field contains new lines, using addnote url-scheme to create a note removes the new lines and replaces them with single space.

example of field value:

これは
例です

Swift string output: "これは\n例です"
Using .addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) to be able to add it as a fld query param in Anki’s addnote url-scheme:

"fldNotes=%E3%81%93%E3%82%8C%E3%81%AF%0A%E4%BE%8B%E3%81%A7%E3%81%99"

Checking if newlines are still there after transforming back to regular string by using “.removingPercentEncoding”:

▿ Optional<String>
  - some : "これは\n例です"

How it looks in the created note (new lines replaced by single space):
image

Should I encode the string in a different way? I am not sure if there is anything on my side I can do to get new lines in the fields.

Any help is welcomed! Thank you.

This is not related to the url-scheme at all. It’s simply that, in HTML, newlines are ignored (in plain text, that is). Instead, you need a <br>.

3 Likes

I see. I was always under the impression that the fields in the note builder were some kind of textarea. I did a quick test and adding <br/> tags added the new lines. Thank you!!

Edit: checking the ankimobile manual

Fields are entered by prefixing their name with "fld". So if your first field is called "Text", the key would be "fldText". The field text is interpreted as HTML, so if you wanted a newline in the text you’d use something like "line 1<br>line 2".

:man_facepalming::man_facepalming::man_facepalming: