feature: vor und nachteile

This commit is contained in:
Hikyu
2026-05-31 13:54:31 +02:00
parent 552a947a1c
commit e3dad17446
23270 changed files with 3024794 additions and 200 deletions
+22
View File
@@ -0,0 +1,22 @@
MIT License
Copyright (c) 2021 Pine Wu
Copyright (c) 2023 Anthony Fu <https://github.com/antfu>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+9
View File
@@ -0,0 +1,9 @@
# @shikijs/markdown-it
[markdown-it](https://markdown-it.github.io/) plugin for [shiki](https://github.com/shikijs/shiki)
[Documentation](https://shiki.style/packages/markdown-it)
## License
MIT
+34
View File
@@ -0,0 +1,34 @@
import MarkdownIt from 'markdown-it';
import { LanguageInput, BuiltinLanguage, CodeOptionsThemes, BuiltinTheme, TransformerOptions, CodeOptionsMeta, HighlighterGeneric } from 'shiki';
interface MarkdownItShikiExtraOptions {
/**
* Custom meta string parser
* Return an object to merge with `meta`
*/
parseMetaString?: (metaString: string, code: string, lang: string) => Record<string, any> | undefined | null;
/**
* markdown-it's highlight function will add a trailing newline to the code.
*
* This integration removes the trailing newline to the code by default,
* you can turn this off by passing false.
*
* @default true
*/
trimEndingNewline?: boolean;
/**
* When lang of code block is empty string, it will work.
*
* @default 'text'
*/
defaultLanguage?: LanguageInput | BuiltinLanguage;
/**
* When lang of code block is not included in langs of options, it will be as a fallback lang.
*/
fallbackLanguage?: LanguageInput | BuiltinLanguage;
}
type MarkdownItShikiSetupOptions = CodeOptionsThemes<BuiltinTheme> & TransformerOptions & CodeOptionsMeta & MarkdownItShikiExtraOptions;
declare function setupMarkdownIt(markdownit: MarkdownIt, highlighter: HighlighterGeneric<any, any>, options: MarkdownItShikiSetupOptions): void;
declare function fromHighlighter(highlighter: HighlighterGeneric<any, any>, options: MarkdownItShikiSetupOptions): (markdownit: MarkdownIt) => void;
export { type MarkdownItShikiExtraOptions, type MarkdownItShikiSetupOptions, fromHighlighter, setupMarkdownIt };
+34
View File
@@ -0,0 +1,34 @@
import MarkdownIt from 'markdown-it';
import { LanguageInput, BuiltinLanguage, CodeOptionsThemes, BuiltinTheme, TransformerOptions, CodeOptionsMeta, HighlighterGeneric } from 'shiki';
interface MarkdownItShikiExtraOptions {
/**
* Custom meta string parser
* Return an object to merge with `meta`
*/
parseMetaString?: (metaString: string, code: string, lang: string) => Record<string, any> | undefined | null;
/**
* markdown-it's highlight function will add a trailing newline to the code.
*
* This integration removes the trailing newline to the code by default,
* you can turn this off by passing false.
*
* @default true
*/
trimEndingNewline?: boolean;
/**
* When lang of code block is empty string, it will work.
*
* @default 'text'
*/
defaultLanguage?: LanguageInput | BuiltinLanguage;
/**
* When lang of code block is not included in langs of options, it will be as a fallback lang.
*/
fallbackLanguage?: LanguageInput | BuiltinLanguage;
}
type MarkdownItShikiSetupOptions = CodeOptionsThemes<BuiltinTheme> & TransformerOptions & CodeOptionsMeta & MarkdownItShikiExtraOptions;
declare function setupMarkdownIt(markdownit: MarkdownIt, highlighter: HighlighterGeneric<any, any>, options: MarkdownItShikiSetupOptions): void;
declare function fromHighlighter(highlighter: HighlighterGeneric<any, any>, options: MarkdownItShikiSetupOptions): (markdownit: MarkdownIt) => void;
export { type MarkdownItShikiExtraOptions, type MarkdownItShikiSetupOptions, fromHighlighter, setupMarkdownIt };
+55
View File
@@ -0,0 +1,55 @@
function setupMarkdownIt(markdownit, highlighter, options) {
const {
parseMetaString,
trimEndingNewline = true,
defaultLanguage = "text",
fallbackLanguage
} = options;
const langs = highlighter.getLoadedLanguages();
markdownit.options.highlight = (code, lang = "text", attrs) => {
if (lang === "") {
lang = defaultLanguage;
}
if (fallbackLanguage && !langs.includes(lang)) {
lang = fallbackLanguage;
}
const meta = parseMetaString?.(attrs, code, lang) || {};
const codeOptions = {
...options,
lang,
meta: {
...options.meta,
...meta,
__raw: attrs
}
};
const builtInTransformer = [];
builtInTransformer.push({
name: "@shikijs/markdown-it:block-class",
code(node) {
node.properties.class = `language-${lang}`;
}
});
if (trimEndingNewline) {
if (code.endsWith("\n"))
code = code.slice(0, -1);
}
return highlighter.codeToHtml(
code,
{
...codeOptions,
transformers: [
...builtInTransformer,
...codeOptions.transformers || []
]
}
);
};
}
function fromHighlighter(highlighter, options) {
return function(markdownit) {
setupMarkdownIt(markdownit, highlighter, options);
};
}
export { fromHighlighter, setupMarkdownIt };
+16
View File
@@ -0,0 +1,16 @@
import MarkdownIt from 'markdown-it';
import { LanguageInput, BuiltinLanguage } from 'shiki';
import { MarkdownItShikiSetupOptions } from './core.mjs';
export { MarkdownItShikiExtraOptions, fromHighlighter, setupMarkdownIt } from './core.mjs';
type MarkdownItShikiOptions = MarkdownItShikiSetupOptions & {
/**
* Language names to include.
*
* @default Object.keys(bundledLanguages)
*/
langs?: Array<LanguageInput | BuiltinLanguage>;
};
declare function markdownItShiki(options: MarkdownItShikiOptions): Promise<(markdownit: MarkdownIt) => void>;
export { type MarkdownItShikiOptions, MarkdownItShikiSetupOptions, markdownItShiki as default };
+16
View File
@@ -0,0 +1,16 @@
import MarkdownIt from 'markdown-it';
import { LanguageInput, BuiltinLanguage } from 'shiki';
import { MarkdownItShikiSetupOptions } from './core.js';
export { MarkdownItShikiExtraOptions, fromHighlighter, setupMarkdownIt } from './core.js';
type MarkdownItShikiOptions = MarkdownItShikiSetupOptions & {
/**
* Language names to include.
*
* @default Object.keys(bundledLanguages)
*/
langs?: Array<LanguageInput | BuiltinLanguage>;
};
declare function markdownItShiki(options: MarkdownItShikiOptions): Promise<(markdownit: MarkdownIt) => void>;
export { type MarkdownItShikiOptions, MarkdownItShikiSetupOptions, markdownItShiki as default };
+16
View File
@@ -0,0 +1,16 @@
import { createHighlighter, bundledLanguages } from 'shiki';
import { setupMarkdownIt } from './core.mjs';
export { fromHighlighter } from './core.mjs';
async function markdownItShiki(options) {
const themeNames = ("themes" in options ? Object.values(options.themes) : [options.theme]).filter(Boolean);
const highlighter = await createHighlighter({
themes: themeNames,
langs: options.langs || Object.keys(bundledLanguages)
});
return function(markdownit) {
setupMarkdownIt(markdownit, highlighter, options);
};
}
export { markdownItShiki as default, setupMarkdownIt };
+59
View File
@@ -0,0 +1,59 @@
{
"name": "@shikijs/markdown-it",
"type": "module",
"version": "1.29.2",
"description": "markdown-it integration for shiki",
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
"license": "MIT",
"homepage": "https://github.com/shikijs/shiki#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/shikijs/shiki.git",
"directory": "packages/markdown-it"
},
"bugs": "https://github.com/shikijs/shiki/issues",
"keywords": [
"shiki",
"markdown-it"
],
"sideEffects": false,
"exports": {
".": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"./core": {
"types": "./dist/core.d.mts",
"default": "./dist/core.mjs"
}
},
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.mts",
"typesVersions": {
"*": {
"core": [
"./dist/core.d.mts"
],
"*": [
"./dist/*",
"./*"
]
}
},
"files": [
"dist"
],
"dependencies": {
"markdown-it": "^14.1.0",
"shiki": "1.29.2"
},
"devDependencies": {
"@types/markdown-it": "^14.1.2",
"@shikijs/transformers": "1.29.2"
},
"scripts": {
"build": "unbuild",
"dev": "unbuild --stub"
}
}