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:
@@ -57,6 +57,10 @@ function Article({ cache }) {
|
||||
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(() => {
|
||||
if (story && story.text) {
|
||||
let div = document.createElement('div');
|
||||
@@ -105,7 +109,7 @@ function Article({ cache }) {
|
||||
:
|
||||
<React.Fragment key={k}>
|
||||
<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>
|
||||
)
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user