@vmz/plugin-markdown-it 0.3.8 → 0.3.10
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/README.md +48 -0
- package/dist/runtime.d.ts +17 -0
- package/dist/runtime.js +25 -6
- package/dist/vmz.plugin.d.ts +20 -2
- package/dist/vmz.plugin.js +63 -46
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# @vmz/plugin-markdown-it
|
|
2
|
+
|
|
3
|
+
## Markdown documents and `<Markdown>` surfaces
|
|
4
|
+
|
|
5
|
+
`@vmz/plugin-markdown-it` registers the Markdown engine used by integrated documents (`/d/`) and the
|
|
6
|
+
`<Markdown>` / `engines.markdown` facade. It renders a deterministic CommonMark-ish subset and exposes heading,
|
|
7
|
+
link, and fence analysis for build-time document work.
|
|
8
|
+
|
|
9
|
+
## Install and register
|
|
10
|
+
|
|
11
|
+
The package depends on `markdown-it` directly, so no separate peer install is required.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { defineConfig } from '@vmz/plugin';
|
|
15
|
+
import markdownIt from '@vmz/plugin-markdown-it';
|
|
16
|
+
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
plugins: [markdownIt()],
|
|
19
|
+
engines: { markdown: 'markdown-it' },
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Registering the plugin alone does not select the engine. Sites with `documents/` need both the plugin and
|
|
24
|
+
`engines.markdown: 'markdown-it'`, otherwise document mount fails at `vmz dev`.
|
|
25
|
+
|
|
26
|
+
## Options
|
|
27
|
+
|
|
28
|
+
All official plugins are factories: `pluginName(optional config)`. Calling `markdownIt()` keeps the deterministic
|
|
29
|
+
defaults.
|
|
30
|
+
|
|
31
|
+
| Option | Default | Meaning |
|
|
32
|
+
|---------------|---------|------------------------------------------------|
|
|
33
|
+
| `html` | `false` | Allow raw HTML inside Markdown |
|
|
34
|
+
| `linkify` | `true` | Autoconvert URL-like text to links |
|
|
35
|
+
| `typographer` | `false` | Typographic replacement of quotes and dashes |
|
|
36
|
+
| `breaks` | `false` | Convert single newlines to `<br>` |
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
plugins: [markdownIt({ html: false, breaks: true })];
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Options configure the build/SSR renderer before use. The materialized `<Markdown>` component keeps its own props
|
|
43
|
+
for per-instance behavior.
|
|
44
|
+
|
|
45
|
+
## VMZ boundary
|
|
46
|
+
|
|
47
|
+
markdown-it owns Markdown parsing and HTML generation. VMZ owns document structure, SSR, link validation, and
|
|
48
|
+
delivery. The plugin does not introduce a second link resolver or app router.
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
export type MarkdownItRuntimeOptions = {
|
|
2
|
+
/** Allow raw HTML in Markdown (default `false`). */
|
|
3
|
+
html?: boolean;
|
|
4
|
+
/** Autoconvert URL-like text to links (default `true`). */
|
|
5
|
+
linkify?: boolean;
|
|
6
|
+
/** Typographic replacements (default `false`). */
|
|
7
|
+
typographer?: boolean;
|
|
8
|
+
/** Convert single newlines to `<br>` (default `false`). */
|
|
9
|
+
breaks?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Configure the renderer before use (also called by the `markdownIt()` plugin factory).
|
|
13
|
+
* Later calls rebuild the cached instance.
|
|
14
|
+
*/
|
|
15
|
+
export declare function configureMarkdownIt(next?: MarkdownItRuntimeOptions): void;
|
|
16
|
+
/** Current renderer options (tests / diagnostics). */
|
|
17
|
+
export declare function getMarkdownItOptions(): Required<MarkdownItRuntimeOptions>;
|
|
1
18
|
/**
|
|
2
19
|
* @param {string} source
|
|
3
20
|
* @returns {string} HTML fragment (no wrapping document)
|
package/dist/runtime.js
CHANGED
|
@@ -2,17 +2,36 @@
|
|
|
2
2
|
* Deterministic CommonMark-ish subset for documents + `<Markdown>` .
|
|
3
3
|
*/
|
|
4
4
|
import MarkdownIt from 'markdown-it';
|
|
5
|
+
const DEFAULT_OPTIONS = {
|
|
6
|
+
html: false,
|
|
7
|
+
linkify: true,
|
|
8
|
+
typographer: false,
|
|
9
|
+
breaks: false,
|
|
10
|
+
};
|
|
11
|
+
let options = { ...DEFAULT_OPTIONS };
|
|
5
12
|
/** @type {import('markdown-it').default | null} */
|
|
6
13
|
let cached = null;
|
|
14
|
+
/**
|
|
15
|
+
* Configure the renderer before use (also called by the `markdownIt()` plugin factory).
|
|
16
|
+
* Later calls rebuild the cached instance.
|
|
17
|
+
*/
|
|
18
|
+
export function configureMarkdownIt(next = {}) {
|
|
19
|
+
options = {
|
|
20
|
+
html: next.html ?? DEFAULT_OPTIONS.html,
|
|
21
|
+
linkify: next.linkify ?? DEFAULT_OPTIONS.linkify,
|
|
22
|
+
typographer: next.typographer ?? DEFAULT_OPTIONS.typographer,
|
|
23
|
+
breaks: next.breaks ?? DEFAULT_OPTIONS.breaks,
|
|
24
|
+
};
|
|
25
|
+
cached = null;
|
|
26
|
+
}
|
|
27
|
+
/** Current renderer options (tests / diagnostics). */
|
|
28
|
+
export function getMarkdownItOptions() {
|
|
29
|
+
return { ...options };
|
|
30
|
+
}
|
|
7
31
|
function createMd() {
|
|
8
32
|
if (cached)
|
|
9
33
|
return cached;
|
|
10
|
-
cached = new MarkdownIt(
|
|
11
|
-
html: false,
|
|
12
|
-
linkify: true,
|
|
13
|
-
typographer: false,
|
|
14
|
-
breaks: false,
|
|
15
|
-
});
|
|
34
|
+
cached = new MarkdownIt(options);
|
|
16
35
|
return cached;
|
|
17
36
|
}
|
|
18
37
|
/**
|
package/dist/vmz.plugin.d.ts
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { type MarkdownItRuntimeOptions } from './runtime.js';
|
|
2
|
+
/**
|
|
3
|
+
* Markdown renderer options. Omitted keys keep the deterministic defaults
|
|
4
|
+
* (`html: false`, `linkify: true`, `typographer: false`, `breaks: false`).
|
|
5
|
+
*/
|
|
6
|
+
export type MarkdownItPluginOptions = MarkdownItRuntimeOptions;
|
|
7
|
+
/**
|
|
8
|
+
* markdown-it plugin factory — register `<Markdown>` + `engines.markdown`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import markdownIt from '@vmz/plugin-markdown-it';
|
|
13
|
+
* export default defineConfig({
|
|
14
|
+
* plugins: [markdownIt({ linkify: false })],
|
|
15
|
+
* engines: { markdown: 'markdown-it' },
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function markdownIt(options?: MarkdownItPluginOptions): import("@vmz/plugin").VmzPlugin;
|
|
20
|
+
export default markdownIt;
|
package/dist/vmz.plugin.js
CHANGED
|
@@ -1,48 +1,65 @@
|
|
|
1
1
|
import { definePlugin, loadPluginSource } from '@vmz/plugin';
|
|
2
|
+
import { configureMarkdownIt } from './runtime.js';
|
|
2
3
|
const source = loadPluginSource(import.meta.url, '../components/MarkdownIt.vmz');
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
4
|
+
/**
|
|
5
|
+
* markdown-it plugin factory — register `<Markdown>` + `engines.markdown`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import markdownIt from '@vmz/plugin-markdown-it';
|
|
10
|
+
* export default defineConfig({
|
|
11
|
+
* plugins: [markdownIt({ linkify: false })],
|
|
12
|
+
* engines: { markdown: 'markdown-it' },
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function markdownIt(options = {}) {
|
|
17
|
+
configureMarkdownIt(options);
|
|
18
|
+
return definePlugin({
|
|
19
|
+
name: '@vmz/plugin-markdown-it',
|
|
20
|
+
version: '0.1.0',
|
|
21
|
+
protocol: '0.1.0',
|
|
22
|
+
stages: ['workspace_resolve', 'analyzer'],
|
|
23
|
+
deterministic: true,
|
|
24
|
+
async contribute(ctx) {
|
|
25
|
+
if (ctx.stage === 'workspace_resolve') {
|
|
26
|
+
return {
|
|
27
|
+
stage: 'workspace_resolve',
|
|
28
|
+
cacheKey: `@vmz/plugin-markdown-it:MarkdownIt.vmz:${source.contentHash.slice(0, 12)}`,
|
|
29
|
+
items: [
|
|
30
|
+
{
|
|
31
|
+
id: 'component-markdown-it',
|
|
32
|
+
kind: 'source',
|
|
33
|
+
path: 'src/components/MarkdownIt.vmz',
|
|
34
|
+
content: source.content,
|
|
35
|
+
contentHash: source.contentHash,
|
|
36
|
+
materialize: true,
|
|
37
|
+
engine: 'markdown-it',
|
|
38
|
+
engineKind: 'markdown',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (ctx.stage === 'analyzer') {
|
|
44
|
+
return {
|
|
45
|
+
stage: 'analyzer',
|
|
46
|
+
cacheKey: '@vmz/plugin-markdown-it:analyzer',
|
|
47
|
+
items: [
|
|
48
|
+
{
|
|
49
|
+
id: 'engine-markdown-it',
|
|
50
|
+
kind: 'analyzer',
|
|
51
|
+
path: 'src/components/MarkdownIt.vmz',
|
|
52
|
+
severity: 'advice',
|
|
53
|
+
message: 'markdown engine markdown-it online',
|
|
54
|
+
code: 'vmz.engine.markdown-it',
|
|
55
|
+
engine: 'markdown-it',
|
|
56
|
+
engineKind: 'markdown',
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return { stage: ctx.stage, items: [] };
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export default markdownIt;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"@vmz/plugin": "0.3.
|
|
3
|
+
"@vmz/plugin": "0.3.10",
|
|
4
4
|
"markdown-it": "^14.1.0"
|
|
5
5
|
},
|
|
6
6
|
"description": "VMZ markdown-it adapter — MarkdownIt + engines.markdown registration",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
},
|
|
50
50
|
"type": "module",
|
|
51
51
|
"types": "./dist/vmz.plugin.d.ts",
|
|
52
|
-
"version": "0.3.
|
|
52
|
+
"version": "0.3.10"
|
|
53
53
|
}
|