Words bugging when i search and replace

For example i have this card:

If i try to search and replace like this, in order to convert every “-” that isn’t the first sentence to an unordered list

This is what i get

The text bugs inside the editor, and when i try to open the field thml through shift+windows+x it doesn’t show the bugged words at all

Then when i exit from the html editor the bugged words disappear

There’s a lot of reasons this could never work.
If you want to create lists, consider using this add-on.


Thank you for you answer, maybe i didn’t expressed myself well… i already have that addon installed; the problem is that i have a lot of cards made like this

" - list"
" - list"
" - list"

instead of

  • list
  • list
  • list

so what i’m trying to do is replacing every " - " with a “< li>” but i get this weird bug


What you’re trying to do is simply technically and logically impossible. To explain it in more detail: Search terms are restricted to the strength of a regular language. However HTML with its hierarchical structure is a context-free language. Parsing a context-free language with regular terms is impossible.

Other complicating factors, which even make a best-attempt solution impossible:

  1. <li> must be closed by another </li>
  2. All <li> elements are encapsulated by another <ul>
  3. Anki uses a mixture of <div> and <br>

TLDR; I’m afraid you’re going to have to do it by hand, or leave it like it is.

1 Like

I somewhat disagree. In theory @hengiesel is right, but if the HTML in your notes is strictly limited and you know exactly what to expect, you might well achieve your goal with simple regex.
However, I think the main issue here is the broken GUI shown in screenshots 3 and 4. Looks like a case of insufficient escaping.
May I ask where the Guillemets come from, @aPaci?

1 Like

Thank you for your answer! I had the same worries so i run some experiments (as i have around 100.000 cards with this problem made in about 7 years, so fixing them by hand is impossibile).
As far as i saw, if i just replace every - with a <li> anki proceed to automatically add the </li> at the end of the line, which is fine, but this way i lose the formatting of the unordered list css because it lacks the <ul>. That said if i replace every - with a <ul><li> instead, it automatically adds the </li> at the end of the line, but it only add </ul> at the end of the whole field, leading to graphic bugs.
The best solution i found so far was to replace every </li></ul><ul><li> so that every new line also closes the previous one. I also tried various other solution that all works quite fine (apparently). The only problem is that every solution that works fine, also breaks the GUI.
In my opinion the GUI shouldn’t be influenced by the html inside the fields, so i considered this a bug and i though about reporting this here…
Anyway if you have other solutions to fix this problem (replacing - with unordered list) please feel free to suggest !

Thank you for your answer too, this is exactly what i was trying to say. Regarding the guillemets, i just inserted those to avoid the automatic conversion in a ⬤ here in the forum. I didn’t though about using the code tool so i just used " "

I was referring to the »-« etc. in your field names.

Can’t you first wrap the lines in <li> tags and wrap the blocks in <ul> tags later? What you want in the end is surely:


Doesn’t each line that you want to convert to a <li> element contain nested <div> tags? Aren’t there any characters other than whitespaces and newlines between the lines(e.g. <br>tag)? If so, I think you can achieve what you want by using a regular expression in two steps, as follows:

Example field data:

<div>- test1</div>
<div>- test2</div>
<div>- test3</div>
<div>- test4</div>

Find and replace (Regex):

  • 1st step:
    • Find: (<div>-[\s\S]+?</div>\s*)+
    • Replace with: <ul>$0</ul>
  • 2nd step:
    • Find: <div>- ([\s\S]+?)</div>
    • Replace with: <li>$1</li>



Demo GIF:

1 Like

Thank you very much… unfortunately it doesn’t work, probably because most of the cards are rich in highlighting, bold, ecc.
I managed to make it work deleting with search and replace before replacing - with <ul><li>
It “works” apparently even though the html is probably messed up. I would try to fix it but apparently the html updates only when i see it (if it makes sense): for example i was trying to replace every </li></ul><ul><li> with </li><li> to fix some graphic error, but the search and replace tools doesn’t update any note; but, if i open the html of a card, the </li></ul><ul><li> suddenly appear, and the search and replace tool start working (only with that card). If there was a way to “update” or “refresh” the html of every card, then i could use the replace tool to fix some errors, but apparently the refresh database function doesn’t do the trick, and i can’t think of opening the html of every field manually to make it “refresh”

1 Like

If <li> is not a requirement, <li> can be “imitated” by replacing

<div> -

with a bit smaller than <li> Unicode bullet point

<div> •

Unfortunately i styled the css for unordered lists so it would be a better solution to only use <ul><li>, but thank you very much anyway.
Do you perhaps know any way to forcibly update the html of the notes?
For example after search and replace, a lot of my cards show a messed up ui.

When i try to see where the error is in the HTML with ctrl + shift + x, everything looks fine and the card start to work normally again.
It looks like that the very fact of going to see the html triggers an auto-fix mechanism.
Is there a way to make this happen automatically on all cards and not only when I manually open the html source?

1 Like

I found this addon Fix Invalid Field HTML - AnkiWeb that seems to fix the problem. I’m currently testing it and I’ll let you know if it works! Thank you very much everyone

1 Like

Hi @aPaci, did the add-on fix your HTML?

Yes it worked!


Any chance you’d be willing to share the deck you were trying to fix? I’d like to use it in an integration test for something.