vimd 0.3.13 → 0.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/parser/markdown-it-parser.d.ts +3 -1
- package/dist/core/parser/markdown-it-parser.d.ts.map +1 -1
- package/dist/core/parser/markdown-it-parser.js +32 -10
- package/dist/templates/default.html +13 -0
- package/dist/templates/standalone.html +13 -0
- package/package.json +1 -2
- package/templates/default.html +13 -0
- package/templates/standalone.html +13 -0
|
@@ -7,9 +7,11 @@ import { MathConfig } from '../../config/types.js';
|
|
|
7
7
|
export declare class MarkdownItParser implements Parser {
|
|
8
8
|
readonly name = "markdown-it";
|
|
9
9
|
private md;
|
|
10
|
-
constructor(
|
|
10
|
+
constructor(_mathConfig?: MathConfig);
|
|
11
11
|
/**
|
|
12
12
|
* Convert markdown to HTML.
|
|
13
|
+
* Math blocks ($$...$$) are protected from markdown-it processing
|
|
14
|
+
* to preserve LaTeX syntax (especially backslashes).
|
|
13
15
|
* @param markdown - The markdown content to convert
|
|
14
16
|
* @returns The converted HTML string
|
|
15
17
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown-it-parser.d.ts","sourceRoot":"","sources":["../../../src/core/parser/markdown-it-parser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markdown-it-parser.d.ts","sourceRoot":"","sources":["../../../src/core/parser/markdown-it-parser.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD;;;GAGG;AACH,qBAAa,gBAAiB,YAAW,MAAM;IAC7C,QAAQ,CAAC,IAAI,iBAAiB;IAC9B,OAAO,CAAC,EAAE,CAAa;gBAEX,WAAW,CAAC,EAAE,UAAU;IA2BpC;;;;;;OAMG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAqC9C;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAGtC"}
|
|
@@ -3,13 +3,12 @@ import MarkdownIt from 'markdown-it';
|
|
|
3
3
|
import hljs from 'highlight.js';
|
|
4
4
|
import strikethrough from 'markdown-it-strikethrough-alt';
|
|
5
5
|
import taskLists from 'markdown-it-task-lists';
|
|
6
|
-
import texmath from 'markdown-it-texmath';
|
|
7
6
|
/**
|
|
8
7
|
* Markdown parser using markdown-it library.
|
|
9
8
|
* Provides fast markdown to HTML conversion with GFM support.
|
|
10
9
|
*/
|
|
11
10
|
export class MarkdownItParser {
|
|
12
|
-
constructor(
|
|
11
|
+
constructor(_mathConfig) {
|
|
13
12
|
this.name = 'markdown-it';
|
|
14
13
|
this.md = new MarkdownIt({
|
|
15
14
|
html: true,
|
|
@@ -30,21 +29,44 @@ export class MarkdownItParser {
|
|
|
30
29
|
// Enable GFM plugins
|
|
31
30
|
this.md.use(strikethrough); // ~~strikethrough~~
|
|
32
31
|
this.md.use(taskLists); // - [ ] task list
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
delimiters: 'dollars',
|
|
38
|
-
});
|
|
39
|
-
}
|
|
32
|
+
// Note: For MathJax, we don't need a markdown-it plugin.
|
|
33
|
+
// MathJax will find and render $...$ and $$...$$ in the browser.
|
|
34
|
+
// The markdown-it-texmath plugin is for server-side KaTeX rendering,
|
|
35
|
+
// which conflicts with client-side MathJax rendering.
|
|
40
36
|
}
|
|
41
37
|
/**
|
|
42
38
|
* Convert markdown to HTML.
|
|
39
|
+
* Math blocks ($$...$$) are protected from markdown-it processing
|
|
40
|
+
* to preserve LaTeX syntax (especially backslashes).
|
|
43
41
|
* @param markdown - The markdown content to convert
|
|
44
42
|
* @returns The converted HTML string
|
|
45
43
|
*/
|
|
46
44
|
async parse(markdown) {
|
|
47
|
-
|
|
45
|
+
// Protect math blocks from markdown-it processing
|
|
46
|
+
const mathBlocks = [];
|
|
47
|
+
// Replace block math ($$...$$) with placeholders
|
|
48
|
+
let processed = markdown.replace(/\$\$([\s\S]*?)\$\$/g, (match) => {
|
|
49
|
+
mathBlocks.push(match);
|
|
50
|
+
return `\n\n%%MATH_BLOCK_${mathBlocks.length - 1}%%\n\n`;
|
|
51
|
+
});
|
|
52
|
+
// Replace inline math ($...$) with placeholders
|
|
53
|
+
// Be careful not to match $$ or currency amounts like $100
|
|
54
|
+
const inlineMathBlocks = [];
|
|
55
|
+
processed = processed.replace(/(?<!\$)\$(?!\$)([^\$\n]+?)\$(?!\$)/g, (match) => {
|
|
56
|
+
inlineMathBlocks.push(match);
|
|
57
|
+
return `%%INLINE_MATH_${inlineMathBlocks.length - 1}%%`;
|
|
58
|
+
});
|
|
59
|
+
// Process with markdown-it
|
|
60
|
+
let html = this.md.render(processed);
|
|
61
|
+
// Restore block math (wrap in div for centering)
|
|
62
|
+
mathBlocks.forEach((block, i) => {
|
|
63
|
+
html = html.replace(`%%MATH_BLOCK_${i}%%`, `<div class="math-block">${block}</div>`);
|
|
64
|
+
});
|
|
65
|
+
// Restore inline math
|
|
66
|
+
inlineMathBlocks.forEach((block, i) => {
|
|
67
|
+
html = html.replace(`%%INLINE_MATH_${i}%%`, block);
|
|
68
|
+
});
|
|
69
|
+
return html;
|
|
48
70
|
}
|
|
49
71
|
/**
|
|
50
72
|
* Check if the parser is available.
|
|
@@ -14,6 +14,19 @@
|
|
|
14
14
|
</style>
|
|
15
15
|
{{/if}}
|
|
16
16
|
{{#if math_enabled}}
|
|
17
|
+
<style>
|
|
18
|
+
/* Block math centering */
|
|
19
|
+
.math-block {
|
|
20
|
+
display: block;
|
|
21
|
+
text-align: center;
|
|
22
|
+
margin: 1em 0;
|
|
23
|
+
}
|
|
24
|
+
mjx-container[display="true"] {
|
|
25
|
+
display: block !important;
|
|
26
|
+
text-align: center !important;
|
|
27
|
+
margin: 1em 0 !important;
|
|
28
|
+
}
|
|
29
|
+
</style>
|
|
17
30
|
<script>
|
|
18
31
|
MathJax = {
|
|
19
32
|
loader: {load: ['[tex]/bussproofs', '[tex]/ams', '[tex]/physics']},
|
|
@@ -14,6 +14,19 @@
|
|
|
14
14
|
</style>
|
|
15
15
|
{{/if}}
|
|
16
16
|
{{#if math_enabled}}
|
|
17
|
+
<style>
|
|
18
|
+
/* Block math centering */
|
|
19
|
+
.math-block {
|
|
20
|
+
display: block;
|
|
21
|
+
text-align: center;
|
|
22
|
+
margin: 1em 0;
|
|
23
|
+
}
|
|
24
|
+
mjx-container[display="true"] {
|
|
25
|
+
display: block !important;
|
|
26
|
+
text-align: center !important;
|
|
27
|
+
margin: 1em 0 !important;
|
|
28
|
+
}
|
|
29
|
+
</style>
|
|
17
30
|
<script>
|
|
18
31
|
MathJax = {
|
|
19
32
|
loader: {load: ['[tex]/bussproofs', '[tex]/ams', '[tex]/physics']},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vimd",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.15",
|
|
4
4
|
"description": "Real-time Markdown preview tool with pandoc (view markdown)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -76,7 +76,6 @@
|
|
|
76
76
|
"markdown-it": "^14.1.0",
|
|
77
77
|
"markdown-it-strikethrough-alt": "^1.0.0",
|
|
78
78
|
"markdown-it-task-lists": "^2.1.1",
|
|
79
|
-
"markdown-it-texmath": "^1.0.0",
|
|
80
79
|
"open": "^9.1.0",
|
|
81
80
|
"polka": "^0.5.2",
|
|
82
81
|
"sirv": "^3.0.2",
|
package/templates/default.html
CHANGED
|
@@ -14,6 +14,19 @@
|
|
|
14
14
|
</style>
|
|
15
15
|
{{/if}}
|
|
16
16
|
{{#if math_enabled}}
|
|
17
|
+
<style>
|
|
18
|
+
/* Block math centering */
|
|
19
|
+
.math-block {
|
|
20
|
+
display: block;
|
|
21
|
+
text-align: center;
|
|
22
|
+
margin: 1em 0;
|
|
23
|
+
}
|
|
24
|
+
mjx-container[display="true"] {
|
|
25
|
+
display: block !important;
|
|
26
|
+
text-align: center !important;
|
|
27
|
+
margin: 1em 0 !important;
|
|
28
|
+
}
|
|
29
|
+
</style>
|
|
17
30
|
<script>
|
|
18
31
|
MathJax = {
|
|
19
32
|
loader: {load: ['[tex]/bussproofs', '[tex]/ams', '[tex]/physics']},
|
|
@@ -14,6 +14,19 @@
|
|
|
14
14
|
</style>
|
|
15
15
|
{{/if}}
|
|
16
16
|
{{#if math_enabled}}
|
|
17
|
+
<style>
|
|
18
|
+
/* Block math centering */
|
|
19
|
+
.math-block {
|
|
20
|
+
display: block;
|
|
21
|
+
text-align: center;
|
|
22
|
+
margin: 1em 0;
|
|
23
|
+
}
|
|
24
|
+
mjx-container[display="true"] {
|
|
25
|
+
display: block !important;
|
|
26
|
+
text-align: center !important;
|
|
27
|
+
margin: 1em 0 !important;
|
|
28
|
+
}
|
|
29
|
+
</style>
|
|
17
30
|
<script>
|
|
18
31
|
MathJax = {
|
|
19
32
|
loader: {load: ['[tex]/bussproofs', '[tex]/ams', '[tex]/physics']},
|