开始优化标点,有问题;

This commit is contained in:
2022-03-25 22:07:09 +08:00
parent beb4707bf0
commit 7203f5e7f2

View File

@@ -68,6 +68,10 @@
min-height: 500px; min-height: 500px;
margin-top: 20px; margin-top: 20px;
} }
#settle-content-mark {
cursor: pointer;
}
</style> </style>
</head> </head>
@@ -94,8 +98,11 @@
<div id="editor-text-area"></div> <div id="editor-text-area"></div>
</div> </div>
</div> </div>
<div id="content-state" style="height: 30px;line-height: 30px;padding-left: 15px;border-top: 1px solid #e8e8e8;color: #666;"> <div style="height: 30px;line-height: 30px;padding-left: 15px;border-top: 1px solid #e8e8e8;color: #666;">
内容变动自动提交 <span id="content-state">内容变动自动提交</span>
<span id="settle-content-mark">
智能优化标点
</span>
</div> </div>
<div id="content-data" style="display: none;">{:rawurlencode($post->content_html)}</div> <div id="content-data" style="display: none;">{:rawurlencode($post->content_html)}</div>
</div> </div>
@@ -162,7 +169,6 @@
editorConfig.customPaste = function (editor, event) { editorConfig.customPaste = function (editor, event) {
var pasteStr = event.clipboardData.getData('text/html'); var pasteStr = event.clipboardData.getData('text/html');
//1匹配出图片img标签即匹配出所有图片过滤其他不需要的字符 //1匹配出图片img标签即匹配出所有图片过滤其他不需要的字符
//2.从匹配出来的结果img标签中循环匹配出图片地址即src属性 //2.从匹配出来的结果img标签中循环匹配出图片地址即src属性
@@ -245,6 +251,56 @@
}, 300); }, 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 编辑器 // 点击空白处 focus 编辑器
document.getElementById('editor-text-area').addEventListener('click', e => { document.getElementById('editor-text-area').addEventListener('click', e => {
if (e.target.id === 'editor-text-area') { if (e.target.id === 'editor-text-area') {