ijgnd / anki21__remove_linebreaks__do_word_wrap

2 stars 1 forks source link

trailing <br> not removed #2

Closed dspjm closed 2 years ago

dspjm commented 4 years ago

Cannot remove
when editing in browser.

ijgnd commented 4 years ago

For me it works as expected in the browser.

I need more details

dspjm commented 4 years ago

I just try it again and it works. However, the problem is it cannot remove the trailing
at the end of the field. I remember it used to remove that one, so is it changed that it won't remove the trailing
?

ijgnd commented 4 years ago

However, the problem is it cannot remove the trailing at the end of the field. I remember it used to remove that one, so is it changed that it won't remove the trailing ?

I don't have this problem with the code I process. Give some html source code where it doesn't work expected. I changed how this add-on works about a month ago which might explain why it works differently.

dspjm commented 4 years ago

However, the problem is it cannot remove the trailing at the end of the field. I remember it used to remove that one, so is it changed that it won't remove the trailing ?

I don't have this problem with the code I process. Give some html source code where it doesn't work expected. I changed how this add-on works about a month ago which might explain why it works differently.

Thanks. Try this "The Goldilocks Rule<br>" in the Front field.

ijgnd commented 4 years ago

I can confirm that the trailing "
" is not removed from a field with the content The Goldilocks Rule<br>

I haven't really looked into it but it doesn't seem like a quick fix. For me this trailing slash has no visual effect so I don't care about it at the moment.

Does it have a visual effect for you? show screenshots.

dspjm commented 4 years ago

Does it have a visual effect for you? show screenshots.

Well, it has an extra empty line between the questions and answers, and it may hide some notes I wrote in addition to looking wired. Because I basically copy from pdf, the trailing newline was always there, so I have to remove it by hand every time now. It would be great if this can be improved. Thanks.

dspjm commented 4 years ago

I am trying to work on the code myself, while I am not sure why line 56:

.replace(/<br>/g, ' ')

is not removing the trailing <br>?

dspjm commented 4 years ago

I think a fix can be

if (string.endsWith('<br>')))
string.slice(0, -4)

What do you think?

ijgnd commented 4 years ago

Thanks for looking into this. My js and html knowledge is very limited. So I have no idea why the regex you mentioned in your first post from today doesn't work. If the second post works that's great. I have no idea if there could be side effects etc. I suggest you test it for a week or two. If you don't run into any problems I could upload it to ankiweb.

ijgnd commented 2 years ago

at least since Anki 2.1.41 from 2021-03-07 a trailing <br> seems to be removed by my add-on with the existing code, version from 2022-09.