obsidian-advanced-slides
obsidian-advanced-slides copied to clipboard
Embedded code has extra characters near dollar signs
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
Actually this happens for any code snippet in a slide. No need to embed to reproduce issue.
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.
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.