HTML editor modifies note when a field with break tags is opened

Opening the HTML editor for fields containing break tags marks a note as modified. Meanwhile, it can be observed that the text in the browser’s Sort Field column changes.
E.g., if the content of a note’s sort field is “foo<br>bar”, the column’s content is “foo bar”. However, after opening and closing the HTML editor, the column changes to “foobar”. It changes back to “foo bar” by itself after a while or immediately when another editor field is focused.

I could reproduce this behaviour on all versions I have installed (2.1.22 to 2.1.45).
Can it be resolved?

This issue may be related:

beautifulsoup is converting the <br> to a <br/>, and the regex was not handling this case. WebEngine converts it back to a <br> when a field is unfocused

1 Like

Thanks for the fix. The Sort Field column is now stable. Notes still are marked as modified just by opening and closing the HTML editor, though. Can this be fixed as well?
If you don’t know straightaway I can investigate myself. I only thought I’d ask first since this issue has existed for so long and you might already be aware of it. :slightly_smiling_face:

It might be worth seeing how Fix entities when checking databse · Issue #1087 · ankitects/anki · GitHub handles the br tags - if we can drop it in as a replacement for BeautifulSoup, then we’ll have a cross-platform solution.

rcdom is apparently not “production quality” though, so it may not make sense to use this for the DB check/arbitrary field input for now.