MSzturc / obsidian-advanced-slides

Create markdown-based reveal.js presentations in Obsidian
https://mszturc.github.io/obsidian-advanced-slides/
MIT License
987 stars 82 forks source link

Embedded code has extra characters near dollar signs #244

Open mfp22 opened 1 year ago

mfp22 commented 1 year ago

Describe the bug

I want to embed a code snippet from another file into a slide. It adds extra ticks `" near dollar signs $.

Samples to Reproduce

Try to embed this code snippet into a slide:

export class CounterService {
  count$ = new BehaviorSubject(1000);

  double$ = this.count$.pipe(map((count) => count * 2));
  triple$ = this.count$.pipe(map((count) => count * 3));

  combined$ = combineLatest([this.double$, this.triple$]).pipe(
    map(([double, triple]) => double + triple)
  );

  over9000$ = this.combined$.pipe(map((combined) => combined > 9000));

  message$ = this.over9000$.pipe(
    map((over9000) => (over9000 ? "It's over 9000!" : "It's under 9000."))
  );
}

And it shows up exactly like this instead:

export class CounterService {
  count$ = new BehaviorSubject(1000);

  double`$ = this.count$`.pipe(map((count) => count * 2));
  triple`$ = this.count$`.pipe(map((count) => count * 3));

  combined`$ = combineLatest([this.double$`, this.triple$]).pipe(
    map(([double, triple]) => double + triple)
  );

  over9000`$ = this.combined$`.pipe(map((combined) => combined > 9000));

  message`$ = this.over9000$`.pipe(
    map((over9000) => (over9000 ? "It's over 9000!" : "It's under 9000."))
  );
}

Expected behavior The embedded code should appear exactly the same in the slide

mfp22 commented 1 year ago

Actually this happens for any code snippet in a slide. No need to embed to reproduce issue.

booxter commented 10 months ago

In my testing, it looks like a single dollar sign per line is ok, backticks are added once the line has more than two dollars.

jojonas commented 6 months ago

This bug affects me too, that's why I investigated some more...

The error is in this line:

https://github.com/MSzturc/obsidian-advanced-slides/blob/2d713cadf4485124afc88e32ee27a48fa7c2c551/src/processors/latexProcessor.ts#L41

The LatexProcessor changes the content of any line containing a $ according to this regular expression: /\$(.*?)\$/g is replaced with '$$$1$$', for example foo $bar$ baz turns into foo '$bar$' baz (in the replacement pattern, $$ is the escaped version of $) . This code exists to support LaTeX math expressions in markdown, e.g.:

The circumference of a circle is $2\pi$.

But this is of course not intended within code blocks.

There used to be a (incorrect?) fix: https://github.com/MSzturc/obsidian-advanced-slides/commit/0e9af6215c0ed4991c4fba0cee2f82103c0d524a, which the author promptly reverted: https://github.com/MSzturc/obsidian-advanced-slides/commit/6ef4847.

tibomogul commented 1 month ago

Pull request for a fix https://github.com/MSzturc/obsidian-advanced-slides/pull/315