fix: 🐛 Tog bort radbrytning i bold (#66)
This commit is contained in:
parent
a5dfb704f4
commit
ca0117ce64
|
@ -34,6 +34,12 @@ describe('parseHtml', () => {
|
|||
<A href="/foo%20bar">Hello</A>
|
||||
</DIV>`
|
||||
|
||||
expect(clean(html)).toEqual(expected)
|
||||
})
|
||||
it('handles breaks in <strong>', () => {
|
||||
const html = '<strong>Uppdatering 2021-02-08 <br /></strong>'
|
||||
const expected = '<STRONG>Uppdatering 2021-02-08</STRONG>'
|
||||
|
||||
expect(clean(html)).toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
@ -131,4 +137,4 @@ Stort tack för ert samarbete!`
|
|||
expect(toMarkdown(html)).toEqual(expected)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -5,13 +5,16 @@ import {
|
|||
parse, HTMLElement, TextNode,
|
||||
} from 'node-html-parser'
|
||||
|
||||
const trimNodes = [
|
||||
const noChildren = [
|
||||
'strong',
|
||||
'b',
|
||||
'em',
|
||||
'i',
|
||||
'u',
|
||||
's',
|
||||
]
|
||||
const trimNodes = [
|
||||
...noChildren,
|
||||
'h1',
|
||||
'h2',
|
||||
'h3',
|
||||
|
@ -40,7 +43,11 @@ const deepClean = (node: HTMLElement): HTMLElement => {
|
|||
const cleaned = new HTMLElement(node.tagName, {}, attributes, node.parentNode)
|
||||
node.childNodes.forEach((childNode) => {
|
||||
if (childNode instanceof HTMLElement) {
|
||||
cleaned.childNodes.push(deepClean(childNode))
|
||||
if (node.tagName && noChildren.includes(node.tagName.toLowerCase())) {
|
||||
cleaned.childNodes.push(cleanText(new TextNode(childNode.innerText), node.tagName))
|
||||
} else {
|
||||
cleaned.childNodes.push(deepClean(childNode))
|
||||
}
|
||||
} else if (childNode instanceof TextNode) {
|
||||
cleaned.childNodes.push(cleanText(childNode, node.tagName))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue