Fixed bug that two p-tags were encapsulated inside each other (#278)

* Fixed bug that two p-tags were encapsulated inside each other

This bug was introduced because the wider-possible-replacer replaced each element that was subject to be enlarged with a brand new p-surrounding. That surrounding got the key of the old (now inner) element and therefore casts an duplicate key exception.
This fix solves that problem by setting the 'wider-possible' class attribute directly on the selected tag instead of creating a surrounding.

* Removed unnecessary console log

* Optimized attribute assignment to not fail on elements without attribs

* Added comment describing the node.attribs assignment
This commit is contained in:
Erik Michelson 2020-06-26 00:07:15 +02:00 committed by GitHub
parent 937a2e9eb9
commit 17cc691403
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -52,7 +52,7 @@ export interface MarkdownPreviewProps {
wide?: boolean
}
const createMarkdownIt = ():MarkdownIt => {
const createMarkdownIt = (): MarkdownIt => {
const md = new MarkdownIt('default', {
html: true,
breaks: true,

View file

@ -17,8 +17,9 @@ export class PossibleWiderReplacer implements ComponentReplacer {
if (!(childIsImage || childIsYoutube || childIsVimeo || childIsPDF)) {
return
}
return (<p className='wider-possible'>
{subNodeConverter(node, index)}
</p>)
// This appends the 'wider-possible' class to the node for a wider view in view-mode
node.attribs = Object.assign(node.attribs || {}, { class: `wider-possible ${node.attribs?.class || ''}` })
return subNodeConverter(node, index)
}
}