@vxrn/mdx-rust 2.0.0-beta.150.1 → 2.0.0-beta.159.1

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.
@@ -3,7 +3,16 @@ import GithubSlugger from "github-slugger";
3
3
  const getTitle = (source) => source.replace(/^#+\s+/, "").replace(/<.*>/, " ");
4
4
  const getHeadings = (source) => {
5
5
  const slugger = new GithubSlugger();
6
- return source.split("\n").filter((x) => x.startsWith("#")).map((x) => ({
6
+ let fence = "";
7
+ return source.split("\n").filter((x) => {
8
+ const marker = x.trimStart().match(/^(`{3,}|~{3,})/)?.[1];
9
+ if (marker) {
10
+ if (!fence) fence = marker;
11
+ else if (marker[0] === fence[0] && marker.length >= fence.length) fence = "";
12
+ return false;
13
+ }
14
+ return !fence && /^#{1,6}\s/.test(x);
15
+ }).map((x) => ({
7
16
  title: getTitle(x),
8
17
  priority: x.trim().split(" ")[0].length,
9
18
  id: slugger.slug(getTitle(x))
@@ -1 +1 @@
1
- {"version":3,"file":"getHeadings.js","names":[],"sources":["getHeadings.js"],"sourcesContent":["import GithubSlugger from \"github-slugger\";\nconst getTitle = (source) => source.replace(/^#+\\s+/, \"\").replace(/<.*>/, \" \");\nconst getHeadings = (source) => {\n const slugger = new GithubSlugger();\n return source.split(\"\\n\").filter((x) => x.startsWith(\"#\")).map((x) => ({\n title: getTitle(x),\n priority: x.trim().split(\" \")[0].length,\n id: slugger.slug(getTitle(x))\n }));\n};\nexport {\n getHeadings\n};\n//# sourceMappingURL=getHeadings.js.map\n"],"mappings":";;;AACA,MAAM,YAAY,WAAW,OAAO,QAAQ,UAAU,EAAE,CAAC,CAAC,QAAQ,QAAQ,GAAG;AAC7E,MAAM,eAAe,WAAW;CAC9B,MAAM,UAAU,IAAI,cAAc;CAClC,OAAO,OAAO,MAAM,IAAI,CAAC,CAAC,QAAQ,MAAM,EAAE,WAAW,GAAG,CAAC,CAAC,CAAC,KAAK,OAAO;EACrE,OAAO,SAAS,CAAC;EACjB,UAAU,EAAE,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC;EACjC,IAAI,QAAQ,KAAK,SAAS,CAAC,CAAC;CAC9B,EAAE;AACJ"}
1
+ {"version":3,"file":"getHeadings.js","names":[],"sources":["getHeadings.js"],"sourcesContent":["import GithubSlugger from \"github-slugger\";\nconst getTitle = (source) => source.replace(/^#+\\s+/, \"\").replace(/<.*>/, \" \");\nconst getHeadings = (source) => {\n const slugger = new GithubSlugger();\n let fence = \"\";\n return source.split(\"\\n\").filter((x) => {\n const marker = x.trimStart().match(/^(`{3,}|~{3,})/)?.[1];\n if (marker) {\n if (!fence) fence = marker;\n else if (marker[0] === fence[0] && marker.length >= fence.length) fence = \"\";\n return false;\n }\n return !fence && /^#{1,6}\\s/.test(x);\n }).map((x) => ({\n title: getTitle(x),\n priority: x.trim().split(\" \")[0].length,\n id: slugger.slug(getTitle(x))\n }));\n};\nexport {\n getHeadings\n};\n//# sourceMappingURL=getHeadings.js.map\n"],"mappings":";;;AACA,MAAM,YAAY,WAAW,OAAO,QAAQ,UAAU,EAAE,CAAC,CAAC,QAAQ,QAAQ,GAAG;AAC7E,MAAM,eAAe,WAAW;CAC9B,MAAM,UAAU,IAAI,cAAc;CAClC,IAAI,QAAQ;CACZ,OAAO,OAAO,MAAM,IAAI,CAAC,CAAC,QAAQ,MAAM;EACtC,MAAM,SAAS,EAAE,UAAU,CAAC,CAAC,MAAM,gBAAgB,CAAC,GAAG;EACvD,IAAI,QAAQ;GACV,IAAI,CAAC,OAAO,QAAQ;QACf,IAAI,OAAO,OAAO,MAAM,MAAM,OAAO,UAAU,MAAM,QAAQ,QAAQ;GAC1E,OAAO;EACT;EACA,OAAO,CAAC,SAAS,YAAY,KAAK,CAAC;CACrC,CAAC,CAAC,CAAC,KAAK,OAAO;EACb,OAAO,SAAS,CAAC;EACjB,UAAU,EAAE,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC;EACjC,IAAI,QAAQ,KAAK,SAAS,CAAC,CAAC;CAC9B,EAAE;AACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vxrn/mdx-rust",
3
- "version": "2.0.0-beta.150.1",
3
+ "version": "2.0.0-beta.159.1",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "module": "dist",
@@ -7,9 +7,19 @@ const getTitle = (source: string) => source.replace(/^#+\s+/, '').replace(/<.*>/
7
7
  // slugPlugin during compilation, so anchor links resolve.
8
8
  export const getHeadings = (source: string): Heading[] => {
9
9
  const slugger = new GithubSlugger()
10
+ // skip lines inside fenced code, where `# comment` is not a heading
11
+ let fence = ''
10
12
  return source
11
13
  .split('\n')
12
- .filter((x) => x.startsWith('#'))
14
+ .filter((x) => {
15
+ const marker = x.trimStart().match(/^(`{3,}|~{3,})/)?.[1]
16
+ if (marker) {
17
+ if (!fence) fence = marker
18
+ else if (marker[0] === fence[0] && marker.length >= fence.length) fence = ''
19
+ return false
20
+ }
21
+ return !fence && /^#{1,6}\s/.test(x)
22
+ })
13
23
  .map((x) => ({
14
24
  title: getTitle(x),
15
25
  priority: x.trim().split(' ')[0].length,
@@ -1 +1 @@
1
- {"version":3,"file":"getHeadings.d.ts","sourceRoot":"","sources":["../src/getHeadings.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAMtC,eAAO,MAAM,WAAW,WAAY,MAAM,KAAG,OAAO,EAUnD,CAAA"}
1
+ {"version":3,"file":"getHeadings.d.ts","sourceRoot":"","sources":["../src/getHeadings.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAMtC,eAAO,MAAM,WAAW,WAAY,MAAM,KAAG,OAAO,EAoBnD,CAAA"}