markdown2typst 0.1.8 → 0.1.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdown2typst",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "A comprehensive JavaScript library for converting Markdown to Typst code",
5
5
  "type": "module",
6
6
  "main": "./dist/markdown2typst.js",
package/src/parser.ts CHANGED
@@ -28,6 +28,12 @@ import { ErrorSeverity } from './types.js';
28
28
  */
29
29
  export function parseMarkdown(markdown: string, onError?: ErrorCallback): Root {
30
30
  try {
31
+ // remark-math requires a blank line before display math. Accept a
32
+ // standalone $$ block immediately after a paragraph as well.
33
+ const normalizedMarkdown = markdown.replace(
34
+ /([^\n])\n(\$\$)/g,
35
+ '$1\n\n$2'
36
+ );
31
37
  const processor = unified()
32
38
  .use(remarkParse)
33
39
  .use(remarkFrontmatter, ['yaml'])
@@ -35,7 +41,7 @@ export function parseMarkdown(markdown: string, onError?: ErrorCallback): Root {
35
41
  .use(remarkMath)
36
42
  .use(remarkFixAdjacentMath);
37
43
 
38
- const parsedTree = processor.parse(markdown);
44
+ const parsedTree = processor.parse(normalizedMarkdown);
39
45
  const tree = processor.runSync(parsedTree) as Root;
40
46
 
41
47
  return tree;