@yankeeinlondon/code-builder
Version:
Adds code highlighting support to vite-plugin-md
1,780 lines (1,750 loc) • 58.1 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
// node_modules/.pnpm/fp-ts@2.13.1/node_modules/fp-ts/lib/function.js
var require_function = __commonJS({
"node_modules/.pnpm/fp-ts@2.13.1/node_modules/fp-ts/lib/function.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEndomorphismMonoid = exports.not = exports.SK = exports.hole = exports.pipe = exports.untupled = exports.tupled = exports.absurd = exports.decrement = exports.increment = exports.tuple = exports.flow = exports.flip = exports.constVoid = exports.constUndefined = exports.constNull = exports.constFalse = exports.constTrue = exports.constant = exports.unsafeCoerce = exports.identity = exports.apply = exports.getRing = exports.getSemiring = exports.getMonoid = exports.getSemigroup = exports.getBooleanAlgebra = void 0;
var getBooleanAlgebra = function(B) {
return function() {
return {
meet: function(x, y) {
return function(a) {
return B.meet(x(a), y(a));
};
},
join: function(x, y) {
return function(a) {
return B.join(x(a), y(a));
};
},
zero: function() {
return B.zero;
},
one: function() {
return B.one;
},
implies: function(x, y) {
return function(a) {
return B.implies(x(a), y(a));
};
},
not: function(x) {
return function(a) {
return B.not(x(a));
};
}
};
};
};
exports.getBooleanAlgebra = getBooleanAlgebra;
var getSemigroup = function(S) {
return function() {
return {
concat: function(f, g) {
return function(a) {
return S.concat(f(a), g(a));
};
}
};
};
};
exports.getSemigroup = getSemigroup;
var getMonoid = function(M) {
var getSemigroupM = (0, exports.getSemigroup)(M);
return function() {
return {
concat: getSemigroupM().concat,
empty: function() {
return M.empty;
}
};
};
};
exports.getMonoid = getMonoid;
var getSemiring = function(S) {
return {
add: function(f, g) {
return function(x) {
return S.add(f(x), g(x));
};
},
zero: function() {
return S.zero;
},
mul: function(f, g) {
return function(x) {
return S.mul(f(x), g(x));
};
},
one: function() {
return S.one;
}
};
};
exports.getSemiring = getSemiring;
var getRing = function(R) {
var S = (0, exports.getSemiring)(R);
return {
add: S.add,
mul: S.mul,
one: S.one,
zero: S.zero,
sub: function(f, g) {
return function(x) {
return R.sub(f(x), g(x));
};
}
};
};
exports.getRing = getRing;
var apply = function(a) {
return function(f) {
return f(a);
};
};
exports.apply = apply;
function identity5(a) {
return a;
}
exports.identity = identity5;
exports.unsafeCoerce = identity5;
function constant(a) {
return function() {
return a;
};
}
exports.constant = constant;
exports.constTrue = constant(true);
exports.constFalse = constant(false);
exports.constNull = constant(null);
exports.constUndefined = constant(void 0);
exports.constVoid = exports.constUndefined;
function flip(f) {
return function() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (args.length > 1) {
return f(args[1], args[0]);
}
return function(a) {
return f(a)(args[0]);
};
};
}
exports.flip = flip;
function flow3(ab, bc, cd, de, ef, fg, gh, hi, ij) {
switch (arguments.length) {
case 1:
return ab;
case 2:
return function() {
return bc(ab.apply(this, arguments));
};
case 3:
return function() {
return cd(bc(ab.apply(this, arguments)));
};
case 4:
return function() {
return de(cd(bc(ab.apply(this, arguments))));
};
case 5:
return function() {
return ef(de(cd(bc(ab.apply(this, arguments)))));
};
case 6:
return function() {
return fg(ef(de(cd(bc(ab.apply(this, arguments))))));
};
case 7:
return function() {
return gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))));
};
case 8:
return function() {
return hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))));
};
case 9:
return function() {
return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))))));
};
}
return;
}
exports.flow = flow3;
function tuple() {
var t = [];
for (var _i = 0; _i < arguments.length; _i++) {
t[_i] = arguments[_i];
}
return t;
}
exports.tuple = tuple;
function increment(n) {
return n + 1;
}
exports.increment = increment;
function decrement(n) {
return n - 1;
}
exports.decrement = decrement;
function absurd(_) {
throw new Error("Called `absurd` function which should be uncallable");
}
exports.absurd = absurd;
function tupled(f) {
return function(a) {
return f.apply(void 0, a);
};
}
exports.tupled = tupled;
function untupled(f) {
return function() {
var a = [];
for (var _i = 0; _i < arguments.length; _i++) {
a[_i] = arguments[_i];
}
return f(a);
};
}
exports.untupled = untupled;
function pipe9(a, ab, bc, cd, de, ef, fg, gh, hi) {
switch (arguments.length) {
case 1:
return a;
case 2:
return ab(a);
case 3:
return bc(ab(a));
case 4:
return cd(bc(ab(a)));
case 5:
return de(cd(bc(ab(a))));
case 6:
return ef(de(cd(bc(ab(a)))));
case 7:
return fg(ef(de(cd(bc(ab(a))))));
case 8:
return gh(fg(ef(de(cd(bc(ab(a)))))));
case 9:
return hi(gh(fg(ef(de(cd(bc(ab(a))))))));
default: {
var ret = arguments[0];
for (var i = 1; i < arguments.length; i++) {
ret = arguments[i](ret);
}
return ret;
}
}
}
exports.pipe = pipe9;
exports.hole = absurd;
var SK = function(_, b) {
return b;
};
exports.SK = SK;
function not(predicate) {
return function(a) {
return !predicate(a);
};
}
exports.not = not;
var getEndomorphismMonoid = function() {
return {
concat: function(first, second) {
return flow3(first, second);
},
empty: identity5
};
};
exports.getEndomorphismMonoid = getEndomorphismMonoid;
}
});
// src/plugin.ts
import { createBuilder } from "@yankeeinlondon/builder-api";
// src/mdi/fence.ts
var import_function10 = __toESM(require_function(), 1);
// src/pipeline/addLanguage.ts
var import_function = __toESM(require_function(), 1);
import { append, createTextNode, select } from "@yankeeinlondon/happy-wrapper";
var addLanguage = (o) => (fence2) => {
if (o.showLanguage) {
fence2.codeBlockWrapper = select(fence2.codeBlockWrapper).update(".lang-display")(
(0, import_function.flow)(append(createTextNode(fence2.requestedLang)))
).toContainer();
}
return fence2;
};
// src/pipeline/addClipboard.ts
var import_function2 = __toESM(require_function(), 1);
import {
addClass,
addVueEvent,
append as append2,
select as select2
} from "@yankeeinlondon/happy-wrapper";
var CLIPBOARD = '<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" class="clipboard" viewBox="0 0 256 256"><path fill="currentColor" d="M166 152a6 6 0 0 1-6 6H96a6 6 0 0 1 0-12h64a6 6 0 0 1 6 6Zm-6-38H96a6 6 0 0 0 0 12h64a6 6 0 0 0 0-12Zm54-66v168a14 14 0 0 1-14 14H56a14 14 0 0 1-14-14V48a14 14 0 0 1 14-14h37.2a45.8 45.8 0 0 1 69.6 0H200a14 14 0 0 1 14 14ZM94 64v2h68v-2a34 34 0 0 0-68 0Zm108-16a2 2 0 0 0-2-2h-29.7a44.9 44.9 0 0 1 3.7 18v8a6 6 0 0 1-6 6H88a6 6 0 0 1-6-6v-8a44.9 44.9 0 0 1 3.7-18H56a2 2 0 0 0-2 2v168a2 2 0 0 0 2 2h144a2 2 0 0 0 2-2Z"/></svg>';
var addClipboard = (p, o) => (fence2) => {
const test = (prop) => typeof prop === "boolean" ? prop : prop ? prop(fence2, p.fileName, p.frontmatter) : false;
if (o?.clipboard || test(fence2.props?.clipboard)) {
fence2.codeBlockWrapper = select2(fence2.codeBlockWrapper).update(".lang-display")(
(el) => (0, import_function2.pipe)(
el,
append2(CLIPBOARD),
addClass("use-clipboard"),
addVueEvent("onClick", "copyToClipboard('testing')")
)
).toContainer();
}
if (test(o.provideClipboardFunctionality) || o?.clipboard || test(fence2.props?.clipboard)) {
const script = `const clipboardAvailable = () => !!navigator?.clipboard?.writeText
const copyToClipboard = (text) => {
navigator?.clipboard?.writeText(text)
}
`;
p.addCodeBlock("clipboard", script);
}
return fence2;
};
// src/pipeline/convertBlocksToDomNodes.ts
import {
createFragment,
safeString,
select as select3
} from "@yankeeinlondon/happy-wrapper";
function mergeClasses(_payload, optionConfig, fence2, prop) {
const baseClasses = optionConfig ? new Set(
typeof optionConfig === "function" ? optionConfig(fence2, "", {}) : optionConfig
) : /* @__PURE__ */ new Set();
const userDefined = fence2.props[prop] ? new Set(String(fence2.props[prop]).split(/s+/g)) : /* @__PURE__ */ new Set();
return [.../* @__PURE__ */ new Set([...baseClasses, ...userDefined])].join(" ");
}
var convertBlocksToDomNodes = (p, o) => (fence2) => {
const code = createFragment(fence2.code);
const codeLinesCount = select3(code).findAll(".code-line").length;
const aboveTheFoldCode = fence2.aboveTheFoldCode ? createFragment(fence2.aboveTheFoldCode) : void 0;
const pre = createFragment(fence2.pre);
const codeBlockWrapper = createFragment(fence2.codeBlockWrapper);
const lineNumbersWrapper = createFragment(fence2.lineNumbersWrapper);
const heading = fence2.heading ? createFragment(
`<div ${fence2.props.heading ? `class="${mergeClasses(p, o.headingClasses, fence2, "heading")}"` : ""}>${safeString(fence2.heading)}</div>`
) : void 0;
const footer = fence2.footer ? createFragment(
`<div ${fence2.props.footer ? `class="${mergeClasses(p, o.footerClasses, fence2, "footer")}"` : ""}">${safeString(fence2.footer)}</div>`
) : void 0;
return {
...fence2,
code,
codeLinesCount,
aboveTheFoldCode,
pre,
codeBlockWrapper,
lineNumbersWrapper,
heading,
footer
};
};
// src/pipeline/defaultBlocks.ts
var import_function3 = __toESM(require_function(), 1);
import { addClass as addClass2, append as append3 } from "@yankeeinlondon/happy-wrapper";
var defaultBlocks = (payload, o) => (fence2) => {
const resolver = (identity5) => (prop) => typeof prop === "function" ? prop(
fence2,
payload.fileName,
payload.frontmatter
) : prop === void 0 ? identity5 : prop;
const metaClasses = [];
if (fence2.props.heading) {
metaClasses.push("with-heading");
} else {
metaClasses.push("no-heading");
}
if (resolver(false)(o?.clipboard)) {
metaClasses.push("with-clipboard");
}
if (resolver(false)(o?.showLanguage)) {
metaClasses.push("show-lang");
}
const heading = (0, import_function3.pipe)(
'<div class="heading-row">',
addClass2(metaClasses),
fence2.props.heading ? append3(
`<div class="${resolver([])(o?.headingClasses).join(" ")}">${fence2.props.heading}</div>`
) : import_function3.identity,
o?.clipboard ? append3(
'<i-clipboard class="icon clipboard" @click="_copyClipboard" />'
) : import_function3.identity,
o?.showLanguage ? append3('<span class="lang-display"></span>') : import_function3.identity
);
const footer = fence2.props.footer ? `<div class="footer">${fence2.props.footer}</div>` : void 0;
const codeBlockWrapper = `<div class="code-wrapper">${heading || ""}<div class="code-block"></div>${footer || ""}</div>`;
const pre = "<pre>\n</pre>\n";
const lineNumbersWrapper = '<div class="line-numbers-wrapper"></div>\n';
return {
...fence2,
pre,
codeBlockWrapper,
lineNumbersWrapper
};
};
// src/pipeline/extractMarkdownItTokens.ts
import { readFileSync } from "fs";
import { dirname, join } from "pathe";
import { toHtml } from "@yankeeinlondon/happy-wrapper";
// src/pipeline/markdownItTokens/parseCSVSyntax.ts
function extractTypedValuesFromCSV(value) {
return value.startsWith('"') ? value.endsWith('"') ? value.slice(1, -1) : value.slice(1) : value.startsWith("{") ? JSON.stringify(value) : value.startsWith("[") ? value.replace(/[[\]]/g, "").split(";;").map((v2) => extractTypedValuesFromCSV(v2)) : value === "true" ? true : value === "false" ? false : Number.isNaN(value) ? value : Number(value);
}
function protectArrays(csv) {
if (csv.includes("[")) {
const parts = csv.split("[").map((p) => {
if (p.includes("]")) {
const [inside, after] = p.split("]");
return `${inside.replace(/,/g, ";;")}]${after}`;
} else {
return p;
}
});
return parts.join("[");
}
return csv;
}
var parseCSVSyntax = (csv, _p, fence2) => {
csv = protectArrays(csv);
fence2.props = csv.split(",").reduce((acc, i) => {
const [key, ...rest] = i.trim().split(/[:=]/);
return {
...acc,
[key.trim()]: extractTypedValuesFromCSV(rest.join(",").trim())
};
}, {});
return fence2;
};
// src/pipeline/markdownItTokens/shared.ts
function hasHighlightProperty(props) {
return typeof props === "object" && "highlight" in props;
}
function isRangeRepresentation(range) {
const re = /(\d+)\s*-\s*(\d+)/;
return typeof range === "string" && re.test(range);
}
function isSymbolRepresentation(sym) {
return typeof sym === "object" && "symbol" in sym;
}
function isObjectRangeRepresentation(range) {
return typeof range === "object" && "from" in range && "to" in range;
}
function hasProps(props) {
return typeof props === "object";
}
// src/pipeline/markdownItTokens/parseObjectSyntax.ts
var parseObjectSyntax = (objCandidate, p, fence2) => {
let { highlightTokens, externalFile, showFilename } = fence2;
try {
const props = objCandidate ? JSON.parse(objCandidate) : fence2.props;
if (hasHighlightProperty(props)) {
const highlight = !Array.isArray(props.highlight) ? [props.highlight] : props.highlight;
for (const h of highlight) {
switch (typeof h) {
case "string":
if (isRangeRepresentation(h)) {
const [from, to] = h.split(/\s*-\s*/).map(Number);
highlightTokens.push({ kind: "range", from, to });
} else {
console.warn(
`the "${p?.fileName}" file has a highlight token "${h}" which can't be parsed. String values are expected to be a range like: "3-6". This value will be ignored.`
);
}
break;
case "number":
highlightTokens.push({ kind: "line", line: h });
break;
case "object":
if (isSymbolRepresentation(h)) {
highlightTokens.push({ kind: "symbol", symbol: h.symbol });
} else if (isObjectRangeRepresentation(h)) {
highlightTokens.push({ kind: "range", from: h.from, to: h.to });
} else {
console.warn(
`the "${p?.fileName}" file has a highlight token "${JSON.stringify(
h
)}" which is not parsable. This value will be ignored.`
);
}
break;
default:
console.warn(
`the "${p?.fileName}" file has a highlight token which is of type "${typeof h}"; this is not parsabe and will be ignored.`
);
}
}
}
if (hasProps(props)) {
if (props.filename) {
externalFile = props.filename;
}
if (props.showFilename) {
showFilename = props.showFilename;
}
}
return { ...fence2, props, highlightTokens, showFilename, externalFile };
} catch {
const vpressExistance = /{\s*((\d+)|(\d+-\d+)).*}/s;
if (objCandidate && vpressExistance.test(objCandidate)) {
const tokens = objCandidate.replace(/\s*{/, "").replace(/}\s*/, "").split(",").map((i) => i.trim());
for (const t of tokens) {
if (isRangeRepresentation(t)) {
const [from, to] = t.split(/\s*-\s*/).map(Number);
highlightTokens.push({ kind: "range", from, to });
} else if (!Number.isNaN(Number(t))) {
highlightTokens.push({ kind: "line", line: Number(t) });
} else {
console.warn(
`the "${p?.fileName}" file is using Vuepress/Vitepress syntax to highlight lines but the token "${t}" is not parsable and will be ignored`
);
}
}
return { ...fence2, highlightTokens, showFilename, externalFile };
} else {
throw new Error(
`the "${p?.fileName}" file found object-like metadata in a code block but it was neither a JSON object nor a Vue/Vitepress highlighting expression: ${objCandidate}`
);
}
}
};
// src/pipeline/extractMarkdownItTokens.ts
function extractVPressFileSyntax(meta) {
const [front, back] = meta.split("<<<");
return [front.trim(), back ? back.trim() : null];
}
function loadFile(codeFile, pipeline) {
const { fileName } = pipeline;
codeFile = codeFile.replace(/^[@~]\//, "/");
const pathToCode = codeFile.startsWith("/") ? join(process.cwd(), codeFile) : join(dirname(fileName), codeFile);
try {
return readFileSync(pathToCode, "utf8");
} catch {
throw new Error(
`Problem loading external code file: '${pathToCode}' which was composed of [ '${codeFile.startsWith("/") ? process.cwd() : dirname(fileName)}', '${codeFile}' ]`
);
}
}
function extractMarkdownItTokens(p, t) {
const [info, vuepressFile] = extractVPressFileSyntax(t.info);
const matches = info.trim().match(/(([!#*]){0,2})(\w+)\s*({.*}){0,1}(.*)$/);
let fence2 = {
pre: "",
codeBlockWrapper: "",
lineNumbersWrapper: "",
code: t.content,
level: t.level,
tag: t.tag,
highlightTokens: [],
externalFile: vuepressFile || null,
showFilename: false,
lang: info,
props: {},
modifiers: [],
markup: t.markup
};
if (matches) {
const [, modifiers, , lang, obj, csv] = matches;
if (obj) {
fence2 = parseObjectSyntax(obj, p, fence2);
} else if (csv) {
fence2 = parseObjectSyntax(void 0, p, parseCSVSyntax(csv, p, fence2));
}
if (modifiers) {
fence2.modifiers = [...modifiers];
}
if (lang) {
fence2.lang = lang;
}
}
if (fence2.externalFile) {
fence2 = {
...fence2,
code: loadFile(fence2.externalFile, p),
aboveTheFoldCode: toHtml(`
${fence2.code}
`)
};
}
return {
...fence2,
trace: `MarkdownIt tokens parsed: [
lang: ${fence2.lang},
externalFile: ${fence2.externalFile},
highlight: ${JSON.stringify(
fence2.highlightTokens
)}
]
Props:${JSON.stringify(fence2.props, null, 2)}`
};
}
// src/pipeline/expandCodeBlockVariables.ts
var expandCodeBlockVariables = (p) => (fence2) => {
if (p.options.escapeCodeTagInterpolation && fence2.modifiers.includes("!" /* ! */) || !p.options.escapeCodeTagInterpolation && !fence2.modifiers.includes("!" /* ! */)) {
const matches = fence2.code.matchAll(/{{\s*(\w+)\s*}}/gs);
for (const m of matches) {
const [fullBlock, variable] = m;
if (variable in p.frontmatter || variable === "frontmatter") {
fence2.code = variable === "frontmatter" ? fence2.code.replace(
fullBlock,
JSON.stringify(p.frontmatter || {}, null, 2)
) : fence2.code.replace(
fullBlock,
JSON.stringify(p.frontmatter[variable] || "")
);
} else {
fence2.code = fence2.code.replace(
fullBlock,
`Error: "${variable}" not found in frontmatter. Valid props: ${Object.keys(
p.frontmatter
)}`
);
}
}
}
return {
...fence2
};
};
// src/pipeline/inlineStyles.ts
import { createInlineStyle } from "@yankeeinlondon/happy-wrapper";
// src/styles/color/mergeColorThemes.ts
function left(item) {
return Array.isArray(item) ? item[0] : item;
}
function right(item) {
return Array.isArray(item) ? item[1] : item;
}
var mergeColorThemes = (light, dark) => {
const props = [.../* @__PURE__ */ new Set([...Object.keys(light), ...Object.keys(dark)])];
return props.reduce(
(acc, prop) => ({
...acc,
[prop]: [
left(light[prop]),
right(dark[prop])
]
}),
{}
);
};
// src/styles/color/color-themes.ts
var base = {
foreground: ["#393a34", "#d4cfbf"],
background: ["#fbfbfb", "#1e1e1e"],
lineNumber: ["#636363", "#888888"],
lineNumberGutter: ["#BEBEBE", "#eeeeee"],
highlight: ["#C0C0C0", "#444444"],
textSelection: ["#656565", "#787878"],
comment: ["#a0ada0", "#758575"],
string: ["#b56959", "#d48372"],
literal: ["#2f8a89", "#429988"],
keyword: ["#296aa3", "#3385CC"],
operator: ["#296aa3", "#3385CC"],
boolean: ["#00B370", "#1c6b48"],
number: ["#0086D3", "#6394bf"],
variable: ["#B09B41", "#c2b36e"],
function: ["#6c7834", "#a1b567"],
deleted: ["#963E47", "#a14f55"],
class: ["#2993a3", "#54b1bf"],
builtin: ["#D88D41", "#e0a569"],
property: ["#b58451", "#dd8e6e"],
namespace: ["#b05a78", "#db889a"],
punctuation: ["#8e8f8b", "#858585"],
decorator: ["#AA7070", "#bd8f8f"],
regex: ["#894B32", "#ab5e3f"],
jsonProperty: ["#587586", "#6b8b9e"]
};
var dracula = {
foreground: "#f8f8f2",
background: "#282a36",
lineNumber: "#888888",
lineNumberGutter: "#eeeeee",
highlight: "#444444",
textSelection: "#787878",
comment: "#6272a4",
prolog: "#6272a4",
doctype: "#6272a4",
cdata: "#6272a4",
punctuation: "#f8f8f2",
namespace: "#f8f8f2/70",
property: "#ff79c6",
boolean: "#bd93f9",
number: "#bd93f9",
builtin: "#50fa7b",
operator: "#f8f8f2",
entity: "#f8f8f2",
url: "#f8f8f2",
string: "#f8f8f2",
variable: "#f8f8f2",
atrule: "#f1fa8c",
function: "#f1fa8c",
class: "#f1fa8c",
attrValue: "#f1fa8c",
keyword: "#8be9fd",
regex: "#ffb86c",
important: "#ffb86c"
};
var darcula = {
foreground: "#a9b7c6",
background: "#2b2b2b",
lineNumber: "#636363",
lineNumberGutter: "#BEBEBE",
highlight: "#363636",
textSelection: "#656565",
comment: "#808080",
keyword: "#cc7832",
punctuation: "#a9b7c6",
symbol: "#6897bb",
property: "#9876aa",
attrValue: "#a5c261",
attrValueForPunctuation: "#a5c261",
attrValueForPunctuationFirstChild: "#a9b7c6",
url: "#287bde",
function: "#ffc66d",
regex: "#364135",
inserted: "#294436",
deleted: "#484a4a",
class: "#ffc66d",
builtin: "#e8bf6a",
string: "#6a8759",
namespace: "#b05a78",
decorator: "#bd8f8f"
};
var duotone = {
foreground: ["#728fcb", "#9a86fd"],
background: ["#faf8f5", "#6a51e6"],
lineNumber: ["#9DB1DB", "#B7A9FE"],
lineNumberGutter: ["#ece8de", "#B7A9FE"],
highlight: ["#E8DFD1", "#391DC7"],
textSelection: ["", ""],
atrule: ["#728fcb", "#ffcc99"],
attrName: ["#896724", "#c4b9fe"],
attrValue: ["#728fcb", "#ffcc99"],
attribute: ["#b29762", "#ffcc99"],
boolean: ["#728fcb", "#ffcc99"],
builtin: ["#b29762", "#9a86fd"],
class: ["#b29762", "#9a86fd"],
className: ["#b29762", "#9a86fd"],
char: ["#728fcb", "#ffcc99"],
cdata: ["#b6ad9a", "#A6A3B7"],
comment: ["#b6ad9a", "#A6A3B7"],
constant: ["#063289", "#e09142"],
deleted: ["#FF9A6C", "#FFB999"],
doctype: ["#b6ad9a", "#A6A3B7"],
entity: ["#728fcb", "#ffcc99"],
function: ["#b29762", "#9a86fd"],
hexcode: ["#728fcb", "#ffcc99"],
id: ["#2d2006", "#eeebff"],
important: ["#896724", "#FFB999"],
inserted: ["", "#D9FF99"],
keyword: ["#728fcb", "#ffcc99"],
number: ["#063289", "#e09142"],
operator: ["#063289", "#e09142"],
prolog: ["#b6ad9a", "#A6A3B7"],
property: ["#b29762", "#9a86fd"],
placeholder: ["#93abdc", "#ffcc99"],
punctuation: ["#b6ad9a", "#A6A3B7"],
regex: ["#728fcb", "#ffcc99"],
selector: ["#2d2006", "#eeebff"],
string: ["#728fcb", "#ffcc99"],
symbol: ["#728fcb", "#ffcc99"],
tag: ["#063289", "#e09142"],
unit: ["#728fcb", "#ffcc99"],
url: ["#728fcb", "#ffcc99"],
variable: ["#93abdc", "#ffcc99"]
};
var material = {
foreground: ["#B84903", "#fd9170"],
background: ["#E4D1CF", "#363636"],
lineNumber: ["#636363", "#888888"],
lineNumberGutter: ["#BEBEBE", "#eeeeee"],
highlight: ["#ACACAC", "#444444"],
textSelection: ["#656565", "#787878"],
atrule: ["#7c4dff", "#c792ea"],
attrName: ["#39adb5", "#ffcb6b"],
attrValue: ["#f6a434", "#a5e844"],
attribute: ["#f6a434", "#a5e844"],
boolean: ["#7c4dff", "#c792ea"],
builtin: ["#39adb5", "#ffcb6b"],
class: ["#39adb5", "#ffcb6b"],
className: ["#6182b8", "#f2ff00"],
char: ["#39adb5", "#80cbc4"],
cdata: ["#39adb5", "#80cbc4"],
comment: ["#7597A7", "#616161"],
constant: ["#7c4dff", "#c792ea"],
deleted: ["#e53935", "#ff6666"],
doctype: ["#aabfc9", "#616161"],
entity: ["#e53935", "#ff6666"],
function: ["#7c4dff", "#c792ea"],
hexcode: ["#f76d47", "#f2ff00"],
id: ["#7c4dff", "#c792ea"],
important: ["#7c4dff", "#c792ea"],
inserted: ["#39adb5", "#80cbc4"],
keyword: ["#7c4dff", "#c792ea"],
number: ["#f76d47", "#fd9170"],
operator: ["#39adb5", "#89ddff"],
prolog: ["#aabfc9", "#616161"],
property: ["#39adb5", "#80cbc4"],
pseudoClass: ["#f6a434", "#a5e844"],
pseudoElement: ["#f6a434", "#a5e844"],
punctuation: ["#39adb5", "#89ddff"],
regex: ["#6182b8", "#f2ff00"],
selector: ["#e53935", "#ff6666"],
string: ["#f6a434", "#a5e844"],
symbol: ["#7c4dff", "#c792ea"],
tag: ["#e53935", "#ff6666"],
unit: ["#f76d47", "#fd9170"],
url: ["#e53935", "#ff6666"],
variable: ["#e53935", "#ff6666"]
};
var solarizedLight = {
foreground: ["#7C929B", "#657b83;"],
background: ["#E3EEF1", "#073642"],
lineNumber: ["#636363", "#888888"],
lineNumberGutter: ["#BEBEBE", "#eeeeee"],
highlight: ["#363636", "hsla(194, 48%, 26%, 0.75)"],
textSelection: ["#656565", "#787878"],
comment: ["#93a1a1", "#B3BDBD"],
punctuation: ["#586e75", "#586e75"],
property: ["#268bd2", "#4FA4DF"],
operator: ["#268bd2", "#4FA4DF"],
tag: ["#268bd2", "#4FA4DF"],
boolean: ["#268bd2", "#4FA4DF"],
number: ["#268bd2", "#4FA4DF"],
constant: ["#268bd2", "#4FA4DF"],
symbol: ["#268bd2", "#4FA4DF"],
deleted: ["#268bd2", "#4FA4DF"],
selector: ["#2aa198", "#33C3B8"],
attrName: ["#2aa198", "#33C3B8"],
string: ["#2aa198", "#33C3B8"],
char: ["#2aa198", "#33C3B8"],
builtin: ["#2aa198", "#33C3B8"],
url: ["#2aa198", "#33C3B8"],
inserted: ["#2aa198", "#33C3B8"],
entity: ["#657b83", "#7D939B"],
atrule: ["#859900", "#9BB300"],
attrValue: ["#859900", "#9BB300"],
keyword: ["#859900", "#9BB300"],
function: ["#b58900", "#D9A400"],
className: ["#b58900", "#D9A400"],
regex: ["#cb4b16", "#E96934"],
important: ["#cb4b16", "#E96934"],
variable: ["#cb4b16", "#E96934"]
};
var twilight = {
foreground: ["#263238", "#fd9170"],
background: ["#cceae7", "#363636"],
lineNumber: ["#636363", "#888888"],
lineNumberGutter: ["#BEBEBE", "#eeeeee"],
highlight: ["#474747", "#444444"],
textSelection: ["#656565", "#787878"],
comment: ["hsl(0, 0%, 50%)", "hsl(0, 0%, 65%)"],
prolog: ["hsl(0, 0%, 50%)", "hsl(0, 0%, 65%)"],
doctype: ["hsl(0, 0%, 50%)", "hsl(0, 0%, 65%)"],
cdata: ["hsl(0, 0%, 50%)", "hsl(0, 0%, 65%)"],
punctuation: ["hsl(8, 8%, 55%)", "hsl(8, 8%, 68%)"],
tag: ["hsl(14, 58%, 55%)", "hsl(14, 58%, 75%)"],
boolean: ["hsl(14, 58%, 55%)", "hsl(14, 58%, 75%)"],
number: ["hsl(14, 58%, 55%)", "hsl(14, 58%, 75%)"],
deleted: ["hsl(6, 58%, 55%)", "hsl(6, 58%, 75%)"],
keyword: ["hsl(53, 89%, 79%)", "hsl(53, 89%, 85%)"],
property: ["hsl(53, 89%, 79%)", "hsl(53, 89%, 85%)"],
selector: ["hsl(53, 89%, 79%)", "hsl(53, 89%, 85%)"],
constant: ["hsl(53, 89%, 79%)", "hsl(53, 89%, 85%)"],
symbol: ["hsl(53, 89%, 79%)", "hsl(53, 89%, 85%)"],
builtin: ["hsl(53, 89%, 79%)", "hsl(53, 89%, 85%)"],
attrName: ["hsl(76, 21%, 52%)", "hsl(76, 21%, 64%)"],
attrValue: ["hsl(76, 21%, 52%)", "hsl(76, 21%, 64%)"],
string: ["hsl(76, 21%, 52%)", "hsl(76, 21%, 64%)"],
char: ["hsl(76, 21%, 52%)", "hsl(76, 21%, 64%)"],
operator: ["hsl(76, 21%, 52%)", "hsl(76, 21%, 64%)"],
entity: ["hsl(76, 21%, 52%)", "hsl(76, 21%, 64%)"],
url: ["hsl(76, 21%, 52%)", "hsl(76, 21%, 64%)"],
variable: ["hsl(76, 21%, 52%)", "hsl(76, 21%, 64%)"],
inserted: ["hsl(76, 21%, 52%)", "hsl(76, 21%, 64%)"],
atrule: ["hsl(218, 50%, 55%)", "hsl(218, 50%, 68%)"],
regex: ["hsl(42, 75%, 65%)", "hsl(42, 75%, 75%)"],
important: ["hsl(42, 75%, 65%)", "hsl(42, 75%, 75%)"],
markupTag: ["hsl(33, 33%, 52%)", "hsl(33, 33%, 72%)"],
markupAttrName: ["hsl(33, 33%, 52%)", "hsl(33, 33%, 72%)"],
markupPunctuation: ["hsl(33, 33%, 52%)", "hsl(33, 33%, 72%)"]
};
var tomorrow = {
foreground: ["#ccc", "#2d2d2d"],
background: ["#2d2d2d", "#ccc"],
lineNumber: ["#636363", "#888888"],
lineNumberGutter: ["#BEBEBE", "#eeeeee"],
highlight: ["#363636", "#5C5C5C"],
textSelection: ["#656565", "#787878"],
comment: ["#999", "#AEAEAE"],
blockComment: ["#999", "#AEAEAE"],
doctype: ["#999", "#AEAEAE"],
prolog: ["#999", "#AEAEAE"],
cdata: ["#999", "#AEAEAE"],
punctuation: ["#ccc", "#727272"],
tag: ["#e2777a", "#E89597"],
attrName: ["#e2777a", "#E89597"],
namespace: ["#e2777a", "#E89597"],
deleted: ["#e2777a", "#E89597"],
functionName: ["#6196cc", "#7AA7D4"],
boolean: ["#f08d49", "#F29B60"],
number: ["#f08d49", "#F29B60"],
function: ["#f08d49", "#F29B60"],
property: ["#f8c555", "#F9D179"],
className: ["#f8c555", "#F9D179"],
constant: ["#f8c555", "#F9D179"],
symbol: ["#f8c555", "#F9D179"],
selector: ["#cc99cd", "#BC7BBE"],
important: ["#cc99cd", "#BC7BBE"],
atrule: ["#cc99cd", "#BC7BBE"],
keyword: ["#cc99cd", "#BC7BBE"],
builtin: ["#cc99cd", "#BC7BBE"],
string: ["#7ec699", "#47A169"],
char: ["#7ec699", "#47A169"],
attrValue: ["#7ec699", "#47A169"],
regex: ["#7ec699", "#47A169"],
variable: ["#7ec699", "#47A169"],
operator: ["#67cdcc", "#2E8C8B"],
entity: ["#67cdcc", "#2E8C8B"],
url: ["#67cdcc", "#2E8C8B"],
inserted: ["#157A44", "#199251"]
};
var themes = {
base,
dracula: mergeColorThemes(darcula, dracula),
solarizedLight,
twilight,
tomorrow,
material,
duotone
};
// src/styles/color/setCodeBlockColors.ts
var setCodeBlockColors = (style, options, props) => {
const { theme, invertColorMode } = options;
const defn = typeof theme === "string" ? themes[theme] : theme;
const inversion = props.inversion ? props.invertColorMode === true : invertColorMode === true;
if (defn) {
for (const prop of Object.keys(defn)) {
const light = !inversion ? left(defn[prop]) : right(defn[prop]);
const dark = !inversion ? right(defn[prop]) : left(defn[prop]);
if (light) {
style.addCssVariable(`prism-${prop}`, light);
}
if (dark) {
style.addCssVariable(`prism-${prop}`, dark, "html.dark");
}
style.addClassDefinition(
`.token.${prop}`,
(c) => c.addProps({
color: `var(--prism-${prop})`
})
);
}
}
return style;
};
// src/pipeline/inlineStyles.ts
var inlineStyles = (p, o) => (fence2) => {
if (p.codeBlockLanguages.langsRequested.length > 0) {
const style = createInlineStyle().convertToVueStyleBlock("css", false).addCssVariable("code-col-width", "auto", ".code-wrapper").addCssVariable(
"code-border-color",
"rgba(238, 239, 240, 0.75)",
".code-wrapper"
).addCssVariable(
"code-border-color",
"rgba(238, 239, 240, 0.35)",
"html.dark .code-wrapper"
).addCssVariable("code-text-copy", "#166534").addCssVariable("code-text-copy", "#bbf7d0", "html.dark").addClassDefinition(
".code-wrapper",
(c) => c.addProps({
marginTop: "0.5rem",
marginBottom: "0.5rem",
overflow: "hidden",
borderRadius: "0.375rem",
backgroundColor: "var(--prism-background)"
}).addChild(".heading-row", {
position: "relative"
}).addChild(".heading-row no-heading", {
height: 0,
padding: 0,
margin: 0
}).addChild(".heading-row with-heading", {
padding: "0.5rem",
margin: "auto",
height: "auto"
}).addChild(".heading", {
color: "var(--prism-foreground)",
fontSize: "1.2rem",
fontWeight: 600,
padding: "0.25rem 1rem 0.25rem 1rem"
}).addChild(".heading-row .lang-display", {
position: "absolute",
color: "var(--prism-foreground)",
right: "0.5rem",
top: "0.325rem",
fontSize: "0.75rem",
fontWeight: 300,
opacity: "75%",
userSelect: "none",
cursor: "default",
display: "flex",
alignItems: "center",
justifyItems: "center"
}).addChild(".heading-row .lang-display.use-clipboard", {
cursor: "pointer"
}).addChild(".heading-row .lang-display.use-clipboard:hover", {
opacity: 1
}).addChild(".heading-row .lang-display.use-clipboard:active", {
color: "var(--code-text-copy)"
}).addChild(".clipboard", {
width: "1rem",
height: "1rem",
marginLeft: "0.2rem",
opacity: ".75"
}).addChild(".code-block", {
fontFamily: o.codeFont || "var(--code-font)"
}).addChild("table", {
width: "100%",
tableLayout: "auto",
padding: "0.375rem",
margin: "auto",
color: "var(--prism-foreground)",
cursor: "default"
}).addChild("table td", {
fontSize: "0.875rem"
}).addChild(".line-numbers-mode table td.line-number", {
width: "var(--code-col-width)",
border: "0px",
opacity: "0.75",
paddingRight: "0.75rem",
paddingLeft: "0.25rem",
textAlign: "right",
borderRight: "1px solid",
borderColor: "var(--lineNumberGutter)"
}).addChild(".no-line-numbers table td.line-number", {
width: 0,
opacity: 0,
border: 0,
padding: 0,
display: "none"
}).addChild("table td.code-line", {
width: "100vw",
whiteSpace: "pre",
border: "0px",
lineHeight: "1.4",
paddingTop: 0,
paddingBottom: 0
}).addChild(".no-line-numbers table td.code-line", {
paddingLeft: "0.5rem",
borderRadius: "0.325rem"
}).addChild("table tr", {
backgroundColor: "var(--prism-background)",
border: "0px",
lineHeight: "0.875"
}).addChild("table tr.highlight", {
backgroundColor: "var(--prism-highlight)",
borderRadius: "0.875rem"
}).addChild("table tr.odd.highlight", {
backgroundColor: "var(--prism-highlight)"
}).addChild("table tr.even.highlight", {
backgroundColor: "var(--prism-highlight)"
}).addChild("table tr.odd", {
backgroundColor: "var(--prism-background)"
}).addChild("table tr.even", {
backgroundColor: "var(--prism-background)"
}).addChild(".footer", {
paddingLeft: "1rem",
paddingRight: "1rem",
borderTop: "1px",
paddingTop: "0.5rem",
paddingBottom: "0.5rem",
fontSize: "0.75rem",
fontWeight: 300,
color: "var(--prism-foreground)"
})
);
p.addStyleBlock(
"codeStyle",
setCodeBlockColors(style, o, fence2.props).finish()
);
}
return fence2;
};
// src/pipeline/highlightLines.ts
var import_function4 = __toESM(require_function(), 1);
import { addClass as addClass3, select as select4 } from "@yankeeinlondon/happy-wrapper";
// src/utils/trace.ts
import { toHtml as toHtml2 } from "@yankeeinlondon/happy-wrapper";
// src/utils/highlightTokensToLines.ts
function highlightTokensToLines(fence2) {
const lines = [];
for (const t of fence2.highlightTokens) {
switch (t.kind) {
case "line": {
lines.push(t.line);
break;
}
case "range": {
{
let i = t.from;
while (i <= t.to) {
lines.push(i);
i++;
}
}
break;
}
case "symbol":
}
}
return lines;
}
// src/utils/prism.ts
var prismLanguages = [
"plain",
"plaintext",
"text",
"txt",
"extend",
"insertBefore",
"DFS",
"html",
"mathml",
"svg",
"xml",
"ssml",
"atom",
"rss",
"js",
"g4",
"ino",
"arm-asm",
"shell",
"yml",
"md",
"art",
"adoc",
"cs",
"dotnet",
"avs",
"avdl",
"gawk",
"shortcode",
"rbnf",
"oscript",
"cfc",
"coffee",
"conc",
"rb",
"jinja2",
"dns-zone",
"dockerfile",
"gv",
"eta",
"xls",
"xlsx",
"gamemakerlanguage",
"po",
"gni",
"ld",
"go-mod",
"hbs",
"mustache",
"hs",
"webmanifest",
"url",
"idr",
"gitignore",
"hgignore",
"npmignore",
"ts",
"n4jsd",
"kt",
"kts",
"kum",
"tex",
"context",
"ly",
"elisp",
"emacs",
"emacs-lisp",
"moon",
"nani",
"objc",
"qasm",
"objectpascal",
"px",
"pcode",
"plantuml",
"pq",
"mscript",
"pbfasm",
"purs",
"py",
"qs",
"rkt",
"razor",
"rpy",
"res",
"robot",
"shellsession",
"sh-session",
"smlnj",
"sol",
"sln",
"trig",
"rq",
"sclang",
"t4",
"troy",
"trickle",
"tsconfig",
"uscript",
"uc",
"vb",
"vba",
"webidl",
"mathematica",
"wl",
"nb",
"xeoracube",
"markup",
"css",
"clike",
"regex",
"javascript",
"abap",
"abnf",
"actionscript",
"ada",
"agda",
"al",
"antlr4",
"apacheconf",
"sql",
"apex",
"apl",
"applescript",
"aql",
"c",
"cpp",
"arduino",
"arff",
"armasm",
"bash",
"yaml",
"markdown",
"arturo",
"asciidoc",
"csharp",
"aspnet",
"asm6502",
"asmatmel",
"autohotkey",
"autoit",
"avisynth",
"avro-idl",
"awk",
"basic",
"batch",
"bbcode",
"bicep",
"birb",
"bison",
"bnf",
"brainfuck",
"brightscript",
"bro",
"bsl",
"cfscript",
"chaiscript",
"cil",
"clojure",
"cmake",
"cobol",
"coffeescript",
"concurnas",
"csp",
"cooklang",
"coq",
"ruby",
"crystal",
"csv",
"cue",
"cypher",
"d",
"dart",
"dataweave",
"dax",
"dhall",
"diff",
"markup-templating",
"django",
"dns-zone-file",
"docker",
"dot",
"ebnf",
"editorconfig",
"eiffel",
"ejs",
"elixir",
"elm",
"lua",
"etlua",
"erb",
"erlang",
"excel-formula",
"fsharp",
"factor",
"false",
"firestore-security-rules",
"flow",
"fortran",
"ftl",
"gml",
"gap",
"gcode",
"gdscript",
"gedcom",
"gettext",
"gherkin",
"git",
"glsl",
"gn",
"linker-script",
"go",
"go-module",
"graphql",
"groovy",
"less",
"scss",
"textile",
"haml",
"handlebars",
"haskell",
"haxe",
"hcl",
"hlsl",
"hoon",
"hpkp",
"hsts",
"json",
"uri",
"http",
"ichigojam",
"icon",
"icu-message-format",
"idris",
"ignore",
"inform7",
"ini",
"io",
"j",
"java",
"php",
"javadoclike",
"scala",
"javadoc",
"javastacktrace",
"jexl",
"jolie",
"jq",
"typescript",
"jsdoc",
"n4js",
"json5",
"jsonp",
"jsstacktrace",
"julia",
"keepalived",
"keyman",
"kotlin",
"kumir",
"kusto",
"latex",
"latte",
"scheme",
"lilypond",
"liquid",
"lisp",
"livescript",
"llvm",
"log",
"lolcode",
"magma",
"makefile",
"mata",
"matlab",
"maxscript",
"mel",
"mermaid",
"mizar",
"mongodb",
"monkey",
"moonscript",
"n1ql",
"nand2tetris-hdl",
"naniscript",
"nasm",
"neon",
"nevod",
"nginx",
"nim",
"nix",
"nsis",
"objectivec",
"ocaml",
"odin",
"opencl",
"openqasm",
"oz",
"parigp",
"parser",
"pascal",
"pascaligo",
"psl",
"pcaxis",
"peoplecode",
"perl",
"phpdoc",
"plant-uml",
"plsql",
"powerquery",
"powershell",
"processing",
"prolog",
"promql",
"properties",
"protobuf",
"stylus",
"twig",
"pug",
"puppet",
"pure",
"purebasic",
"purescript",
"python",
"qsharp",
"q",
"qml",
"qore",
"r",
"racket",
"cshtml",
"jsx",
"tsx",
"reason",
"rego",
"renpy",
"rescript",
"rest",
"rip",
"roboconf",
"robotframework",
"rust",
"sas",
"sass",
"shell-session",
"smali",
"smalltalk",
"smarty",
"sml",
"solidity",
"solution-file",
"soy",
"turtle",
"sparql",
"splunk-spl",
"sqf",
"squirrel",
"stan",
"stata",
"iecst",
"supercollider",
"swift",
"systemd",
"t4-templating",
"t4-cs",
"vbnet",
"t4-vb",
"tap",
"tcl",
"tt2",
"toml",
"tremor",
"typoscript",
"unrealscript",
"uorazor",
"v",
"vala",
"velocity",
"verilog",
"vhdl",
"vim",
"visual-basic",
"warpscript",
"wasm",
"web-idl",
"wiki",
"wolfram",
"wren",
"xeora",
"xojo",
"xquery",
"yang",
"zig"
];
// src/utils/escapeHtml.ts
import { keys } from "inferred-types";
var HTML_ESCAPE_TEST_RE = /["&<>]/;
var HTML_ESCAPE_REPLACE_RE = /["&<>]/g;
var HTML_REPLACEMENTS = {
"&": "&",
"<": "<",
">": ">",
'"': """
};
function replaceUnsafeChar(ch) {
if (ch in keys(HTML_REPLACEMENTS)) {
return HTML_REPLACEMENTS[ch];
} else {
console.error(
`character ["${ch}"] sent to replaceUnsafeChar(ch) was not recognized!`
);
return "";
}
}
function escapeHtml(str) {
if (HTML_ESCAPE_TEST_RE.test(str)) {
return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar);
}
return str;
}
// src/pipeline/highlightLines.ts
var highlightLines = (_o) => (fence2) => {
const hl = highlightTokensToLines(fence2);
const highlight = (el, idx) => (0, import_function4.pipe)(el, hl.includes(idx + 1) ? addClass3("highlight") : import_function4.identity);
return {
...fence2,
trace: `Highlighted line(s) were: ${hl.join(", ")}`,
code: select4(fence2.code).updateAll(".code-line")(highlight).toContainer(),
lineNumbersWrapper: select4(fence2.lineNumbersWrapper).updateAll(".line-number")(highlight).toContainer()
};
};
// src/pipeline/renderHtml.ts
import { toHtml as toHtml3 } from "@yankeeinlondon/happy-wrapper";
// src/pipeline/rendering/flex-lines.ts
var import_function5 = __toESM(require_function(), 1);
import {
before,
changeTagName,
createFragment as createFragment2,
select as select5,
wrap
} from "@yankeeinlondon/happy-wrapper";
var flexLines = (p, o, fence2) => {
const hasLineNumbers = o.lineNumbers || fence2.modifiers.includes("#" /* # */);
const lineNumbersWrapper = hasLineNumbers ? fence2.lineNumbersWrapper : createFragment2();
return (0, import_function5.pipe)(
fence2.codeBlockWrapper,
select5,
(s) => s.update(
".code-block",
`Couldn't find the ".code-wrapper" in the file ${p.fileName}`
)((el) => fence2.heading ? before(fence2.heading)(el) : el),
(s) => s.update(
".code-block",
`Couldn't find the ".code-block" in the file ${p.fileName}`
)(wrap(fence2.pre, lineNumbersWrapper)),
(s) => s.updateAll(".code-line")(changeTagName("code")),
(s) => s.toContainer()
);
};
// src/pipeline/rendering/tabular.ts
var import_function6 = __toESM(require_function(), 1);
import {
addClass as addClass4,
before as before2,
changeTagName as changeTagName2,
clone,
createElement,
filterClasses,
select as select6
} from "@yankeeinlondon/happy-wrapper";
var tabularFormatting = (p, fence2) => {
const toTable = changeTagName2("table");
const toTD = changeTagName2("td");
let misplaced = [];
const removed = (classes) => {
misplaced = classes;
};
const lineNumberElement = (el, idx, _) => before2(`<td class="line-number">${idx + 1}</td>`)(el);
fence2.pre = (0, import_function6.pipe)(
fence2.pre,
select6,
(s) => s.update()(toTable),
(s) => s.updateAll(".code-line")(toTD),
(s) => s.updateAll(".code-line")(
(el) => (0, import_function6.pipe)(
el,
filterClasses(
removed,
/line-{1,2}\d/,
"odd",
"even",
"first-row",
"last-row",
"highlight"
),
(el2) => {
const tr = (0, import_function6.pipe)(
'<tr class="code-row">',
createElement,
addClass4(misplaced)
);
tr.append(clone(el2));
el2.replaceWith(tr);
return el2;
}
)
),
(s) => s.updateAll(".code-line")(lineNumberElement),
(s) => s.toContainer()
);
fence2.codeBlockWrapper = (0, import_function6.pipe)(
fence2.codeBlockWrapper,
select6,
(s) => s.update(
".code-block",
`Couldn't find the ".code-block" node in the file ${p.fileName}`
)((el) => {
el.append(fence2.pre);
return el;
}),
(s) => s.toContainer()
);
return fence2.codeBlockWrapper;
};
// src/pipeline/renderHtml.ts
var renderHtml = (p, o) => (fence2) => {
switch (o.layoutStructure) {
case "flex-lines": {
fence2.codeBlockWrapper = flexLines(p, o, fence2);
break;
}
case "tabular": {
fence2.codeBlockWrapper = tabularFormatting(p, fence2);
break;
}
}
if (fence2.footer) {
fence2.codeBlockWrapper.lastElementChild.append(fence2.footer);
}
const html = toHtml3(fence2.codeBlockWrapper);
return {
...fence2,
trace: `Finalized HTML is:
${toHtml3(fence2.codeBlockWrapper)}`,
html
};
};
// src/pipeline/updateLineNumbers.ts
var import_function7 = __toESM(require_function(), 1);
import {
addClass as addClass5,
createElement as createElement2,
into,
select as select7,
wrap as wrap2
} from "@yankeeinlondon/happy-wrapper";
var evenOdd = (lineNumber2) => (el) => lineNumber2 % 2 === 0 ? addClass5("even")(el) : addClass5("odd")(el);
var firstLast = (lineNumber2, lineCount) => (el) => lineNumber2 === 1 ? addClass5("first-row")(el) : lineNumber2 === lineCount ? addClass5("last-row")(el) : el;
var lineNumber = (i, aboveTheFold) => i + 1 - aboveTheFold;
var specificLine = (i, aboveTheFold) => {
return lineNumber(i, aboveTheFold) > 0 ? `line-${lineNumber(i, aboveTheFold)}` : `negative-line-${Math.abs(lineNumber(i, aboveTheFold))}`;
};
var addLinesToContainer = (fence2, _o, aboveTheFold = 0) => {
return (wrapper) => {
const children = [];
for (let lineNumber2 = 1 - aboveTheFold; fence2.codeLinesCount >= lineNumber2; lineNumber2++) {
const tagName = "span";
const child = createElement2(
`<${tagName} class="line-number">${lineNumber2}</${tagName}>`
);
children.push(child);
}
return wrap2(...children)(wrapper);
};
};
var addLineClasses = (aboveTheFold) => (el, idx = 0, total = 0) => (0, import_function7.pipe)(
el,
evenOdd(lineNumber(idx, aboveTheFold)),
firstLast(lineNumber(idx, aboveTheFold), total),
addClass5(specificLine(idx, aboveTheFold))
);
var updateLineNumbers = (o) => (fence2) => {
const linesAboveTheFold = 0;
const aboveTheFoldCode = fence2.aboveTheFoldCode ? (0, import_function7.pipe)(
fence2.aboveTheFoldCode,
select7,
(s) => s.updateAll(".code-line")((el) => {
const isEmptyLine = el.textContent.length === 0;
const isEmptyComment = el.textContent.trim() === "//";
return isEmptyComment || isEmptyLine ? false : el;
}),
(s) => s.toContainer()
) : void 0;
const code = (0, import_function7.pipe)(
aboveTheFoldCode ? into()(aboveTheFoldCode, fence2.code) : fence2.code,
select7,
(s) => s.updateAll(".code-line")(addLineClasses(linesAboveTheFold)),
(s) => s.toContainer()
);
const lineNumbersWrapper = (0, import_function7.pipe)(
fence2.lineNumbersWrapper,
addLinesToContainer(fence2, o, linesAboveTheFold),
select7,
(s) => s.updateAll(".code-line")(addLineClasses(linesAboveTheFold)),
(s) => s.toContainer()
);
return {
...fence2,
trace: `Processed ${fence2.codeLinesCount} lines and put into fence.lineNumbersWrapper [the level was at ${fence2.level}]. Also merged aboveTheFold code [${linesAboveTheFold} lines] with code (if needed) and added meta classes for for each line.`,
aboveTheFoldCode,
code,
lineNumbersWrapper
};
};
// src/pipeline/useHighlighter.ts
function isLineCallback(cb) {
return !!(cb && typeof cb === "function");
}
var klass