Replacing New lines in Text from Photo texts

Hi all,

I frequently use the new text from photo feature to capture text from books for later reference. Unfortunately this produces some kind of new lines where there are new lines in the original text:

I tried to get rid of them with the following JavaScript snippet:

newLine  = "\n"
replace  = " "

content = draft.content.replaceAll(newLine, replace)

content = draft.content.replaceAll("  ", " ")

draft.content = content

This works with texts where I inserted new lines by myself, but not with the pasted text from the photo. I also tested the \r escape sequence, it didn’t work.

Any ideas?

Thanks in advance!

Can’t help much— I’m holding off i(Pad)OS 15 until I hear that Shortcuts isn’t so buggy— but aren’t you overwriting the result of the first contents = ... statement with the one that immediately follows?

What happens if you chain those assignments? e.g.

content = draft.content.replaceAll(newLine, replace).replaceAll("  ", replace)
2 Likes

Thanks, that worked :+1:

1 Like