@vmz/plugin-markdown-it 0.3.5 → 0.3.7
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.
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {string} source
|
|
3
|
+
* @returns {string} HTML fragment (no wrapping document)
|
|
4
|
+
*/
|
|
5
|
+
export declare function renderMarkdown(source: any): any;
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} source
|
|
8
|
+
* @returns {{
|
|
9
|
+
* html: string,
|
|
10
|
+
* headings: Array<{ level: number, id: string, text: string }>,
|
|
11
|
+
* links: Array<{ href: string, text: string }>,
|
|
12
|
+
* fences: Array<{ lang: string, info: string, content: string, lineStart: number, lineEnd: number }>
|
|
13
|
+
* }}
|
|
14
|
+
*/
|
|
15
|
+
export declare function analyzeMarkdown(source: any): {
|
|
16
|
+
html: any;
|
|
17
|
+
headings: any[];
|
|
18
|
+
links: any[];
|
|
19
|
+
fences: any[];
|
|
20
|
+
};
|
|
21
|
+
/** @param {string} text */
|
|
22
|
+
export declare function slugify(text: any): string;
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
* Deterministic CommonMark-ish subset for documents + `<Markdown>` .
|
|
3
3
|
*/
|
|
4
4
|
import MarkdownIt from 'markdown-it';
|
|
5
|
-
|
|
6
5
|
/** @type {import('markdown-it').default | null} */
|
|
7
6
|
let cached = null;
|
|
8
|
-
|
|
9
7
|
function createMd() {
|
|
10
|
-
if (cached)
|
|
8
|
+
if (cached)
|
|
9
|
+
return cached;
|
|
11
10
|
cached = new MarkdownIt({
|
|
12
11
|
html: false,
|
|
13
12
|
linkify: true,
|
|
@@ -16,7 +15,6 @@ function createMd() {
|
|
|
16
15
|
});
|
|
17
16
|
return cached;
|
|
18
17
|
}
|
|
19
|
-
|
|
20
18
|
/**
|
|
21
19
|
* @param {string} source
|
|
22
20
|
* @returns {string} HTML fragment (no wrapping document)
|
|
@@ -25,7 +23,6 @@ export function renderMarkdown(source) {
|
|
|
25
23
|
const md = createMd();
|
|
26
24
|
return md.render(String(source ?? ''));
|
|
27
25
|
}
|
|
28
|
-
|
|
29
26
|
/**
|
|
30
27
|
* @param {string} source
|
|
31
28
|
* @returns {{
|
|
@@ -45,7 +42,6 @@ export function analyzeMarkdown(source) {
|
|
|
45
42
|
/** @type {Array<{ lang: string, info: string, content: string, lineStart: number, lineEnd: number }>} */
|
|
46
43
|
const fences = [];
|
|
47
44
|
const seenIds = new Set();
|
|
48
|
-
|
|
49
45
|
for (let i = 0; i < tokens.length; i++) {
|
|
50
46
|
const t = tokens[i];
|
|
51
47
|
if (t.type === 'heading_open') {
|
|
@@ -55,7 +51,8 @@ export function analyzeMarkdown(source) {
|
|
|
55
51
|
let id = slugify(text);
|
|
56
52
|
if (seenIds.has(id)) {
|
|
57
53
|
let n = 2;
|
|
58
|
-
while (seenIds.has(`${id}-${n}`))
|
|
54
|
+
while (seenIds.has(`${id}-${n}`))
|
|
55
|
+
n++;
|
|
59
56
|
id = `${id}-${n}`;
|
|
60
57
|
}
|
|
61
58
|
seenIds.add(id);
|
|
@@ -84,20 +81,16 @@ export function analyzeMarkdown(source) {
|
|
|
84
81
|
}
|
|
85
82
|
}
|
|
86
83
|
}
|
|
87
|
-
|
|
88
84
|
const html = md.renderer.render(tokens, md.options, {});
|
|
89
85
|
return { html, headings, links, fences };
|
|
90
86
|
}
|
|
91
|
-
|
|
92
87
|
/** @param {string} text */
|
|
93
88
|
export function slugify(text) {
|
|
94
|
-
return (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
.replace(/^-|-$/g, '') || 'section'
|
|
102
|
-
);
|
|
89
|
+
return (String(text || '')
|
|
90
|
+
.trim()
|
|
91
|
+
.toLowerCase()
|
|
92
|
+
.replace(/[^\p{L}\p{N}\s_-]/gu, '')
|
|
93
|
+
.replace(/\s+/g, '-')
|
|
94
|
+
.replace(/-+/g, '-')
|
|
95
|
+
.replace(/^-|-$/g, '') || 'section');
|
|
103
96
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { definePlugin, loadPluginSource } from '@vmz/plugin';
|
|
2
|
-
|
|
3
|
-
const source = loadPluginSource(import.meta.url, 'components/MarkdownIt.vmz');
|
|
4
|
-
|
|
2
|
+
const source = loadPluginSource(import.meta.url, '../components/MarkdownIt.vmz');
|
|
5
3
|
export default definePlugin({
|
|
6
4
|
name: '@vmz/plugin-markdown-it',
|
|
7
5
|
version: '0.1.0',
|
package/package.json
CHANGED
|
@@ -1,20 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@vmz/plugin": "0.3.
|
|
3
|
+
"@vmz/plugin": "0.3.7",
|
|
4
4
|
"markdown-it": "^14.1.0"
|
|
5
5
|
},
|
|
6
6
|
"description": "VMZ markdown-it adapter — MarkdownIt + engines.markdown registration",
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"@types/node": "^22.15.0",
|
|
9
|
+
"typescript": "^5.8.3"
|
|
10
|
+
},
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=24.12.0"
|
|
13
|
+
},
|
|
7
14
|
"exports": {
|
|
8
15
|
".": {
|
|
9
|
-
"default": "./vmz.plugin.
|
|
10
|
-
"types": "./vmz.plugin.ts"
|
|
16
|
+
"default": "./dist/vmz.plugin.js",
|
|
17
|
+
"types": "./dist/vmz.plugin.d.ts"
|
|
11
18
|
},
|
|
12
19
|
"./package.json": "./package.json",
|
|
13
20
|
"./runtime": {
|
|
14
|
-
"default": "./runtime.
|
|
15
|
-
"types": "./runtime.ts"
|
|
21
|
+
"default": "./dist/runtime.js",
|
|
22
|
+
"types": "./dist/runtime.d.ts"
|
|
16
23
|
}
|
|
17
24
|
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"components",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
18
30
|
"keywords": [
|
|
19
31
|
"vmz",
|
|
20
32
|
"plugin",
|
|
@@ -22,7 +34,7 @@
|
|
|
22
34
|
"markdown-it"
|
|
23
35
|
],
|
|
24
36
|
"license": "MIT",
|
|
25
|
-
"main": "./vmz.plugin.
|
|
37
|
+
"main": "./dist/vmz.plugin.js",
|
|
26
38
|
"name": "@vmz/plugin-markdown-it",
|
|
27
39
|
"publishConfig": {
|
|
28
40
|
"access": "public"
|
|
@@ -32,7 +44,10 @@
|
|
|
32
44
|
"type": "git",
|
|
33
45
|
"url": "git+https://github.com/doki-land/vmz-framework.git"
|
|
34
46
|
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc -p tsconfig.json"
|
|
49
|
+
},
|
|
35
50
|
"type": "module",
|
|
36
|
-
"types": "./vmz.plugin.ts",
|
|
37
|
-
"version": "0.3.
|
|
51
|
+
"types": "./dist/vmz.plugin.d.ts",
|
|
52
|
+
"version": "0.3.7"
|
|
38
53
|
}
|