ObsidianToAnki / Obsidian_to_Anki

Script to add flashcards from text/markdown files to Anki
GNU General Public License v3.0
1.51k stars 132 forks source link

`'` character replaced with `&;` unexpectedly in display math block #536

Open kai-kea opened 7 months ago

kai-kea commented 7 months ago

A simplified example as follows:

Markdown:

> [!eqn] Open Addressing with Quadratic Probing
> $$ h(k, i) = (h'(k) + c_1 \cdot i + c_2 \cdot i^2) \mod m $$
<!--ID: 1708997849864-->

Notes added to Anki using this regex:

^\> *\[\!(?:ret|def|eqn|thm)\][-\+]? ?((?:[^\n])+)?\n*((?:\n(?:^.{1,3}$|^.{4}(?<!<!--).*))+)

Which matches some types of callouts.

In Anki, I get: Front: Open Addressing with Quadratic Probing Back: h(k, i) = (h&;(k) + c_1 \cdot i + c_2 \cdot i^2) \mod m Tags: 039, obsidian

I read through the source code and from what I understand, inside Math blocks, the mathjax/latex is masked. When it's unmasked, ' char is masked and then replaced with &#039;. The RegexNote.parse method removes the #039 if the option to make obsidian tags to anki tags is on.

nicoberling commented 7 months ago

Just ran into the same issue after activating tags, with the following example, using :

> [!anki]+ Q
> $id'$

Giving the following backside:

<blockquote>
  <p><anki-mathjax>id&amp;;</anki-mathjax></p>
</blockquote>

All using a similar regex for the cards: (?:\> \[!anki\][+-]?) ([^\n]+)\n(.+(?:\n(?:^.{1,3}$|^.{4}(?<!<!--).*))*)

menghuu commented 2 months ago

I have the same issue(but with code block).

START 问答题 something 背面: A few more elements to see. You can include links to websites. Code blocks are supported Github-flavoured code blocks too, but Anki won't do syntax highlighting

    print("Hello world!")
    a = 'test'

END

the codeblock show in anki app:

    print("Hello world!")
    a = &;test&;