forked from tanner/qotnews
fix: Refine code block detection to ignore inline <code>
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -60,7 +60,25 @@ function Article({ cache }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const isCodeBlock = (v) => {
|
const isCodeBlock = (v) => {
|
||||||
return v.localName === 'pre' || (v.localName === 'code' && !v.closest('p'));
|
if (v.localName === 'pre') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (v.localName === 'code') {
|
||||||
|
if (v.closest('p')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const parent = v.parentElement;
|
||||||
|
if (parent) {
|
||||||
|
const nonWhitespaceChildren = Array.from(parent.childNodes).filter(n => {
|
||||||
|
return n.nodeType !== Node.TEXT_NODE || n.textContent.trim() !== '';
|
||||||
|
});
|
||||||
|
if (nonWhitespaceChildren.length === 1 && nonWhitespaceChildren[0] === v) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderNodes = (nodes, keyPrefix = '') => {
|
const renderNodes = (nodes, keyPrefix = '') => {
|
||||||
|
|||||||
Reference in New Issue
Block a user