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:
<li> must be closed by another </li>
All <li> elements are encapsulated by another <ul>
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.
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?
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 " "
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:
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”
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?
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