diff --git a/src/app/plugins/react-custom-html-parser.tsx b/src/app/plugins/react-custom-html-parser.tsx index 76bcc6622..f1ce4d83e 100644 --- a/src/app/plugins/react-custom-html-parser.tsx +++ b/src/app/plugins/react-custom-html-parser.tsx @@ -333,13 +333,10 @@ const extractTextFromChildren = (nodes: ChildNode[]): string => { return text; }; -export function CodeBlock({ - children, - opts, -}: { - children: ChildNode[]; - opts: HTMLReactParserOptions; -}) { +export // Session memory for the code-block Wrap toggle (#131). +const codeWrapPreference = { value: false }; + +function CodeBlock({ children, opts }: { children: ChildNode[]; opts: HTMLReactParserOptions }) { const code = children[0]; const attribs = code instanceof Element && code.name === 'code' ? code.attribs : undefined; const languageClass = attribs?.class; @@ -357,6 +354,13 @@ export function CodeBlock({ const [expanded, setExpand] = useState(false); const [copied, setCopied] = useTimeoutToggle(); + // [Gitea #131] Line-wrap toggle for long lines; the choice is remembered for + // the session (module-level), not persisted. + const [wrap, setWrap] = useState(codeWrapPreference.value); + const toggleWrap = () => { + codeWrapPreference.value = !wrap; + setWrap(!wrap); + }; const handleCopy = () => { copyToClipboard(extractTextFromChildren(children)); @@ -376,6 +380,16 @@ export function CodeBlock({ + + Wrap + -
+
{domToReact(children as unknown as DOMNode[], opts)}