wizhi更新
This commit is contained in:
1 parent
d4e89788c5
commit
0c6efc4160
16 files changed
+11810
-811
No files matched your search
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
const TABLE_STYLE = 'border-collapse: collapse; width: 100%; border: 1px solid #dcdfe6; margin: 12px 0; table-layout: auto;'
|
||||
const TABLE_CLASS = 'rich-table note-rich-editor-table'
|
||||
const TR_STYLE = 'border-bottom: 1px solid #ebeef5;'
|
||||
const TH_STYLE = 'border: 1px solid #dcdfe6; background-color: #f5f7fa; color: #303133; font-weight: 600; padding: 8px 12px; font-size: 14px; text-align: left; min-width: 44px; word-break: break-word;'
|
||||
const TD_STYLE = 'border: 1px solid #dcdfe6; background-color: #ffffff; color: #303133; padding: 8px 12px; font-size: 14px; vertical-align: top; word-break: break-word; min-width: 44px;'
|
||||
@@ -26,9 +27,22 @@ export function injectTableInlineStyles(html) {
|
||||
} else {
|
||||
cleanAttrs = ` style="${TABLE_STYLE}"` + cleanAttrs
|
||||
}
|
||||
if (/class\s*=\s*["']/i.test(cleanAttrs)) {
|
||||
cleanAttrs = cleanAttrs.replace(/class\s*=\s*["']([^"']*)["']/i, (m, value) => `class="${value} ${TABLE_CLASS}"`)
|
||||
} else {
|
||||
cleanAttrs = ` class="${TABLE_CLASS}"` + cleanAttrs
|
||||
}
|
||||
return `<table border="1" cellpadding="8" cellspacing="0"${cleanAttrs}>`
|
||||
})
|
||||
|
||||
// 使用 class 定位表体,避免小程序端不支持 tbody 标签选择器
|
||||
res = res.replace(/<tbody(\s+[^>]*)?>/gi, (match, attrs = '') => {
|
||||
if (/class\s*=\s*["']/i.test(attrs)) {
|
||||
return `<tbody${attrs.replace(/class\s*=\s*["']([^"']*)["']/i, (m, value) => `class="${value} rich-table__body"`)}>`
|
||||
}
|
||||
return `<tbody class="rich-table__body"${attrs}>`
|
||||
})
|
||||
|
||||
// 注入 tr 样式
|
||||
res = res.replace(/<tr(\s+[^>]*)?>/gi, (match, attrs = '') => {
|
||||
if (/style\s*=\s*["']/i.test(attrs)) {
|
||||
|
||||
Reference in new issue
Block a user