mirror of
https://github.com/marktext/marktext.git
synced 2025-05-02 20:49:15 +08:00
* fix: #2836 fix formula first render * Revert "refresh svg by innerHTML" * add NS to vNode before path * improve readability
This commit is contained in:
parent
d24a578a1a
commit
ccf105e146
@ -1,7 +1,7 @@
|
||||
import loadRenderer from '../../renderers'
|
||||
import { CLASS_OR_ID } from '../../config'
|
||||
import { conflict, mixins, camelToSnake } from '../../utils'
|
||||
import { patch, toVNode, toHTML, h } from './snabbdom'
|
||||
import { patch, toVNode, toHTML, h, addNStoVNodeSvgChildren } from './snabbdom'
|
||||
import { beginRules } from '../rules'
|
||||
import renderInlines from './renderInlines'
|
||||
import renderBlock from './renderBlock'
|
||||
@ -175,7 +175,7 @@ class StateRender {
|
||||
const children = blocks.map(block => {
|
||||
return this.renderBlock(null, block, activeBlocks, matches, true)
|
||||
})
|
||||
|
||||
addNStoVNodeSvgChildren(children)
|
||||
const newVdom = h(selector, children)
|
||||
const rootDom = document.querySelector(selector) || this.container
|
||||
const oldVdom = toVNode(rootDom)
|
||||
|
@ -17,3 +17,21 @@ export const htmlToVNode = html => { // helper function for convert html to vnod
|
||||
wrapper.innerHTML = html
|
||||
return toVNode(wrapper).children
|
||||
}
|
||||
|
||||
const addNS = ({ data, children, sel }) => {
|
||||
data.ns = 'http://www.w3.org/2000/svg'
|
||||
if (sel !== 'foreignObject' && children !== undefined) {
|
||||
for (const vNode of children) {
|
||||
if (vNode.data === undefined) continue
|
||||
addNS(vNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const addNStoVNodeSvgChildren = (children = []) => {
|
||||
for (const vNode of children) {
|
||||
if (vNode.data === undefined) continue
|
||||
if (vNode.sel.startsWith('svg')) addNS(vNode)
|
||||
addNStoVNodeSvgChildren(vNode.children)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user