ObsidianToAnki / Obsidian_to_Anki

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

Facing issues while using custom regex #593

Open UlliDa opened 3 weeks ago

UlliDa commented 3 weeks ago

While using custom regex (this one: https://github.com/ObsidianToAnki/Obsidian_to_Anki/issues/332) i am facing an issue with links inside my cards that never happened before. I guess since the update on the newest version of Obsidian.

1 2

It depends on this piece of code and does not happen with other card formattings (like the built in).

showdown.subParser('unhashHTMLSpans', function (text, options, globals) {
  text = globals.converter._dispatch('unhashHTMLSpans.before', text, options, globals);

  for (var i = 0; i < globals.gHtmlSpans.length; ++i) {
    var repText = globals.gHtmlSpans[i],
        // limiter to prevent infinite loop (assume 10 as limit for recurse)
        limit = 0;

    while (/¨C(\d+)C/.test(repText)) {
      var num = RegExp.$1;
      repText = repText.replace('¨C' + num + 'C', globals.gHtmlSpans[num]);
      if (limit === 10) {
        console.error('maximum nesting of 10 spans reached!!!');
        break;
      }
      ++limit;
    }
    text = text.replace('¨C' + i + 'C', repText);
  }