Skip to content

Commit b08b2a8

Browse files
committed
🐛 Prevent replace/replaceAll from interpreting $; resolves #133
1 parent 0e848f6 commit b08b2a8

File tree

9 files changed

+61
-12
lines changed

9 files changed

+61
-12
lines changed

se-test-vault/math-test.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
frontmatter: go
3+
---
4+
5+
## Math
6+
7+
$$f'(x), \frac{dy}{dx},\dot{x}, y' ...$$
8+
9+
---
10+
11+
## Slide 1: Test Formula
12+
13+
Different math rendering with and without show grid
14+
- with grid: rendering like inline formula
15+
- without grid: rendering like block
16+
(position of $t \to \infty$ changes)
17+
18+
$$\lim_{t \to \infty} (w(t) - y(t)) = 0$$
19+
20+
---
21+
22+
<!-- slide template="[[template_formula]]" -->
23+
24+
## Slide 2: Test Equation with Templates
25+
26+
- Test equation-template
27+
- Formula is rendered as inline-formula independent of grid on/off settings like (like
28+
29+
::: formula
30+
$$\lim_{t \to \infty} (w(t) - y(t)) = 0$$
31+
:::
32+
33+
---
34+
35+
## Test
36+
37+
Problems with inline code `$ ... $`

se-test-vault/syntax-test.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ _emphasis_ **bold** ==highlight==
4343
4444
---
4545

46-
## Math
47-
48-
$$f'(x), \frac{dy}{dx},\dot{x}, y' ...$$
49-
50-
---
51-
5246
## Included H1
5347

5448
This will include everything under H1

se-test-vault/template_formula.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- content -->
2+
<% content %>
3+
<!-- content -->
4+
5+
<grid drag="100 20" drop="bottom" bg="silver" align="center" pad="0 20px">
6+
<!-- formula -->
7+
<% formula %>
8+
<!-- formula -->
9+
</grid>

src/obsidian/processors/debugViewProcessor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class DebugViewProcessor implements Processor {
2020
if (notes.length > 0) {
2121
newSlide += `\n\n${notes}`;
2222
}
23-
output = output.replace(slide, newSlide);
23+
output = output.replace(slide, () => newSlide);
2424
return newSlide;
2525
})
2626
.join(options.verticalSeparator);

src/obsidian/processors/templateProcessor.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ export class TemplateProcessor implements Processor {
150150
fileWithExtension = `${fileWithExtension}.md`;
151151
}
152152
let templateContent = this.utils.parseFile(fileWithExtension, null);
153+
154+
if (templateContent == null) {
155+
throw new Error(
156+
`Template file not found: [[${file}]] (resolved to: ${fileWithExtension})`,
157+
);
158+
}
159+
153160
templateContent =
154161
this.multipleFileProcessor.process(templateContent);
155162
templateContent = templateContent
@@ -187,9 +194,9 @@ export class TemplateProcessor implements Processor {
187194
name = `<% ${name.trim()} %>`;
188195
result = result.replaceAll(
189196
optionalName,
190-
`${content}\n${optionalName}`,
197+
() => `${content}\n${optionalName}`,
191198
);
192-
result = result.replaceAll(name, content);
199+
result = result.replaceAll(name, () => content);
193200
result = result.replaceAll(match, "");
194201
}
195202
result = this.footnoteProcessor.transformFootNotes(result);

