Skip to content

Commit

Permalink
feat: better latex support
Browse files Browse the repository at this point in the history
  • Loading branch information
kirito41dd committed Dec 28, 2024
1 parent 017aa23 commit 6fe4946
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "hugo-publish",
"name": "Hugo Publish",
"version": "1.0.8",
"version": "1.0.9",
"minAppVersion": "0.15.0",
"description": "Publish your blog to hugo site.",
"author": "kirito",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-sample-plugin",
"version": "1.0.8",
"version": "1.0.9",
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
"main": "main.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export default class HugoPublishPlugin extends Plugin {
//console.log("ast", ast)
util.transform_wiki_image(ast);
util.transform_wiki_link(ast);
util.transform_better_latex(ast);


const meta = this.app.metadataCache.getFileCache(f);
Expand Down
10 changes: 10 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ export const get_md_yaml_hader_from_content = (content: string): [string, string
}
}

export const transform_better_latex = (ast: Root) => {
visit(ast, 'math', function (node, index, parent) {
// https://www.gohugo.org/doc/tutorials/mathjax_en/
// just put LaTeX code in between <div>$$TeX Code$$</div>
const new_value = '<div>\n$$\n' + node.value + '\n$$\n</div>';
node.value = new_value;
(node as { type: string }).type = 'html'; // force cast
})
}

// ![[xxx.png]] -> ![xxx.png](xxx.png)
export const transform_wiki_image = (ast: Root) => {
visit(ast, 'paragraph', function (node, index, parent) {
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"1.0.5": "0.15.0",
"1.0.6": "0.15.0",
"1.0.7": "0.15.0",
"1.0.8": "0.15.0"
"1.0.8": "0.15.0",
"1.0.9": "0.15.0"
}

0 comments on commit 6fe4946

Please sign in to comment.