@vxrn/mdx 2.6.5 → 2.6.6
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/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
- package/src/getHeadings.test.ts +22 -0
- package/src/getHeadings.ts +11 -1
- package/types/getHeadings.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vxrn/mdx",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.6",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./package.json": "./package.json",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"clean:build": "tamagui-build clean:build",
|
|
26
26
|
"lint": "biome check src",
|
|
27
27
|
"lint:fix": "biome check --write src",
|
|
28
|
+
"test": "vitest run --dir src",
|
|
28
29
|
"typecheck": "tsc --noEmit",
|
|
29
30
|
"watch": "bun run build --watch"
|
|
30
31
|
},
|
|
@@ -61,12 +62,13 @@
|
|
|
61
62
|
"unist-util-visit": "^2.0.3"
|
|
62
63
|
},
|
|
63
64
|
"devDependencies": {
|
|
64
|
-
"@tamagui/build": "3.0.5"
|
|
65
|
+
"@tamagui/build": "3.0.5",
|
|
66
|
+
"vitest": "^4.1.0"
|
|
65
67
|
},
|
|
66
68
|
"publishConfig": {
|
|
67
69
|
"access": "public"
|
|
68
70
|
},
|
|
69
|
-
"releaseSourceCommit": "
|
|
71
|
+
"releaseSourceCommit": "d3b6ddb713d7e54713fc28f29e9ae48ed5394140",
|
|
70
72
|
"repository": {
|
|
71
73
|
"type": "git",
|
|
72
74
|
"url": "git+https://github.com/onejs/one.git",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { expect, test } from 'vitest'
|
|
2
|
+
import { getHeadings } from './getHeadings'
|
|
3
|
+
|
|
4
|
+
test('ignores # lines inside fenced code', () => {
|
|
5
|
+
const source = [
|
|
6
|
+
'# Install',
|
|
7
|
+
'```bash',
|
|
8
|
+
'# install deps',
|
|
9
|
+
'bun install',
|
|
10
|
+
'```',
|
|
11
|
+
'~~~sh',
|
|
12
|
+
'# run it',
|
|
13
|
+
'~~~',
|
|
14
|
+
'## Usage',
|
|
15
|
+
'#not-a-heading',
|
|
16
|
+
].join('\n')
|
|
17
|
+
|
|
18
|
+
expect(getHeadings(source)).toEqual([
|
|
19
|
+
{ title: 'Install', priority: 1, id: 'install' },
|
|
20
|
+
{ title: 'Usage', priority: 2, id: 'usage' },
|
|
21
|
+
])
|
|
22
|
+
})
|
package/src/getHeadings.ts
CHANGED
|
@@ -4,9 +4,19 @@ const getTitle = (source: string) => source.replace(/^#+\s+/, '').replace(/<.*>/
|
|
|
4
4
|
|
|
5
5
|
export const getHeadings = (source: string) => {
|
|
6
6
|
const slugger = new GithubSlugger()
|
|
7
|
+
// skip lines inside fenced code, where `# comment` is not a heading
|
|
8
|
+
let fence = ''
|
|
7
9
|
return source
|
|
8
10
|
.split('\n')
|
|
9
|
-
.filter((x) =>
|
|
11
|
+
.filter((x) => {
|
|
12
|
+
const marker = x.trimStart().match(/^(`{3,}|~{3,})/)?.[1]
|
|
13
|
+
if (marker) {
|
|
14
|
+
if (!fence) fence = marker
|
|
15
|
+
else if (marker[0] === fence[0] && marker.length >= fence.length) fence = ''
|
|
16
|
+
return false
|
|
17
|
+
}
|
|
18
|
+
return !fence && /^#{1,6}\s/.test(x)
|
|
19
|
+
})
|
|
10
20
|
.map((x) => ({
|
|
11
21
|
title: getTitle(x),
|
|
12
22
|
priority: x.trim().split(' ')[0].length,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getHeadings.d.ts","sourceRoot":"","sources":["../src/getHeadings.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,WAAY,MAAM;;;;
|
|
1
|
+
{"version":3,"file":"getHeadings.d.ts","sourceRoot":"","sources":["../src/getHeadings.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW,WAAY,MAAM;;;;GAoBzC,CAAA"}
|