svem
Version:
Svelte in Markdown preprocessor
42 lines (39 loc) • 1.52 kB
TypeScript
import { TransformerNotationDiffOptions } from '@shikijs/transformers';
import { Plugin } from 'unified';
import { Highlighter } from 'shiki';
import { XNode, XAttributes } from './attribute.js';
import { XHTMLNode } from './html.js';
import 'mdast';
type XCodeNode = XNode & {
type: 'code';
lang: string;
value: string;
};
type CodeAttributes = XAttributes & {
file?: string;
title?: string;
};
type CodeBlockTheme = {
light: string;
dark?: string;
};
type CreateBlockOptions = {
lang: string;
themes: CodeBlockTheme;
diffOptions?: TransformerNotationDiffOptions | false;
};
type CodeHighlightOptions = Omit<CreateBlockOptions, 'lang'> & {
langs: string[];
themes: CodeBlockTheme;
allowCopy?: boolean;
transform?: (code: string) => string;
};
/**
* Wrap and highlight code blocks with shiki.
* @param {(Omit<CreateBlockOptions, 'lang'> & {langs: string[], themes: CodeBlockTheme, embedRaw?: boolean, transform?: (code: string) => string}) | void} options
* @returns {(tree) => Promise<void>}
*/
declare const remarkCodeHighlight: Plugin<[CodeHighlightOptions | void], XNode>;
declare const createWrapper: (code: string, lang: string, attributes: CodeAttributes, rawCode?: string) => XHTMLNode;
declare function highlight(shiki: Highlighter, code: string, options: CreateBlockOptions): string;
export { type CodeAttributes, type CodeBlockTheme, type CodeHighlightOptions, type CreateBlockOptions, type XCodeNode, createWrapper, highlight, remarkCodeHighlight };