Skip to content

Commit

Permalink
feat: migrate to Shikiji (#109)
Browse files Browse the repository at this point in the history
Co-authored-by: Dimitri POSTOLOV <en3m@ya.ru>
  • Loading branch information
atomiks and Dimitri POSTOLOV authored Dec 3, 2023
1 parent 00e5451 commit b682355
Show file tree
Hide file tree
Showing 54 changed files with 7,255 additions and 16,352 deletions.
15 changes: 11 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import type { Highlighter, IShikiTheme } from 'shiki';
import type {
BundledHighlighterOptions,
Highlighter,
BuiltinTheme,
ThemeRegistrationRaw,
ShikijiTransformer,
} from 'shikiji';
import type { Transformer } from 'unified';
import type { Root, Element, Properties } from 'hast';

Expand All @@ -11,16 +17,17 @@ export type CharsElement = Omit<Element, 'properties' | 'children'> & {
children: Array<Element | Text>;
};

type Theme = IShikiTheme | string;
type Theme = BuiltinTheme | ThemeRegistrationRaw;

export interface Options {
grid?: boolean;
theme?: Theme | Record<string, Theme>;
keepBackground?: boolean;
defaultLang?: string | { block?: string; inline?: string };
tokensMap?: Record<string, string>;
transformers?: ShikijiTransformer[];
filterMetaString?(str: string): string;
getHighlighter?(options: Pick<Options, 'theme'>): Promise<Highlighter>;
getHighlighter?(options: BundledHighlighterOptions): Promise<Highlighter>;
onVisitLine?(element: LineElement): void;
onVisitHighlightedLine?(element: LineElement): void;
onVisitHighlightedChars?(element: CharsElement, id: string | undefined): void;
Expand All @@ -29,5 +36,5 @@ export interface Options {
}

export default function rehypePrettyCode(
options?: void | Options | undefined
options?: void | Options | undefined,
): void | Transformer<Root, Root>;
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ unified().use(rehypePrettyCode, {
if (id) {
// If the word spans across syntax boundaries (e.g. punctuation), remove
// colors from the child elements.
if (element.properties['data-highlighted-chars-wrapper']) {
if (element.properties['data-highlighted-chars-mark']) {
element.children.forEach((child) => {
if ('properties' in child && child.properties) {
child.properties.style = '';
Expand Down
Loading

0 comments on commit b682355

Please sign in to comment.