Skip to content

Commit

Permalink
feat(runtime-web): rich-text 拓展属性支持
Browse files Browse the repository at this point in the history
  • Loading branch information
hwaphon committed Apr 3, 2024
1 parent f622e41 commit 9ddec27
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/runtime-web/src/components/src/base/rich-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ const Rules = {
tr: 1,
ul: 1
}
// 维护 props => attribute 的映射
const PROPS_MAP = {
className: 'class'
}

function decode(text) {
return text.replace(/&([a-zA-Z]*?);/g, function (match, p) {
Expand Down Expand Up @@ -216,8 +220,13 @@ export default class RichText extends BaseElement {

parseHtmlTag(tagName, props, children) {
const element = document.createElement(tagName)
element.setAttribute('class', props.className || '')
element.setAttribute('style', props.style || '')
// props 已经在 getNodeProps 中做了过滤处理,所以走到这里后应该全量设置
const keys = Object.keys(props || {})
if (keys.length > 0) {
keys.forEach((key) => {
element.setAttribute(PROPS_MAP[key] || key, props[key])
})
}

if (!children) return element

Expand Down

0 comments on commit 9ddec27

Please sign in to comment.