/
githubmirror
/
hexo
Обзор
Документация
Войти
/
githubmirror
/
hexo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lib/extend/syntax_highlight.ts
63 строки
1 KB
D-Sketon
feat: Support additional options for Backtick Code Block (#5625)
05 мар 2025, 11:58
Не верифицирован
05 мар 2025, 11:58
9e696d3
Код
Авторство
О чём код?
import type Hexo from '../hexo'; export interface HighlightOptions { lang: string | undefined, caption: string | undefined, lines_length?: number | undefined, // plugins/filter/before_post_render/backtick_code_block firstLineNumber?: string | number // plugins/tag/code.ts language_attr?: boolean | undefined; firstLine?: string | number; line_number?: boolean | undefined; line_threshold?: number | undefined; mark?: number[] | string; wrap?: boolean | undefined; } interface HighlightExecArgs { context?: Hexo; args?: [string, HighlightOptions]; } interface StoreFunction { (content: string, options: HighlightOptions): string; priority?: number; } interface Store { [key: string]: StoreFunction } class SyntaxHighlight { public store: Store; constructor() { this.store = {}; } register(name: string, fn: StoreFunction): void { if (typeof fn !== 'function') throw new TypeError('fn must be a function'); this.store[name] = fn; } query(name: string): StoreFunction { return name && this.store[name]; } exec(name: string, options: HighlightExecArgs): string { const fn = this.store[name]; if (!fn) throw new TypeError(`syntax highlighter ${name} is not registered`); const ctx = options.context; const args = options.args || []; return Reflect.apply(fn, ctx, args); } } export default SyntaxHighlight;