MCPcopy Index your code
hub / github.com/marijnh/Eloquent-JavaScript / highlight

Function highlight

src/render_html.mjs:61–69  ·  view source on GitHub ↗
(lang, text)

Source from the content-addressed store, hash-verified

59 .split(" ").map(n => "tok-" + n)
60
61function highlight(lang, text) {
62 let result = "", parser = parsers[lang], tree = parser ? parser.parse(text) : Tree.empty
63 highlightCode(text, tree, classHighlighter, (code, cls) => {
64 let esc = escape(code)
65 cls = cls.replace(/([\w-]+)\s*/g, (m, style) => styled.includes(style) ? m : "")
66 result += cls ? `<span class="${cls}">${esc}</span>` : esc
67 }, () => result += "\n")
68 return result
69}
70
71function maybeSplitInlineCode(html) {
72 if (html.length <= 16) return html

Callers 1

fenceFunction · 0.85

Calls 1

escapeFunction · 0.70

Tested by

no test coverage detected