If in a pre block dont replace whitespace when highlighting

This commit is contained in:
Jackson Harper 2022-11-15 15:34:27 +08:00
parent ed7303b9fb
commit aa856a5366
2 changed files with 9 additions and 3 deletions

View file

@ -195,7 +195,6 @@ export function ArticleContainer(props: ArticleContainerProps): JSX.Element {
readerTableHeaderColor: theme.colors.readerTableHeader.toString(),
readerHeadersColor: theme.colors.readerHeader.toString(),
}
console.log('setting font family: ', styles.fontFamily)
return (
<>

View file

@ -121,10 +121,17 @@ export function makeHighlightNodeAttributes(
})
const { parentNode, nextSibling } = node
var isPre = false
var nodeElement = (node instanceof HTMLElement) ? node : node.parentElement
if (nodeElement) {
isPre = (window.getComputedStyle(nodeElement).whiteSpace.startsWith('pre'))
}
parentNode?.removeChild(node)
textPartsToHighlight.forEach(({ highlight, text: rawText }, i) => {
// Prevent hardcoded \n, we'll create new-lines based on the startsParagraph data
const text = rawText.replace(/\n/g, '')
// If we are not in preformatted text, prevent hardcoded \n,
// we'll create new-lines based on the startsParagraph data
const text = isPre ? rawText : rawText.replace(/\n/g, '')
const newTextNode = document.createTextNode(text)
if (!highlight) {