Automatic removal of `<div></div>`

Regarding the divs

You can use the “Find & Replace” function in the browser to remove these empty divs.

Cleaning up with Regex

To clean up monsters like the one in your image, regular expressions will not be as good as a proper Python script / parser. But you could try anyways:

Since Anki’s Regular Expression engine doesn’t support recursion like (<div>)(?R)?(<\/div>) (Perl syntax), you would risk unmatched tags with this regular expression:
<div>(<div>|<\/div>)*<\/div>

You could test this on a single note and see if it’s worth risking some side effects.

With the current version of Anki, these empty divs should not appear as often anymore, because Enter no longer inserts <div></div>:

Regarding non-breaking-spaces

I can reliably reproduce the insertion of &nbsp; by copy-pasting formatted content in the editor:

It doesn’t matter whether you paste it between different fields or into the same one. I’d really appreciate this getting fixed.

How to clean up non-breaking-spaces

In the meantime @aPaci, you can select all notes with Ctrl+A and (again) use the “Find & Replace” feature like this:


Related post

Anki inserts erroneous non-breaking spaces when pasting from clipboard

6 Likes