@shikijs/markdown-it 1.0.0-beta.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/LICENSE +22 -0
- package/README.md +9 -0
- package/dist/core.d.mts +22 -0
- package/dist/core.d.ts +22 -0
- package/dist/core.mjs +51 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.mjs +17 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Pine Wu
|
|
4
|
+
Copyright (c) 2023 Anthony Fu <https://github.com/antfu>
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
package/dist/core.d.mts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import MarkdownIt from 'markdown-it';
|
|
2
|
+
import { CodeOptionsThemes, BuiltinTheme, TransformerOptions, CodeOptionsMeta, HighlighterGeneric } from 'shiki';
|
|
3
|
+
|
|
4
|
+
interface MarkdownItShikiExtraOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Add `highlighted` class to lines defined in after codeblock
|
|
7
|
+
*
|
|
8
|
+
* @deprecated Use [transformerNotationHighlight](https://shiki.style/packages/transformers#transformernotationhighlight) instead
|
|
9
|
+
* @default false
|
|
10
|
+
*/
|
|
11
|
+
highlightLines?: boolean | string;
|
|
12
|
+
/**
|
|
13
|
+
* Custom meta string parser
|
|
14
|
+
* Return an object to merge with `meta`
|
|
15
|
+
*/
|
|
16
|
+
parseMetaString?: (metaString: string, code: string, lang: string) => Record<string, any> | undefined | null;
|
|
17
|
+
}
|
|
18
|
+
type MarkdownItShikiSetupOptions = CodeOptionsThemes<BuiltinTheme> & TransformerOptions & CodeOptionsMeta & MarkdownItShikiExtraOptions;
|
|
19
|
+
declare function setupMarkdownIt(markdownit: MarkdownIt, highlighter: HighlighterGeneric<any, any>, options: MarkdownItShikiSetupOptions): void;
|
|
20
|
+
declare function fromHighlighter(highlighter: HighlighterGeneric<any, any>, options: MarkdownItShikiSetupOptions): (markdownit: MarkdownIt) => void;
|
|
21
|
+
|
|
22
|
+
export { type MarkdownItShikiExtraOptions, type MarkdownItShikiSetupOptions, fromHighlighter, setupMarkdownIt };
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import MarkdownIt from 'markdown-it';
|
|
2
|
+
import { CodeOptionsThemes, BuiltinTheme, TransformerOptions, CodeOptionsMeta, HighlighterGeneric } from 'shiki';
|
|
3
|
+
|
|
4
|
+
interface MarkdownItShikiExtraOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Add `highlighted` class to lines defined in after codeblock
|
|
7
|
+
*
|
|
8
|
+
* @deprecated Use [transformerNotationHighlight](https://shiki.style/packages/transformers#transformernotationhighlight) instead
|
|
9
|
+
* @default false
|
|
10
|
+
*/
|
|
11
|
+
highlightLines?: boolean | string;
|
|
12
|
+
/**
|
|
13
|
+
* Custom meta string parser
|
|
14
|
+
* Return an object to merge with `meta`
|
|
15
|
+
*/
|
|
16
|
+
parseMetaString?: (metaString: string, code: string, lang: string) => Record<string, any> | undefined | null;
|
|
17
|
+
}
|
|
18
|
+
type MarkdownItShikiSetupOptions = CodeOptionsThemes<BuiltinTheme> & TransformerOptions & CodeOptionsMeta & MarkdownItShikiExtraOptions;
|
|
19
|
+
declare function setupMarkdownIt(markdownit: MarkdownIt, highlighter: HighlighterGeneric<any, any>, options: MarkdownItShikiSetupOptions): void;
|
|
20
|
+
declare function fromHighlighter(highlighter: HighlighterGeneric<any, any>, options: MarkdownItShikiSetupOptions): (markdownit: MarkdownIt) => void;
|
|
21
|
+
|
|
22
|
+
export { type MarkdownItShikiExtraOptions, type MarkdownItShikiSetupOptions, fromHighlighter, setupMarkdownIt };
|
package/dist/core.mjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { transformerMetaHighlight } from '@shikijs/transformers';
|
|
2
|
+
|
|
3
|
+
function setupMarkdownIt(markdownit, highlighter, options) {
|
|
4
|
+
const {
|
|
5
|
+
highlightLines = false,
|
|
6
|
+
parseMetaString
|
|
7
|
+
} = options;
|
|
8
|
+
markdownit.options.highlight = (code, lang = "text", attrs) => {
|
|
9
|
+
const meta = parseMetaString?.(attrs, code, lang) || {};
|
|
10
|
+
const codeOptions = {
|
|
11
|
+
...options,
|
|
12
|
+
lang,
|
|
13
|
+
meta: {
|
|
14
|
+
...options.meta,
|
|
15
|
+
...meta,
|
|
16
|
+
__raw: attrs
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const builtInTransformer = [];
|
|
20
|
+
if (highlightLines) {
|
|
21
|
+
builtInTransformer.push(
|
|
22
|
+
transformerMetaHighlight({
|
|
23
|
+
className: highlightLines === true ? "highlighted" : highlightLines
|
|
24
|
+
})
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
builtInTransformer.push({
|
|
28
|
+
name: "@shikijs/markdown-it:block-class",
|
|
29
|
+
code(node) {
|
|
30
|
+
node.properties.class = `language-${lang}`;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return highlighter.codeToHtml(
|
|
34
|
+
code,
|
|
35
|
+
{
|
|
36
|
+
...codeOptions,
|
|
37
|
+
transformers: [
|
|
38
|
+
...builtInTransformer,
|
|
39
|
+
...codeOptions.transformers || []
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function fromHighlighter(highlighter, options) {
|
|
46
|
+
return function(markdownit) {
|
|
47
|
+
setupMarkdownIt(markdownit, highlighter, options);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { fromHighlighter, setupMarkdownIt };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import MarkdownIt from 'markdown-it';
|
|
2
|
+
import { LanguageInput, BuiltinLanguage } from 'shiki';
|
|
3
|
+
import { MarkdownItShikiSetupOptions } from './core.mjs';
|
|
4
|
+
export { MarkdownItShikiExtraOptions, fromHighlighter, setupMarkdownIt } from './core.mjs';
|
|
5
|
+
|
|
6
|
+
type MarkdownItShikiOptions = MarkdownItShikiSetupOptions & {
|
|
7
|
+
/**
|
|
8
|
+
* Language names to include.
|
|
9
|
+
*
|
|
10
|
+
* @default Object.keys(bundledLanguages)
|
|
11
|
+
*/
|
|
12
|
+
langs?: Array<LanguageInput | BuiltinLanguage>;
|
|
13
|
+
};
|
|
14
|
+
declare function markdownItShiki(options: MarkdownItShikiOptions): Promise<(markdownit: MarkdownIt) => void>;
|
|
15
|
+
|
|
16
|
+
export { type MarkdownItShikiOptions, MarkdownItShikiSetupOptions, markdownItShiki as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import MarkdownIt from 'markdown-it';
|
|
2
|
+
import { LanguageInput, BuiltinLanguage } from 'shiki';
|
|
3
|
+
import { MarkdownItShikiSetupOptions } from './core.js';
|
|
4
|
+
export { MarkdownItShikiExtraOptions, fromHighlighter, setupMarkdownIt } from './core.js';
|
|
5
|
+
|
|
6
|
+
type MarkdownItShikiOptions = MarkdownItShikiSetupOptions & {
|
|
7
|
+
/**
|
|
8
|
+
* Language names to include.
|
|
9
|
+
*
|
|
10
|
+
* @default Object.keys(bundledLanguages)
|
|
11
|
+
*/
|
|
12
|
+
langs?: Array<LanguageInput | BuiltinLanguage>;
|
|
13
|
+
};
|
|
14
|
+
declare function markdownItShiki(options: MarkdownItShikiOptions): Promise<(markdownit: MarkdownIt) => void>;
|
|
15
|
+
|
|
16
|
+
export { type MarkdownItShikiOptions, MarkdownItShikiSetupOptions, markdownItShiki as default };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getHighlighter, bundledLanguages } from 'shiki';
|
|
2
|
+
import { setupMarkdownIt } from './core.mjs';
|
|
3
|
+
export { fromHighlighter } from './core.mjs';
|
|
4
|
+
import '@shikijs/transformers';
|
|
5
|
+
|
|
6
|
+
async function markdownItShiki(options) {
|
|
7
|
+
const themeNames = ("themes" in options ? Object.values(options.themes) : [options.theme]).filter(Boolean);
|
|
8
|
+
const highlighter = await getHighlighter({
|
|
9
|
+
themes: themeNames,
|
|
10
|
+
langs: options.langs || Object.keys(bundledLanguages)
|
|
11
|
+
});
|
|
12
|
+
return function(markdownit) {
|
|
13
|
+
setupMarkdownIt(markdownit, highlighter, options);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { markdownItShiki as default, setupMarkdownIt };
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@shikijs/markdown-it",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0-beta.0",
|
|
5
|
+
"description": "markdown-it integration for shiki",
|
|
6
|
+
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/shikijs/shiki#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/shikijs/shiki.git",
|
|
12
|
+
"directory": "packages/markdown-it"
|
|
13
|
+
},
|
|
14
|
+
"bugs": "https://github.com/shikijs/shiki/issues",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"shiki",
|
|
17
|
+
"markdown-it"
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.mts",
|
|
23
|
+
"default": "./dist/index.mjs"
|
|
24
|
+
},
|
|
25
|
+
"./core": {
|
|
26
|
+
"types": "./dist/core.d.mts",
|
|
27
|
+
"default": "./dist/core.mjs"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"main": "./dist/index.mjs",
|
|
31
|
+
"module": "./dist/index.mjs",
|
|
32
|
+
"types": "./dist/index.d.mts",
|
|
33
|
+
"typesVersions": {
|
|
34
|
+
"*": {
|
|
35
|
+
"core": [
|
|
36
|
+
"./dist/core.d.mts"
|
|
37
|
+
],
|
|
38
|
+
"*": [
|
|
39
|
+
"./dist/*",
|
|
40
|
+
"./*"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist"
|
|
46
|
+
],
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"markdown-it": "^14.0.0",
|
|
49
|
+
"@shikijs/transformers": "1.0.0-beta.0",
|
|
50
|
+
"shiki": "1.0.0-beta.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/markdown-it": "^13.0.7"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "unbuild",
|
|
57
|
+
"dev": "unbuild --stub"
|
|
58
|
+
}
|
|
59
|
+
}
|