Merge pull request #1416 from omnivore-app/fix/highlighting-code-blocks

If in a pre block dont replace whitespace when highlighting
This commit is contained in:
Jackson Harper 2022-11-15 16:43:15 +08:00 committed by GitHub
commit 2c994e941b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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
let isPre = false
const 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) {