From 7203f5e7f2a5c59cf288e57fad3a4d6b21c3982d Mon Sep 17 00:00:00 2001 From: augushong Date: Fri, 25 Mar 2022 22:07:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=A7=8B=E4=BC=98=E5=8C=96=E6=A0=87?= =?UTF-8?q?=E7=82=B9,=E6=9C=89=E9=97=AE=E9=A2=98;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- view/admin/post/edit_content.html | 62 +++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/view/admin/post/edit_content.html b/view/admin/post/edit_content.html index a3d5e2a..752bddb 100644 --- a/view/admin/post/edit_content.html +++ b/view/admin/post/edit_content.html @@ -68,6 +68,10 @@ min-height: 500px; margin-top: 20px; } + + #settle-content-mark { + cursor: pointer; + } @@ -94,8 +98,11 @@
-
- 内容变动自动提交 +
+ 内容变动自动提交 + + 智能优化标点 +
@@ -162,7 +169,6 @@ editorConfig.customPaste = function (editor, event) { var pasteStr = event.clipboardData.getData('text/html'); - //1,匹配出图片img标签(即匹配出所有图片),过滤其他不需要的字符 //2.从匹配出来的结果(img标签中)循环匹配出图片地址(即src属性) @@ -245,6 +251,56 @@ }, 300); + $('#settle-content-mark').click(function () { + var content = editor.getHtml(); + var contentDom = $(content); + + var newContentDom = []; + contentDom.each(function (index, elem) { + var tagName = elem.tagName; + + var settleTagList = [ + 'P', + 'H1', + 'H2', + 'H3', + 'H4', + 'UL', + ]; + if (settleTagList.indexOf(tagName) < 0) { + newContentDom.push(elem) + return true; + } + + var html = $(elem).html(); + html = html.replaceAll(',', ','); + html = html.replaceAll('.', '。'); + html = html.replaceAll('!', '!'); + html = html.replaceAll(':', ';'); + html = html.replaceAll(':', ':'); + html = html.replaceAll('?', '?'); + // html = html.replaceAll('<', '《'); + // html = html.replaceAll('>', '》'); + html = html.replaceAll('/', '、'); + + $(elem).html(html) + + newContentDom.push(elem) + + + }) + + editor.clear() + + newContentDom.forEach(elem => { + var outerHTML = $(elem).prop('outerHTML'); + console.log(outerHTML); + editor.dangerouslyInsertHtml(outerHTML) + }); + + }) + + // 点击空白处 focus 编辑器 document.getElementById('editor-text-area').addEventListener('click', e => { if (e.target.id === 'editor-text-area') {