refactor: Extract code block detection into isCodeBlock function

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2025-12-03 01:46:19 +00:00
parent da108f25d4
commit 6dc47f6672

View File

@@ -57,6 +57,10 @@ function Article({ cache }) {
setPConv(prevPConv => [...prevPConv, n]); setPConv(prevPConv => [...prevPConv, n]);
}; };
const isCodeBlock = (v) => {
return v.localName === 'pre' || v.localName === 'code' || (v.children?.length === 1 && v.children[0].localName === 'code');
};
const nodes = useMemo(() => { const nodes = useMemo(() => {
if (story && story.text) { if (story && story.text) {
let div = document.createElement('div'); let div = document.createElement('div');
@@ -105,7 +109,7 @@ function Article({ cache }) {
: :
<React.Fragment key={k}> <React.Fragment key={k}>
<v.localName dangerouslySetInnerHTML={v.innerHTML ? { __html: v.innerHTML } : null} /> <v.localName dangerouslySetInnerHTML={v.innerHTML ? { __html: v.innerHTML } : null} />
{(v.localName === 'pre' || v.localName === 'code' || (v.children?.length === 1 && v.children[0].localName === 'code')) && <button onClick={() => pConvert(k)}>Convert Code to Paragraph</button>} {isCodeBlock(v) && <button onClick={() => pConvert(k)}>Convert Code to Paragraph</button>}
</React.Fragment> </React.Fragment>
) )
)} )}