This commit is contained in:
team3
2026-06-30 00:14:18 +02:00
parent 3e3559aa8f
commit c794fcaccf
152 changed files with 9485 additions and 9583 deletions

View File

@@ -17,9 +17,9 @@ marked.use(markedHighlight({
}))
marked.setOptions({ breaks: true, gfm: true })
// LaTeX-Mathe via KaTeX. Eigene marked-Extensions (statt marked-katex-extension,
// die marked v18 hinterherhinkt). marked tokenisiert Code zuerst → $…$ in Code-
// Blöcken wird NICHT als Mathe erkannt. throwOnError:false zeigt defektes TeX rot.
// LaTeX math via KaTeX. Own marked extensions (instead of marked-katex-extension,
// which lags behind marked v18). marked tokenizes code first → $…$ inside code
// blocks is NOT treated as math. throwOnError:false renders broken TeX in red.
function renderTex(tex, displayMode) {
return katex.renderToString(tex, { displayMode, throwOnError: false, output: 'html' })
}
@@ -40,8 +40,8 @@ const inlineMath = {
level: 'inline',
start(src) { const i = src.indexOf('$'); return i < 0 ? undefined : i },
tokenizer(src) {
// $…$: kein $$, kein Leerzeichen direkt hinter dem öffnenden $ und vor dem
// schließenden $ (pandoc-Stil) → mindert Kollisionen mit Fließtext-Dollarzeichen.
// $…$: no $$, no space right after the opening $ or before the closing $
// (pandoc style) → reduces collisions with dollar signs in prose.
const m = /^\$(?![\s$])((?:\\\$|[^$])+?)\$/.exec(src)
if (!m || /\s$/.test(m[1])) return
return { type: 'inlineMath', raw: m[0], text: m[1].trim() }
@@ -51,8 +51,8 @@ const inlineMath = {
marked.use({ extensions: [blockMath, inlineMath] })
// Rohes HTML im Markdown (z. B. <p>, <img> ohne Backticks aus Agenten-Output)
// als Text anzeigen statt rendernsonst verschluckt der Browser den Inhalt.
// Raw HTML in markdown (e.g. <p>, <img> without backticks from agent output)
// shown as text instead of renderedotherwise the browser swallows the content.
marked.use({
renderer: {
html(token) {
@@ -66,15 +66,20 @@ export function renderMarkdown(text) {
return DOMPurify.sanitize(marked.parse(text || ''))
}
// Inline-Variante (kein <p>-Wrapping) für kurze Texte wie Quiz-Optionen oder
// Lückentext-Satzteile — rendert $…$-Mathe und Markdown ohne Block-Umbruch.
// Inline variant (no <p> wrapping) for short texts like quiz options or
// gap-text sentence fragments — renders $…$ math and markdown without a block break.
export function renderMarkdownInline(text) {
return DOMPurify.sanitize(marked.parseInline(text || ''))
}
// Markdown in Top-Level-Blöcke zerlegen: je Block { raw (exakte Quelle), html }.
// raw ist verlustfrei (tokens.map(raw).join('') === Original) → Block-genaues Ersetzen.
export function renderBloecke(text) {
// Strip markdown to plain text (code fences + inline marks) — for previews/search.
export function plainText(text) {
return (text || '').replace(/```[a-z]*\n?/g, '').replace(/[`*_#]/g, '')
}
// Split markdown into top-level blocks: each block { raw (exact source), html }.
// raw is lossless (tokens.map(raw).join('') === original) → block-precise replacement.
export function renderBlocks(text) {
const tokens = marked.lexer(text || '')
return tokens
.filter((t) => t.type !== 'space' && (t.raw || '').trim())