@temelj/mdx 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.
@@ -1,5 +1,5 @@
1
1
  import { toString as hastToString } from "hast-util-to-string";
2
- import { codeToHast, } from "shiki";
2
+ import { codeToHast, ShikiError, } from "shiki";
3
3
  import { visit } from "unist-util-visit";
4
4
  import { transformerNotationHighlight, } from "@shikijs/transformers";
5
5
  import { numericRangeContains } from "@temelj/iterator";
@@ -79,16 +79,27 @@ export function syntaxHighlightPlugin(options = {}) {
79
79
  }
80
80
  },
81
81
  });
82
- const hast = await codeToHast(sourceCode, hastOptions);
83
- // Insert highlighted code into parent
84
- const hastPre = hast.children[0];
85
- parent.children.splice(index, 1, {
86
- ...hastPre,
87
- properties: {
88
- ...hastPre.properties,
89
- dataFileName: meta.fileName,
90
- },
91
- });
82
+ try {
83
+ const hast = await codeToHast(sourceCode, hastOptions);
84
+ // Insert highlighted code into parent
85
+ const hastPre = hast.children[0];
86
+ parent.children.splice(index, 1, {
87
+ ...hastPre,
88
+ properties: {
89
+ ...hastPre.properties,
90
+ dataFileName: meta.fileName,
91
+ },
92
+ });
93
+ }
94
+ catch (error) {
95
+ if (error instanceof ShikiError) {
96
+ if (error.message.includes("Language `math` is not included in this bundle")) {
97
+ // Skip if the block is math block.
98
+ return;
99
+ }
100
+ }
101
+ throw error;
102
+ }
92
103
  }
93
104
  visit(tree, "element", (node, index, parent) => {
94
105
  promises.push(visitor(node, index, parent));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temelj/mdx",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Utilities for working with MDX.",
5
5
  "keywords": [
6
6
  "mdx"
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/syntax-highlight/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK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