@shikijs/markdown-it 2.0.3 → 2.2.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 +14 -0
- package/dist/async.d.ts +14 -0
- package/dist/async.mjs +50 -0
- package/dist/core.d.mts +4 -29
- package/dist/core.d.ts +4 -29
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/shared/markdown-it.BMSlR5u0.d.mts +31 -0
- package/dist/shared/markdown-it.BMSlR5u0.d.ts +31 -0
- package/package.json +19 -3
package/dist/async.d.mts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MarkdownItAsync } from 'markdown-it-async';
|
|
2
|
+
import { CodeToHastOptions } from 'shiki';
|
|
3
|
+
import { M as MarkdownItShikiSetupOptions } from './shared/markdown-it.BMSlR5u0.mjs';
|
|
4
|
+
export { a as MarkdownItShikiExtraOptions } from './shared/markdown-it.BMSlR5u0.mjs';
|
|
5
|
+
|
|
6
|
+
declare function setupMarkdownWithCodeToHtml(markdownit: MarkdownItAsync, codeToHtml: (code: string, options: CodeToHastOptions<any, any>) => Promise<string>, options: MarkdownItShikiSetupOptions): void;
|
|
7
|
+
/**
|
|
8
|
+
* Create a markdown-it-async plugin from a codeToHtml function.
|
|
9
|
+
*
|
|
10
|
+
* This plugin requires to be installed against a markdown-it-async instance.
|
|
11
|
+
*/
|
|
12
|
+
declare function fromAsyncCodeToHtml(codeToHtml: (code: string, options: CodeToHastOptions<any, any>) => Promise<string>, options: MarkdownItShikiSetupOptions): (markdownit: MarkdownItAsync) => Promise<void>;
|
|
13
|
+
|
|
14
|
+
export { MarkdownItShikiSetupOptions, fromAsyncCodeToHtml, setupMarkdownWithCodeToHtml };
|
package/dist/async.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MarkdownItAsync } from 'markdown-it-async';
|
|
2
|
+
import { CodeToHastOptions } from 'shiki';
|
|
3
|
+
import { M as MarkdownItShikiSetupOptions } from './shared/markdown-it.BMSlR5u0.js';
|
|
4
|
+
export { a as MarkdownItShikiExtraOptions } from './shared/markdown-it.BMSlR5u0.js';
|
|
5
|
+
|
|
6
|
+
declare function setupMarkdownWithCodeToHtml(markdownit: MarkdownItAsync, codeToHtml: (code: string, options: CodeToHastOptions<any, any>) => Promise<string>, options: MarkdownItShikiSetupOptions): void;
|
|
7
|
+
/**
|
|
8
|
+
* Create a markdown-it-async plugin from a codeToHtml function.
|
|
9
|
+
*
|
|
10
|
+
* This plugin requires to be installed against a markdown-it-async instance.
|
|
11
|
+
*/
|
|
12
|
+
declare function fromAsyncCodeToHtml(codeToHtml: (code: string, options: CodeToHastOptions<any, any>) => Promise<string>, options: MarkdownItShikiSetupOptions): (markdownit: MarkdownItAsync) => Promise<void>;
|
|
13
|
+
|
|
14
|
+
export { MarkdownItShikiSetupOptions, fromAsyncCodeToHtml, setupMarkdownWithCodeToHtml };
|
package/dist/async.mjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
function setupMarkdownWithCodeToHtml(markdownit, codeToHtml, options) {
|
|
2
|
+
const {
|
|
3
|
+
parseMetaString,
|
|
4
|
+
trimEndingNewline = true,
|
|
5
|
+
defaultLanguage = "text"
|
|
6
|
+
} = options;
|
|
7
|
+
markdownit.options.highlight = async (code, lang = "text", attrs) => {
|
|
8
|
+
if (lang === "") {
|
|
9
|
+
lang = defaultLanguage;
|
|
10
|
+
}
|
|
11
|
+
const meta = parseMetaString?.(attrs, code, lang) || {};
|
|
12
|
+
const codeOptions = {
|
|
13
|
+
...options,
|
|
14
|
+
lang,
|
|
15
|
+
meta: {
|
|
16
|
+
...options.meta,
|
|
17
|
+
...meta,
|
|
18
|
+
__raw: attrs
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const builtInTransformer = [];
|
|
22
|
+
builtInTransformer.push({
|
|
23
|
+
name: "@shikijs/markdown-it:block-class",
|
|
24
|
+
code(node) {
|
|
25
|
+
node.properties.class = `language-${lang}`;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
if (trimEndingNewline) {
|
|
29
|
+
if (code.endsWith("\n"))
|
|
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
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function fromAsyncCodeToHtml(codeToHtml, options) {
|
|
45
|
+
return async function(markdownit) {
|
|
46
|
+
return setupMarkdownWithCodeToHtml(markdownit, codeToHtml, options);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { fromAsyncCodeToHtml, setupMarkdownWithCodeToHtml };
|
package/dist/core.d.mts
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
1
|
import MarkdownIt from 'markdown-it';
|
|
2
|
-
import {
|
|
2
|
+
import { HighlighterGeneric } from 'shiki';
|
|
3
|
+
import { M as MarkdownItShikiSetupOptions } from './shared/markdown-it.BMSlR5u0.mjs';
|
|
4
|
+
export { a as MarkdownItShikiExtraOptions } from './shared/markdown-it.BMSlR5u0.mjs';
|
|
3
5
|
|
|
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
6
|
declare function setupMarkdownIt(markdownit: MarkdownIt, highlighter: HighlighterGeneric<any, any>, options: MarkdownItShikiSetupOptions): void;
|
|
32
7
|
declare function fromHighlighter(highlighter: HighlighterGeneric<any, any>, options: MarkdownItShikiSetupOptions): (markdownit: MarkdownIt) => void;
|
|
33
8
|
|
|
34
|
-
export {
|
|
9
|
+
export { MarkdownItShikiSetupOptions, fromHighlighter, setupMarkdownIt };
|
package/dist/core.d.ts
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
1
|
import MarkdownIt from 'markdown-it';
|
|
2
|
-
import {
|
|
2
|
+
import { HighlighterGeneric } from 'shiki';
|
|
3
|
+
import { M as MarkdownItShikiSetupOptions } from './shared/markdown-it.BMSlR5u0.js';
|
|
4
|
+
export { a as MarkdownItShikiExtraOptions } from './shared/markdown-it.BMSlR5u0.js';
|
|
3
5
|
|
|
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
6
|
declare function setupMarkdownIt(markdownit: MarkdownIt, highlighter: HighlighterGeneric<any, any>, options: MarkdownItShikiSetupOptions): void;
|
|
32
7
|
declare function fromHighlighter(highlighter: HighlighterGeneric<any, any>, options: MarkdownItShikiSetupOptions): (markdownit: MarkdownIt) => void;
|
|
33
8
|
|
|
34
|
-
export {
|
|
9
|
+
export { MarkdownItShikiSetupOptions, fromHighlighter, setupMarkdownIt };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import MarkdownIt from 'markdown-it';
|
|
2
2
|
import { LanguageInput, BuiltinLanguage } from 'shiki';
|
|
3
|
-
import { MarkdownItShikiSetupOptions } from './
|
|
4
|
-
export {
|
|
3
|
+
import { M as MarkdownItShikiSetupOptions } from './shared/markdown-it.BMSlR5u0.mjs';
|
|
4
|
+
export { a as MarkdownItShikiExtraOptions } from './shared/markdown-it.BMSlR5u0.mjs';
|
|
5
|
+
export { fromHighlighter, setupMarkdownIt } from './core.mjs';
|
|
5
6
|
|
|
6
7
|
type MarkdownItShikiOptions = MarkdownItShikiSetupOptions & {
|
|
7
8
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import MarkdownIt from 'markdown-it';
|
|
2
2
|
import { LanguageInput, BuiltinLanguage } from 'shiki';
|
|
3
|
-
import { MarkdownItShikiSetupOptions } from './
|
|
4
|
-
export {
|
|
3
|
+
import { M as MarkdownItShikiSetupOptions } from './shared/markdown-it.BMSlR5u0.js';
|
|
4
|
+
export { a as MarkdownItShikiExtraOptions } from './shared/markdown-it.BMSlR5u0.js';
|
|
5
|
+
export { fromHighlighter, setupMarkdownIt } from './core.js';
|
|
5
6
|
|
|
6
7
|
type MarkdownItShikiOptions = MarkdownItShikiSetupOptions & {
|
|
7
8
|
/**
|
|
@@ -0,0 +1,31 @@
|
|
|
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 };
|
|
@@ -0,0 +1,31 @@
|
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shikijs/markdown-it",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.2.0",
|
|
5
5
|
"description": "markdown-it integration for shiki",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -25,6 +25,10 @@
|
|
|
25
25
|
"./core": {
|
|
26
26
|
"types": "./dist/core.d.mts",
|
|
27
27
|
"default": "./dist/core.mjs"
|
|
28
|
+
},
|
|
29
|
+
"./async": {
|
|
30
|
+
"types": "./dist/async.d.mts",
|
|
31
|
+
"default": "./dist/async.mjs"
|
|
28
32
|
}
|
|
29
33
|
},
|
|
30
34
|
"main": "./dist/index.mjs",
|
|
@@ -35,6 +39,9 @@
|
|
|
35
39
|
"core": [
|
|
36
40
|
"./dist/core.d.mts"
|
|
37
41
|
],
|
|
42
|
+
"async": [
|
|
43
|
+
"./dist/async.d.mts"
|
|
44
|
+
],
|
|
38
45
|
"*": [
|
|
39
46
|
"./dist/*",
|
|
40
47
|
"./*"
|
|
@@ -44,13 +51,22 @@
|
|
|
44
51
|
"files": [
|
|
45
52
|
"dist"
|
|
46
53
|
],
|
|
54
|
+
"peerDependencies": {
|
|
55
|
+
"markdown-it-async": "^2.0.0"
|
|
56
|
+
},
|
|
57
|
+
"peerDependenciesMeta": {
|
|
58
|
+
"markdown-it-async": {
|
|
59
|
+
"optional": true
|
|
60
|
+
}
|
|
61
|
+
},
|
|
47
62
|
"dependencies": {
|
|
48
63
|
"markdown-it": "^14.1.0",
|
|
49
|
-
"shiki": "2.0
|
|
64
|
+
"shiki": "2.2.0"
|
|
50
65
|
},
|
|
51
66
|
"devDependencies": {
|
|
52
67
|
"@types/markdown-it": "^14.1.2",
|
|
53
|
-
"
|
|
68
|
+
"markdown-it-async": "^2.0.0",
|
|
69
|
+
"@shikijs/transformers": "2.2.0"
|
|
54
70
|
},
|
|
55
71
|
"scripts": {
|
|
56
72
|
"build": "unbuild",
|