Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/@types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface SlidesExtendedSettings {
paneMode: "split" | "tab" | "sidebar";
themeDirectory: string;
center: boolean;
preamblePath: string;
}

export type ChartJsOptions = {
Expand Down Expand Up @@ -67,6 +68,7 @@ export type Options = {
width: number;
enableCustomControls: boolean;
transition: string;
preamble: string;
// biome-ignore lint/suspicious/noExplicitAny: minimal adaptation to Chart.js types
[key: string]: any;
};
Expand Down
21 changes: 21 additions & 0 deletions src/obsidian/obsidianUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,23 @@ export class ObsidianUtils implements MediaCollector {
return this.settings;
}

async getPreamble(): Promise<string> {
if (!this.settings.preamblePath) {
return "";
}
try {
const preamble = await this.app.vault.adapter.read(
this.settings.preamblePath,
);
return preamble;
} catch (_e) {
console.warn(
`Slides Extended: Preamble file not found at '${this.settings.preamblePath}'. Ignoring.`,
);
return "";
}
}

private getTFile(filename: string): TFile | null {
if (filename.startsWith("[[") && filename.endsWith("]]")) {
filename = filename.substring(2, filename.length - 2).trim();
Expand Down Expand Up @@ -243,6 +260,10 @@ export class ObsidianUtils implements MediaCollector {
return file;
}

getExportDirectory(override?: string): string {
return override ?? this.exportDir;
}

getAbsolutePath(relativePath: string): string {
const markdownFile = this.getTFile(relativePath);
return this.absolute(markdownFile?.path);
Expand Down
31 changes: 30 additions & 1 deletion src/plugin/load-mathjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,37 @@ window.MathJax = {
},
startup: {
ready: () => {
const preamblePath = window.mathJaxPreamblePath;
const preamblePromise =
preamblePath &&
preamblePath.trim().length > 0 &&
preamblePath.trim() !== "undefined"
? fetch(preamblePath)
.then((response) => {
if (!response.ok) {
throw new Error(
`Failed to load preamble file: ${response.statusText}`,
);
}
return response.text();
})
.catch((err) => {
console.error(
`Slides Extended: Could not load preamble file at '${preamblePath}'.`,
err,
);
return ""; // Resolve with empty string on failure
})
: Promise.resolve("");

MathJax.startup.defaultReady();
MathJax.startup.promise.then(() => {
MathJax.startup.promise.then(async () => {
const preamble = await preamblePromise;
if (preamble && preamble.trim().length > 0) {
// Process the preamble. This makes definitions available globally.
MathJax.tex2chtml(preamble);
}

console.debug("MathJax initialized and ready");
mathJaxReady = true;

Expand Down
16 changes: 16 additions & 0 deletions src/slidesExtended-SettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,22 @@ export class SlidesExtendedSettingTab extends PluginSettingTab {
});
});

containerEl.createEl("h2", { text: "MathJax" });

new Setting(containerEl)
.setName("Preamble path")
.setDesc(
"Path to MathJax preamble file. This file will be included in your slides. (Requires reload!)",
)
.addText((text) =>
text
.setPlaceholder("preamble.sty")
.setValue(this.newSettings.preamblePath)
.onChange((value) => {
this.newSettings.preamblePath = value;
}),
);

containerEl.createEl("h2", { text: "Plugins" });

new Setting(containerEl)
Expand Down
2 changes: 2 additions & 0 deletions src/slidesExtended-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ export const DEFAULT_SETTINGS: SlidesExtendedSettings = {
paneMode: "split",
themeDirectory: "",
center: true,
preamblePath: "preamble.sty",
};
export const DEFAULTS: Options = {
bg: "",
center: true,
preamble: "",
css: "",
defaultTemplate: "",
enableCustomControls: true,
Expand Down
16 changes: 14 additions & 2 deletions src/template/embed.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,19 @@
{{/remoteCSSPaths}}

<script defer src="{{{base}}}dist/fontawesome/all.min.js"></script>
<script defer src="{{{base}}}plugin/load-mathjax.js"></script>
{{#preamblePath}}
<script>
window.mathJaxPreamblePath = '{{{preamblePath}}}';
</script>
{{/preamblePath}}
<script>
(function() {
const script = document.createElement('script');
script.defer = true;
script.src = `{{{base}}}plugin/load-mathjax.js?v=${new Date().getTime()}`;
document.head.appendChild(script);
})();
</script>

<script type="text/javascript">

Expand Down Expand Up @@ -157,4 +169,4 @@
<!-- created with {{! ignore me }}Slides Extended embed.html template -->
</body>

</html>
</html>
16 changes: 14 additions & 2 deletions src/template/reveal.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@
{{/remoteCSSPaths}}

<script defer src="{{{base}}}dist/fontawesome/all.min.js"></script>
<script defer src="{{{base}}}plugin/load-mathjax.js"></script>
{{#preamblePath}}
<script>
window.mathJaxPreamblePath = '{{{preamblePath}}}';
</script>
{{/preamblePath}}
<script>
(function() {
const script = document.createElement('script');
script.defer = true;
script.src = `{{{base}}}plugin/load-mathjax.js?v=${new Date().getTime()}`;
document.head.appendChild(script);
})();
</script>

<script type="text/javascript">
function pageInIframe() {
Expand Down Expand Up @@ -264,4 +276,4 @@
</script>
<!-- created with {{! ignore me }}Slides Extended reveal.html template -->
</body>
</html>
</html>
12 changes: 8 additions & 4 deletions test/buildValidation.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ describe("Build Validation", () => {
for (const match of matches) {
const path = match[1];

it(`should have ${path} in build output`, () => {
const fullPath = join(BUILD_DIR, path);
expect(existsSync(fullPath)).toBe(true);
});
// The load-mathjax.js script is now loaded dynamically with a cache-busting
// timestamp, so we can't statically verify its path.
if (!path.startsWith("plugin/load-mathjax.js")) {
it(`should have ${path} in build output`, () => {
const fullPath = join(BUILD_DIR, path);
expect(existsSync(fullPath)).toBe(true);
});
}
}
});
}
Expand Down