test/__snapshots__/extendedSyntax.unit.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ exports[`Extended Markdown Syntax > Speaker Notes 1`] = `""<!-- .slide: class=\
2828
2929
exports[`Extended Markdown Syntax > Horizontal / Vertical Slides 1`] = `""<!-- .slide: class=\\"drop\\" -->\\n<div class=\\"\\" style=\\"position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center\\" absolute=\\"true\\">\\n\\n# Slide 1\\n</div>\\n---\\n<!-- .slide: class=\\"drop\\" -->\\n<div class=\\"\\" style=\\"position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center\\" absolute=\\"true\\">\\n\\n# Slide 2.1\\n</div>\\n--\\n<!-- .slide: class=\\"drop\\" -->\\n<div class=\\"\\" style=\\"position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center\\" absolute=\\"true\\">\\n\\n# Slide 2.2\\n</div>""`;
3030
31-
exports[`Slides Extended Feature > Show Debug Grid 1`] = `""<!-- .slide: class=\\"drop\\" -->\\n<div class=\\"\\" style=\\"position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center\\" absolute=\\"true\\">\\n\\n## My Slide\\n\\nThis slide shows the debug view feature\\n\\n\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 0%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 10%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 20%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 30%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 40%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 50%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 60%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 70%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 80%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 90%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 10%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 20%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 30%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 40%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 50%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 60%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 70%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 80%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 90%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n</div>""`;
31+
exports[`Slides Extended Feature > Show Debug Grid 1`] = `""<!-- .slide: class=\\"drop\\" -->\\n<div class=\\"\\" style=\\"position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center\\" absolute=\\"true\\">\\n\\n## My Slide\\n\\nThis slide shows the debug view feature\\n\\n$$lim_{t \\to infty} (w(t) - y(t)) = 0$$\\n\\n\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 0%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 10%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 20%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 30%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 40%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 50%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 60%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 70%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 80%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 90%; height: 10%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 0%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 10%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 20%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 30%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 40%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 50%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 60%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 70%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 80%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n<div class=\\"\\" style=\\"border: thin dotted blue; box-sizing: border-box; position: absolute; left: 90%; top: 0%; height: 100%; width: 10%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n</div>\\n</div>""`;

test/__snapshots__/template.unit.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ exports[`Template with variable in frontmatter 1`] = `""<!-- .slide: class=\\"dr
88

99
exports[`Template with variable not set 1`] = `""<!-- .slide: class=\\"drop\\" -->\\n<div class=\\"\\" style=\\"position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center\\" absolute=\\"true\\">\\n\\n# MyContent\\n\\n # After<div class=\\"\\" style=\\"position: absolute; left: 0%; top: 94%; height: 6%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n\\n <% footer %>\\n </div>\\n</div>""`;
1010

11-
exports[`Template with variable set 1`] = `""<!-- .slide: class=\\"drop\\" -->\\n<div class=\\"\\" style=\\"position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center\\" absolute=\\"true\\">\\n\\n# MyContent\\n\\n\\n\\n\\n # After<div class=\\"\\" style=\\"position: absolute; left: 0%; top: 94%; height: 6%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n\\n <div class=\\"block\\">\\n\\n# Hello\\n</div>\\n\\n\\n </div>\\n</div>""`;
11+
exports[`Template with variable set 1`] = `""<!-- .slide: class=\\"drop\\" -->\\n<div class=\\"\\" style=\\"position: absolute; left: 0px; top: 0px; height: 700px; width: 960px; min-height: 700px; display: flex; flex-direction: column; align-items: center; justify-content: center\\" absolute=\\"true\\">\\n\\n# MyContent\\n\\n\\n\\n\\n # After<div class=\\"\\" style=\\"position: absolute; left: 0%; top: 94%; height: 6%; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center\\" >\\n\\n <div class=\\"block\\">\\n\\n$$lim_{t \\to infty} (w(t) - y(t)) = 0$$\\n</div>\\n\\n\\n </div>\\n</div>""`;

test/extendedSyntax.unit.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ test('Slides Extended Feature > Show Debug Grid', () => {
412412
413413
This slide shows the debug view feature
414414
415+
$$\lim_{t \to \infty} (w(t) - y(t)) = 0$$
416+
415417
`;
416418

417419
const { options, markdown } = prepare(input);

test/template.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ test('Template with variable set', () => {
8787
# MyContent
8888
8989
::: footer
90-
# Hello
90+
$$\lim_{t \to \infty} (w(t) - y(t)) = 0$$
9191
:::
9292
9393
`;

0 commit comments

Comments
 (0)