@sy-common/wang-editor 1.0.0-beta.13 → 1.0.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.vue +26 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sy-common/wang-editor",
3
- "version": "1.0.0-beta.13",
3
+ "version": "1.0.0-beta.15",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "lambo",
package/src/index.vue CHANGED
@@ -117,10 +117,10 @@ export default {
117
117
  {
118
118
  name: "宋体",
119
119
  value: "宋体"
120
- }, "隶书","方正小标宋简体", "思源宋体‌", "微软雅黑", "Arial", "Tahoma", "Verdana", "Times New Roman", "Courier New"]
120
+ }, "隶书", "方正小标宋简体", "思源宋体‌", "微软雅黑", "Arial", "Tahoma", "Verdana", "Times New Roman", "Courier New"]
121
121
  },
122
- color:{
123
- colors:[
122
+ color: {
123
+ colors: [
124
124
  "rgb(0, 0, 0)",
125
125
  "rgb(38, 38, 38)",
126
126
  "rgb(89, 89, 89)",
@@ -244,13 +244,29 @@ export default {
244
244
  onChange(editor) {
245
245
  let self = this;
246
246
  let html = this.editor.getHtml()
247
- if (html.includes('table')) {
248
- html = html.replace(/<table /g, '<table class="wangeditor-styled-table" style= "border-collapse: collapse;"'); // 添加边框)
249
- }
250
- if(html.includes('hr')){
251
- html = html.replace(/<hr/g,'<hr style="border:1px solid rgb(250, 64, 6);"');
252
- }
253
- console.log("this.editor.getMenuConfig('color')",this.editor.getMenuConfig('color'))
247
+ // 创建一个临时的 div 容器来解析 HTML
248
+ const tempDiv = document.createElement('div');
249
+ tempDiv.innerHTML = html;
250
+
251
+ // 处理 table 元素
252
+ const tables = tempDiv.querySelectorAll('table');
253
+ tables.forEach(table => {
254
+ const currentStyle = table.getAttribute('style') || '';
255
+ const newStyle = `${currentStyle}; border-collapse: collapse;`.trim();
256
+ table.setAttribute('class', 'wangeditor-styled-table');
257
+ table.setAttribute('style', newStyle);
258
+ });
259
+
260
+ // 处理 hr 元素
261
+ const hrs = tempDiv.querySelectorAll('hr');
262
+ hrs.forEach(hr => {
263
+ const currentStyle = hr.getAttribute('style') || '';
264
+ const newStyle = `${currentStyle}; border: 1px solid rgb(250, 64, 6);`.trim();
265
+ hr.setAttribute('style', newStyle);
266
+ });
267
+ // 更新处理后的 HTML
268
+ html = tempDiv.innerHTML;
269
+ console.log("this.editor.getMenuConfig('color')", this.editor.getMenuConfig('color'))
254
270
  this.$emit('input', self.valueType === 'html' ? html : editor.getText())
255
271
  this.$emit('on-change', html, editor.getText())
256
272
  },