@shikijs/markdown-it 3.22.0 → 4.0.0
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/async.d.mts +7 -6
- package/dist/async.mjs +39 -45
- package/dist/common-CiaeKkQk.d.mts +32 -0
- package/dist/core.d.mts +6 -6
- package/dist/core.mjs +36 -50
- package/dist/index.d.mts +18 -19
- package/dist/index.mjs +13 -15
- package/package.json +9 -6
- package/dist/shared/markdown-it.BMSlR5u0.d.mts +0 -31
package/dist/async.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { n as MarkdownItShikiSetupOptions, t as MarkdownItShikiExtraOptions } from "./common-CiaeKkQk.mjs";
|
|
2
|
+
import "./core.mjs";
|
|
3
|
+
import { CodeToHastOptions } from "shiki";
|
|
4
|
+
import { MarkdownItAsync } from "markdown-it-async";
|
|
5
5
|
|
|
6
|
+
//#region src/async.d.ts
|
|
6
7
|
declare function setupMarkdownWithCodeToHtml(markdownit: MarkdownItAsync, codeToHtml: (code: string, options: CodeToHastOptions<any, any>) => Promise<string>, options: MarkdownItShikiSetupOptions): void;
|
|
7
8
|
/**
|
|
8
9
|
* Create a markdown-it-async plugin from a codeToHtml function.
|
|
@@ -10,5 +11,5 @@ declare function setupMarkdownWithCodeToHtml(markdownit: MarkdownItAsync, codeTo
|
|
|
10
11
|
* This plugin requires to be installed against a markdown-it-async instance.
|
|
11
12
|
*/
|
|
12
13
|
declare function fromAsyncCodeToHtml(codeToHtml: (code: string, options: CodeToHastOptions<any, any>) => Promise<string>, options: MarkdownItShikiSetupOptions): (markdownit: MarkdownItAsync) => Promise<void>;
|
|
13
|
-
|
|
14
|
-
export { MarkdownItShikiSetupOptions, fromAsyncCodeToHtml, setupMarkdownWithCodeToHtml };
|
|
14
|
+
//#endregion
|
|
15
|
+
export { type MarkdownItShikiExtraOptions, type MarkdownItShikiSetupOptions, fromAsyncCodeToHtml, setupMarkdownWithCodeToHtml };
|
package/dist/async.mjs
CHANGED
|
@@ -1,50 +1,44 @@
|
|
|
1
|
+
//#region src/async.ts
|
|
1
2
|
function setupMarkdownWithCodeToHtml(markdownit, codeToHtml, options) {
|
|
2
|
-
|
|
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
|
-
code = code.slice(0, -1);
|
|
31
|
-
}
|
|
32
|
-
return await codeToHtml(
|
|
33
|
-
code,
|
|
34
|
-
{
|
|
35
|
-
...codeOptions,
|
|
36
|
-
transformers: [
|
|
37
|
-
...builtInTransformer,
|
|
38
|
-
...codeOptions.transformers || []
|
|
39
|
-
]
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
};
|
|
3
|
+
const { parseMetaString, trimEndingNewline = true, defaultLanguage = "text" } = options;
|
|
4
|
+
markdownit.options.highlight = async (code, lang = "text", attrs) => {
|
|
5
|
+
if (lang === "") lang = defaultLanguage;
|
|
6
|
+
const meta = parseMetaString?.(attrs, code, lang) || {};
|
|
7
|
+
const codeOptions = {
|
|
8
|
+
...options,
|
|
9
|
+
lang,
|
|
10
|
+
meta: {
|
|
11
|
+
...options.meta,
|
|
12
|
+
...meta,
|
|
13
|
+
__raw: attrs
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const builtInTransformer = [];
|
|
17
|
+
builtInTransformer.push({
|
|
18
|
+
name: "@shikijs/markdown-it:block-class",
|
|
19
|
+
code(node) {
|
|
20
|
+
node.properties.class = `language-${lang}`;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
if (trimEndingNewline) {
|
|
24
|
+
if (code.endsWith("\n")) code = code.slice(0, -1);
|
|
25
|
+
}
|
|
26
|
+
return await codeToHtml(code, {
|
|
27
|
+
...codeOptions,
|
|
28
|
+
transformers: [...builtInTransformer, ...codeOptions.transformers || []]
|
|
29
|
+
});
|
|
30
|
+
};
|
|
43
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a markdown-it-async plugin from a codeToHtml function.
|
|
34
|
+
*
|
|
35
|
+
* This plugin requires to be installed against a markdown-it-async instance.
|
|
36
|
+
*/
|
|
44
37
|
function fromAsyncCodeToHtml(codeToHtml, options) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
return async function(markdownit) {
|
|
39
|
+
return setupMarkdownWithCodeToHtml(markdownit, codeToHtml, options);
|
|
40
|
+
};
|
|
48
41
|
}
|
|
49
42
|
|
|
50
|
-
|
|
43
|
+
//#endregion
|
|
44
|
+
export { fromAsyncCodeToHtml, setupMarkdownWithCodeToHtml };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BuiltinLanguage, BuiltinTheme, CodeOptionsMeta, CodeOptionsThemes, LanguageInput, TransformerOptions } from "shiki";
|
|
2
|
+
|
|
3
|
+
//#region src/common.d.ts
|
|
4
|
+
interface MarkdownItShikiExtraOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Custom meta string parser
|
|
7
|
+
* Return an object to merge with `meta`
|
|
8
|
+
*/
|
|
9
|
+
parseMetaString?: (metaString: string, code: string, lang: string) => Record<string, any> | undefined | null;
|
|
10
|
+
/**
|
|
11
|
+
* markdown-it's highlight function will add a trailing newline to the code.
|
|
12
|
+
*
|
|
13
|
+
* This integration removes the trailing newline to the code by default,
|
|
14
|
+
* you can turn this off by passing false.
|
|
15
|
+
*
|
|
16
|
+
* @default true
|
|
17
|
+
*/
|
|
18
|
+
trimEndingNewline?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* When lang of code block is empty string, it will work.
|
|
21
|
+
*
|
|
22
|
+
* @default 'text'
|
|
23
|
+
*/
|
|
24
|
+
defaultLanguage?: LanguageInput | BuiltinLanguage;
|
|
25
|
+
/**
|
|
26
|
+
* When lang of code block is not included in langs of options, it will be as a fallback lang.
|
|
27
|
+
*/
|
|
28
|
+
fallbackLanguage?: LanguageInput | BuiltinLanguage;
|
|
29
|
+
}
|
|
30
|
+
type MarkdownItShikiSetupOptions = CodeOptionsThemes<BuiltinTheme> & TransformerOptions & CodeOptionsMeta & MarkdownItShikiExtraOptions;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { MarkdownItShikiSetupOptions as n, MarkdownItShikiExtraOptions as t };
|
package/dist/core.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { HighlighterGeneric } from
|
|
3
|
-
import
|
|
4
|
-
export { a as MarkdownItShikiExtraOptions } from './shared/markdown-it.BMSlR5u0.mjs';
|
|
1
|
+
import { n as MarkdownItShikiSetupOptions, t as MarkdownItShikiExtraOptions } from "./common-CiaeKkQk.mjs";
|
|
2
|
+
import { HighlighterGeneric } from "shiki";
|
|
3
|
+
import MarkdownIt from "markdown-it";
|
|
5
4
|
|
|
5
|
+
//#region src/core.d.ts
|
|
6
6
|
declare function setupMarkdownIt(markdownit: MarkdownIt, highlighter: HighlighterGeneric<any, any>, options: MarkdownItShikiSetupOptions): void;
|
|
7
7
|
declare function fromHighlighter(highlighter: HighlighterGeneric<any, any>, options: MarkdownItShikiSetupOptions): (markdownit: MarkdownIt) => void;
|
|
8
|
-
|
|
9
|
-
export { MarkdownItShikiSetupOptions, fromHighlighter, setupMarkdownIt };
|
|
8
|
+
//#endregion
|
|
9
|
+
export { type MarkdownItShikiExtraOptions, type MarkdownItShikiSetupOptions, fromHighlighter, setupMarkdownIt };
|
package/dist/core.mjs
CHANGED
|
@@ -1,55 +1,41 @@
|
|
|
1
|
+
//#region src/core.ts
|
|
1
2
|
function setupMarkdownIt(markdownit, highlighter, options) {
|
|
2
|
-
|
|
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
|
-
if (trimEndingNewline) {
|
|
34
|
-
if (code.endsWith("\n"))
|
|
35
|
-
code = code.slice(0, -1);
|
|
36
|
-
}
|
|
37
|
-
return highlighter.codeToHtml(
|
|
38
|
-
code,
|
|
39
|
-
{
|
|
40
|
-
...codeOptions,
|
|
41
|
-
transformers: [
|
|
42
|
-
...builtInTransformer,
|
|
43
|
-
...codeOptions.transformers || []
|
|
44
|
-
]
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
};
|
|
3
|
+
const { parseMetaString, trimEndingNewline = true, defaultLanguage = "text", fallbackLanguage } = options;
|
|
4
|
+
const langs = highlighter.getLoadedLanguages();
|
|
5
|
+
markdownit.options.highlight = (code, lang = "text", attrs) => {
|
|
6
|
+
if (lang === "") lang = defaultLanguage;
|
|
7
|
+
if (fallbackLanguage && !langs.includes(lang)) lang = fallbackLanguage;
|
|
8
|
+
const meta = parseMetaString?.(attrs, code, lang) || {};
|
|
9
|
+
const codeOptions = {
|
|
10
|
+
...options,
|
|
11
|
+
lang,
|
|
12
|
+
meta: {
|
|
13
|
+
...options.meta,
|
|
14
|
+
...meta,
|
|
15
|
+
__raw: attrs
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const builtInTransformer = [];
|
|
19
|
+
builtInTransformer.push({
|
|
20
|
+
name: "@shikijs/markdown-it:block-class",
|
|
21
|
+
code(node) {
|
|
22
|
+
node.properties.class = `language-${lang}`;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
if (trimEndingNewline) {
|
|
26
|
+
if (code.endsWith("\n")) code = code.slice(0, -1);
|
|
27
|
+
}
|
|
28
|
+
return highlighter.codeToHtml(code, {
|
|
29
|
+
...codeOptions,
|
|
30
|
+
transformers: [...builtInTransformer, ...codeOptions.transformers || []]
|
|
31
|
+
});
|
|
32
|
+
};
|
|
48
33
|
}
|
|
49
34
|
function fromHighlighter(highlighter, options) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
35
|
+
return function(markdownit) {
|
|
36
|
+
setupMarkdownIt(markdownit, highlighter, options);
|
|
37
|
+
};
|
|
53
38
|
}
|
|
54
39
|
|
|
55
|
-
|
|
40
|
+
//#endregion
|
|
41
|
+
export { fromHighlighter, setupMarkdownIt };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export { fromHighlighter, setupMarkdownIt } from './core.mjs';
|
|
1
|
+
import { n as MarkdownItShikiSetupOptions, t as MarkdownItShikiExtraOptions } from "./common-CiaeKkQk.mjs";
|
|
2
|
+
import { fromHighlighter, setupMarkdownIt } from "./core.mjs";
|
|
3
|
+
import { BuiltinLanguage, LanguageInput } from "shiki";
|
|
4
|
+
import MarkdownIt from "markdown-it";
|
|
6
5
|
|
|
6
|
+
//#region src/index.d.ts
|
|
7
7
|
type MarkdownItShikiOptions = MarkdownItShikiSetupOptions & {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Language names to include.
|
|
10
|
+
*
|
|
11
|
+
* @default Object.keys(bundledLanguages)
|
|
12
|
+
*/
|
|
13
|
+
langs?: Array<LanguageInput | BuiltinLanguage>;
|
|
14
|
+
/**
|
|
15
|
+
* Alias of languages
|
|
16
|
+
* @example { 'my-lang': 'javascript' }
|
|
17
|
+
*/
|
|
18
|
+
langAlias?: Record<string, string>;
|
|
19
19
|
};
|
|
20
20
|
declare function markdownItShiki(options: MarkdownItShikiOptions): Promise<(markdownit: MarkdownIt) => void>;
|
|
21
|
-
|
|
22
|
-
export { MarkdownItShikiSetupOptions, markdownItShiki as default };
|
|
23
|
-
export type { MarkdownItShikiOptions };
|
|
21
|
+
//#endregion
|
|
22
|
+
export { MarkdownItShikiExtraOptions, MarkdownItShikiOptions, MarkdownItShikiSetupOptions, markdownItShiki as default, fromHighlighter, setupMarkdownIt };
|
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export { fromHighlighter } from './core.mjs';
|
|
1
|
+
import { fromHighlighter, setupMarkdownIt } from "./core.mjs";
|
|
2
|
+
import { bundledLanguages, createHighlighter } from "shiki";
|
|
4
3
|
|
|
4
|
+
//#region src/index.ts
|
|
5
5
|
async function markdownItShiki(options) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return function(markdownit) {
|
|
15
|
-
setupMarkdownIt(markdownit, highlighter, options);
|
|
16
|
-
};
|
|
6
|
+
const highlighter = await createHighlighter({
|
|
7
|
+
themes: ("themes" in options ? Object.values(options.themes) : [options.theme]).filter(Boolean),
|
|
8
|
+
langs: options.langs || Object.keys(bundledLanguages),
|
|
9
|
+
langAlias: options.langAlias || {}
|
|
10
|
+
});
|
|
11
|
+
return function(markdownit) {
|
|
12
|
+
setupMarkdownIt(markdownit, highlighter, options);
|
|
13
|
+
};
|
|
17
14
|
}
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
//#endregion
|
|
17
|
+
export { markdownItShiki as default, fromHighlighter, setupMarkdownIt };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shikijs/markdown-it",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0",
|
|
5
5
|
"description": "markdown-it integration for shiki",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
"files": [
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=20"
|
|
33
|
+
},
|
|
31
34
|
"peerDependencies": {
|
|
32
35
|
"markdown-it-async": "^2.2.0"
|
|
33
36
|
},
|
|
@@ -37,16 +40,16 @@
|
|
|
37
40
|
}
|
|
38
41
|
},
|
|
39
42
|
"dependencies": {
|
|
40
|
-
"markdown-it": "^14.1.
|
|
41
|
-
"shiki": "
|
|
43
|
+
"markdown-it": "^14.1.1",
|
|
44
|
+
"shiki": "4.0.0"
|
|
42
45
|
},
|
|
43
46
|
"devDependencies": {
|
|
44
47
|
"@types/markdown-it": "^14.1.2",
|
|
45
48
|
"markdown-it-async": "^2.2.0",
|
|
46
|
-
"@shikijs/transformers": "
|
|
49
|
+
"@shikijs/transformers": "4.0.0"
|
|
47
50
|
},
|
|
48
51
|
"scripts": {
|
|
49
|
-
"build": "
|
|
50
|
-
"dev": "
|
|
52
|
+
"build": "tsdown",
|
|
53
|
+
"dev": "tsdown --watch"
|
|
51
54
|
}
|
|
52
55
|
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { LanguageInput, BuiltinLanguage, CodeOptionsThemes, BuiltinTheme, TransformerOptions, CodeOptionsMeta } from 'shiki';
|
|
2
|
-
|
|
3
|
-
interface MarkdownItShikiExtraOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Custom meta string parser
|
|
6
|
-
* Return an object to merge with `meta`
|
|
7
|
-
*/
|
|
8
|
-
parseMetaString?: (metaString: string, code: string, lang: string) => Record<string, any> | undefined | null;
|
|
9
|
-
/**
|
|
10
|
-
* markdown-it's highlight function will add a trailing newline to the code.
|
|
11
|
-
*
|
|
12
|
-
* This integration removes the trailing newline to the code by default,
|
|
13
|
-
* you can turn this off by passing false.
|
|
14
|
-
*
|
|
15
|
-
* @default true
|
|
16
|
-
*/
|
|
17
|
-
trimEndingNewline?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* When lang of code block is empty string, it will work.
|
|
20
|
-
*
|
|
21
|
-
* @default 'text'
|
|
22
|
-
*/
|
|
23
|
-
defaultLanguage?: LanguageInput | BuiltinLanguage;
|
|
24
|
-
/**
|
|
25
|
-
* When lang of code block is not included in langs of options, it will be as a fallback lang.
|
|
26
|
-
*/
|
|
27
|
-
fallbackLanguage?: LanguageInput | BuiltinLanguage;
|
|
28
|
-
}
|
|
29
|
-
type MarkdownItShikiSetupOptions = CodeOptionsThemes<BuiltinTheme> & TransformerOptions & CodeOptionsMeta & MarkdownItShikiExtraOptions;
|
|
30
|
-
|
|
31
|
-
export type { MarkdownItShikiSetupOptions as M, MarkdownItShikiExtraOptions as a };
|