/
githubmirror
/
marktext
Обзор
Документация
Войти
/
githubmirror
/
marktext
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/muya/src/inlineRenderer/renderer/highlight.ts
49 строк
1 KB
Ran Luo
feat(muya): migrate TS rewrite to packages/muya alongside legacy muyajs (#4314)
29 май 2026, 15:35
Не верифицирован
29 май 2026, 15:35
0d86641
Код
Авторство
О чём код?
import type Format from '../../block/base/format'; import type { H, Token } from '../types'; import type Renderer from './index'; import { union } from '../../utils'; // change text to highlight vnode export default function highlight( this: Renderer, h: H, block: Format, rStart: number, rEnd: number, token: Token, ) { const { text } = block; const { highlights } = token; let result = []; const unions = []; let pos = rStart; if (highlights) { for (const light of highlights) { const un = union({ start: rStart, end: rEnd }, light); if (un) unions.push(un); } } if (unions.length) { for (const u of unions) { const { start, end, active } = u; const className = this.getHighlightClassName(!!active); if (pos < start) result.push(text.substring(pos, start)); result.push(h(`span.${className}`, text.substring(start, end))); pos = end; } if (pos < rEnd) result.push(block.text.substring(pos, rEnd)); } else { result = [text.substring(rStart, rEnd)]; } return result; }