vimd 0.3.14 → 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.
@@ -10,6 +10,8 @@ export declare class MarkdownItParser implements Parser {
10
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":"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;;;;OAIG;IACG,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI9C;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;CAGtC"}
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"}
@@ -36,11 +36,37 @@ export class MarkdownItParser {
36
36
  }
37
37
  /**
38
38
  * Convert markdown to HTML.
39
+ * Math blocks ($$...$$) are protected from markdown-it processing
40
+ * to preserve LaTeX syntax (especially backslashes).
39
41
  * @param markdown - The markdown content to convert
40
42
  * @returns The converted HTML string
41
43
  */
42
44
  async parse(markdown) {
43
- return this.md.render(markdown);
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;
44
70
  }
45
71
  /**
46
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.14",
3
+ "version": "0.3.15",
4
4
  "description": "Real-time Markdown preview tool with pandoc (view markdown)",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -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']},