debanjandhar12 / logseq-anki-sync

An logseq to anki syncing plugin with superpowers - image occlusion, card direction, incremental cards, and a lot more.
GNU Affero General Public License v3.0
462 stars 34 forks source link

Anki card contains "<b>:-></b>" #238

Closed HeinzContiZacherl closed 10 months ago

HeinzContiZacherl commented 10 months ago

Describe the bug A clear and concise description of what the bug is: Anki card contains <b>:-></b> instead of :->

Steps to Reproduce: Steps to reproduce the behavior:

  1. On Logseq: create a card like this: Test Card in Logseq
  2. Export card to Anki
  3. See error: On Anki cards looks like this: image

Expected behavior A clear and concise description of what you expected to happen. On Anki cards should look like this: image

Developer console screenshot: Please add a screenshot of the error in logseq's developer console if applicable. Logseq's developer console can be accessed by pressing Ctrl + Shift + I.

Device Information (please complete the following information):

HeinzContiZacherl commented 10 months ago

Update: 19.12.23

The issue with "<b>:-></b>" appearing in Anki cards might stem from two factors. Firstly, in Logseq, ":->" is automatically converted to ":→", which could be happening before syncing with Anki, causing unexpected formatting. Secondly, there's an HTML code issue where HTML entities for bold tags are being rendered as actual tags. The problematic code is <span>Systemmonitor anzeigen&lt;b&gt;:-&gt;&lt;/b&gt; {{c1::<code>top</code>.}}</span>, which displays as "Systemmonitor anzeigen<b>:-></b> {{c1::top.}}". The solution is to remove the bold tag entities from the code, updating it to <span>Systemmonitor anzeigen:-&gt; {{c1::<code>top</code>.}}</span>, which should correctly display ":->" without bold formatting.

HeinzContiZacherl commented 10 months ago

Could it possibly be a solution to change add the following lines to your converter-code?

`// Render the markdown resultContent = Mldoc.export( "html", resultContent, JSON.stringify(mldocsOptions), JSON.stringify({}), );

// Replace ":→" with ":->" only if ":→" is present if (resultContent.includes(":→")) { resultContent = resultContent.replace(/:→/g, ":->"); }`

debanjandhar12 commented 10 months ago

Issue is occurring due to no space before ":->".

The bold tags are first being added here: https://github.com/debanjandhar12/logseq-anki-sync/blob/2efe2f231b352c88572e563c91f73414ccb8eefe/src/notes/SwiftArrowNote.ts#L48

and then passed to: https://github.com/debanjandhar12/logseq-anki-sync/blob/2efe2f231b352c88572e563c91f73414ccb8eefe/src/notes/SwiftArrowNote.ts#L59

The converter internally uses mldoc which require html code to be space separated. However, earlier, we didn't add space.


Replacing the above line of SwiftArrowNote with below should fix it:

replacement += `${beforeArrowSpace}${beforeArrowSpace.endsWith(" ") ? "" : " "}<b>${g3}</b>${afterArrowSpace}`;
HeinzContiZacherl commented 10 months ago

Great! I just added a space before ":->" to my notes in Logseq and it worked. Now the Anki cards are correct.

Do you think you could add this little change to future releases or mention the needed space on the documentation? I think that would improve your addon even further.

I want to really thank you for your work. Im a newbie coder and couldn't solve it myself. Your addon changed my academic life.

debanjandhar12 commented 10 months ago

I'm glad the plugin has been helpful for you. I have included the fix and will do a release with it included soon.