Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
166 lines
4.7 KiB
JavaScript
166 lines
4.7 KiB
JavaScript
const FontStyle = {
|
|
NotSet: -1,
|
|
None: 0,
|
|
Italic: 1,
|
|
Bold: 2,
|
|
Underline: 4,
|
|
};
|
|
|
|
const FONT_STYLE_TO_CSS = {
|
|
[FontStyle.Italic]: "font-style: italic",
|
|
[FontStyle.Bold]: "font-weight: bold",
|
|
[FontStyle.Underline]: "text-decoration: underline",
|
|
};
|
|
|
|
const renderToHtml = function (lines, options = {}) {
|
|
const theme = options.theme;
|
|
const themes = options.themes;
|
|
const highlightedLines = makeHighlightSet(options.highlightLines);
|
|
const addLines = makeHighlightSet(options.addLines);
|
|
const deleteLines = makeHighlightSet(options.deleteLines);
|
|
const focusLines = makeHighlightSet(options.focusLines);
|
|
|
|
let className = "shiki";
|
|
|
|
if (highlightedLines.size) {
|
|
className += " highlighted";
|
|
}
|
|
if (addLines.size) {
|
|
className += " added";
|
|
}
|
|
if (deleteLines.size) {
|
|
className += " deleted";
|
|
}
|
|
if (focusLines.size) {
|
|
className += " focus";
|
|
}
|
|
|
|
let html = "";
|
|
|
|
if (theme) {
|
|
html += `<pre class="${className}" style="background-color: ${theme.theme.bg}">`;
|
|
} else if (themes) {
|
|
const backgroundStyles = Object.entries(themes).map(
|
|
([theme, theme$]) => {
|
|
if (theme === "light") {
|
|
return `background-color:${theme$.theme.bg};`;
|
|
}
|
|
|
|
return `--shiki-${theme}-bg:${theme$.theme.bg};`;
|
|
}
|
|
);
|
|
|
|
const foregroundStyles = Object.entries(themes).map(
|
|
([theme, theme$]) => {
|
|
if (theme === "light") {
|
|
return `color:${theme$.theme.fg};`;
|
|
}
|
|
|
|
return `--shiki-${theme}:${theme$.theme.fg};`;
|
|
}
|
|
);
|
|
|
|
const classes = `${className} shiki-themes ${Object.values(themes)
|
|
.map((theme) => theme.theme.name)
|
|
.join(" ")}`;
|
|
|
|
html += `<pre class="${classes}" style="${backgroundStyles.join(
|
|
""
|
|
)}${foregroundStyles.join("")}">`;
|
|
}
|
|
|
|
if (options.langId) {
|
|
html += `<div class="language-id">${options.langId}</div>`;
|
|
}
|
|
html += `<code>`;
|
|
|
|
lines.forEach((l, index) => {
|
|
const lineNumber = index + 1;
|
|
|
|
let lineClass = "line";
|
|
if (highlightedLines.has(lineNumber)) {
|
|
lineClass += " highlight";
|
|
}
|
|
if (addLines.has(lineNumber)) {
|
|
lineClass += " add";
|
|
}
|
|
if (deleteLines.has(lineNumber)) {
|
|
lineClass += " del";
|
|
}
|
|
if (focusLines.has(lineNumber)) {
|
|
lineClass += " focus";
|
|
}
|
|
|
|
html += `<span class="${lineClass.trim()}">`;
|
|
|
|
l.forEach((token) => {
|
|
const cssDeclarations = [];
|
|
if (theme) {
|
|
cssDeclarations.push(`color:${token.color || theme.theme.fg}`);
|
|
} else if (themes) {
|
|
/**
|
|
* The `htmlStyle` property can be a `string` or an `object`. The `string` representation is deprecated.
|
|
* @see https://github.com/search?q=repo%3Ashikijs%2Fshiki+htmlStyle&type=code
|
|
*/
|
|
if (typeof token.htmlStyle === "string") {
|
|
cssDeclarations.push(token.htmlStyle);
|
|
} else if (typeof token.htmlStyle === "object") {
|
|
for (const [key, value] of Object.entries(
|
|
token.htmlStyle
|
|
)) {
|
|
cssDeclarations.push(`${key}:${value}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (token.fontStyle > FontStyle.None) {
|
|
cssDeclarations.push(FONT_STYLE_TO_CSS[token.fontStyle]);
|
|
}
|
|
html += `<span style="${cssDeclarations.join(";")}">${escapeHtml(
|
|
token.content
|
|
)}</span>`;
|
|
});
|
|
html += `</span>\n`;
|
|
});
|
|
html = html.replace(/\n*$/, ""); // Get rid of final new lines
|
|
html += `</code></pre>`;
|
|
|
|
return html;
|
|
};
|
|
|
|
const makeHighlightSet = function (highlightLines) {
|
|
const lines = new Set();
|
|
|
|
if (!highlightLines) {
|
|
return lines;
|
|
}
|
|
|
|
for (let lineSpec of highlightLines) {
|
|
if (lineSpec.toString().includes("-")) {
|
|
const [begin, end] = lineSpec
|
|
.split("-")
|
|
.map((lineNo) => Number(lineNo));
|
|
for (let line = begin; line <= end; line++) {
|
|
lines.add(line);
|
|
}
|
|
} else if (lineSpec.toString().trim()) {
|
|
lines.add(Number(lineSpec));
|
|
}
|
|
}
|
|
|
|
return lines;
|
|
};
|
|
|
|
const htmlEscapes = {
|
|
"&": "&",
|
|
"<": "<",
|
|
">": ">",
|
|
'"': """,
|
|
"'": "'",
|
|
};
|
|
|
|
function escapeHtml(html) {
|
|
return html.replace(/[&<>"']/g, (chr) => htmlEscapes[chr]);
|
|
}
|
|
|
|
exports.renderToHtml = renderToHtml;
|