提交 ec63f18b authored 作者: 王鹏飞's avatar 王鹏飞

feat: 增加批量去空格和文字气泡转成图标气泡

上级 1afbfb14
class ConvertTooltipType {
constructor() {
this.title = '气泡转换'
this.iconSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill="currentColor" d="M8 0L3 5h3v11h4V5h3L8 0z"/></svg>`
this.tag = 'button'
}
// eslint-disable-next-line no-unused-vars
getValue(editor) {
return ''
}
// eslint-disable-next-line no-unused-vars
isActive(editor) {
return false
}
// eslint-disable-next-line no-unused-vars
isDisabled(editor) {
return false
}
exec(editor) {
// 获取当前 HTML
const html = editor.getHtml()
console.log(html)
if (!html) {
return
}
// 使用正则表达式批量将文字气泡(tooltipType="1")转换为图标气泡(tooltipType="2")
// 匹配 data-tooltipType="1"、data-tooltipType='1'、data-tooltip-type="1"、data-tooltip-type='1' 等格式
const htmlConverted = html
.replace(/data-tooltipType="1"/gi, 'data-tooltipType="2"')
.replace(/data-tooltipType='1'/gi, "data-tooltipType='2'")
.replace(/data-tooltip-type="1"/gi, 'data-tooltip-type="2"')
.replace(/data-tooltip-type='1'/gi, "data-tooltip-type='2'")
console.log(htmlConverted)
// 如果内容有变化,设置回去
if (htmlConverted !== html) {
// 保存当前选区
// 设置处理后的 HTML
editor.setHtml(htmlConverted)
}
}
}
export default {
key: 'ConvertTooltipType', // 定义 menu key :要保证唯一、不重复(重要)
factory() {
return new ConvertTooltipType()
},
}
export { ConvertTooltipType }
...@@ -2,7 +2,7 @@ import { DomEditor, SlateTransforms, SlateRange } from '@wangeditor/editor'; ...@@ -2,7 +2,7 @@ import { DomEditor, SlateTransforms, SlateRange } from '@wangeditor/editor';
class GalleryAuto { class GalleryAuto {
constructor() { constructor() {
this.title = '离线画廊' this.title = '画廊'
this.iconSvg = `<svg width="24px" height="19px" viewBox="0 0 24 19" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> this.iconSvg = `<svg width="24px" height="19px" viewBox="0 0 24 19" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>图标</title> <title>图标</title>
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
......
...@@ -3,7 +3,7 @@ import { DomEditor, SlateTransforms as Transforms, SlateRange } from '@wangedito ...@@ -3,7 +3,7 @@ import { DomEditor, SlateTransforms as Transforms, SlateRange } from '@wangedito
// Extend menu // Extend menu
class ImageAuto { class ImageAuto {
constructor() { constructor() {
this.title = '离线图片' this.title = '图片'
this.iconSvg = `<svg width="23px" height="21px" viewBox="0 0 23 21" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> this.iconSvg = `<svg width="23px" height="21px" viewBox="0 0 23 21" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>编辑器图片样式</title> <title>编辑器图片样式</title>
<g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
......
class RemoveSpaces {
constructor() {
this.title = '去空格'
this.iconSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill="currentColor" d="M2 2h12v12H2V2zm1 1v10h10V3H3zm2 2h6v1H5V5zm0 2h6v1H5V7zm0 2h4v1H5V9z"/></svg>`
this.tag = 'button'
}
// eslint-disable-next-line no-unused-vars
getValue(editor) {
return ''
}
// eslint-disable-next-line no-unused-vars
isActive(editor) {
return false
}
// eslint-disable-next-line no-unused-vars
isDisabled(editor) {
return false
}
exec(editor) {
// 获取当前 HTML
const html = editor.getHtml()
if (!html) {
return
}
// 使用正则表达式去除 HTML 标签之间文本的空格
// 匹配 >文本< 之间的内容,去除空格字符(包括多个相邻的空格)和 &nbsp;,保留其他字符和标签结构
const htmlWithoutSpaces = html.replace(/>([^<]*?)</g, (match, text) => {
// 先去除所有的 &nbsp; HTML 实体
let textWithoutSpaces = text.replace(/&nbsp;+/gi, '')
// 然后去除所有空格字符(包括多个相邻的空格),保留其他字符
textWithoutSpaces = textWithoutSpaces.replace(/ +/g, '')
return `>${textWithoutSpaces}<`
})
// 如果内容有变化,设置回去
if (htmlWithoutSpaces !== html) {
// 设置处理后的 HTML
editor.setHtml(htmlWithoutSpaces)
}
}
}
export default {
key: 'RemoveSpaces', // 定义 menu key :要保证唯一、不重复(重要)
factory() {
return new RemoveSpaces()
},
}
export { RemoveSpaces }
...@@ -34,6 +34,8 @@ import TooltipAutoConf from './customer/Tooltip' ...@@ -34,6 +34,8 @@ import TooltipAutoConf from './customer/Tooltip'
import ImageEditorConf from './customer/ImageEditor' import ImageEditorConf from './customer/ImageEditor'
import CustomerLinkConf from './customer/CustomerLink' import CustomerLinkConf from './customer/CustomerLink'
import ExpandReadConf from './customer/ExpandRead' import ExpandReadConf from './customer/ExpandRead'
import RemoveSpacesConf from './customer/RemoveSpaces'
import ConvertTooltipTypeConf from './customer/ConvertTooltipType'
// AI对话 // AI对话
import AIChat from './menu/AIChat' import AIChat from './menu/AIChat'
...@@ -54,6 +56,8 @@ import AIDigitalHuman from './menu/AIDigitalHuman' ...@@ -54,6 +56,8 @@ import AIDigitalHuman from './menu/AIDigitalHuman'
import AITranslate from './menu/AITranslate' import AITranslate from './menu/AITranslate'
import AISearch from './menu/AISearch' import AISearch from './menu/AISearch'
import AIWrite from './menu/AIWrite' import AIWrite from './menu/AIWrite'
import AIImage from './menu/AIImage'
import AIBaiduSearch from './menu/AIBaiduSearch'
import ImageModal from './components/image' import ImageModal from './components/image'
import VideoModal from './components/video' import VideoModal from './components/video'
...@@ -105,6 +109,8 @@ const module = { ...@@ -105,6 +109,8 @@ const module = {
ImageEditorConf, ImageEditorConf,
CustomerLinkConf, CustomerLinkConf,
ExpandReadConf, ExpandReadConf,
RemoveSpacesConf,
ConvertTooltipTypeConf,
AIChat, AIChat,
AIRewrite, AIRewrite,
AIExpand, AIExpand,
...@@ -121,6 +127,8 @@ const module = { ...@@ -121,6 +127,8 @@ const module = {
AITranslate, AITranslate,
AISearch, AISearch,
AIWrite, AIWrite,
AIImage,
AIBaiduSearch,
], ],
} }
Boot.registerModule(module) Boot.registerModule(module)
...@@ -195,7 +203,7 @@ const WangEditorCustomer = (props, ref) => { ...@@ -195,7 +203,7 @@ const WangEditorCustomer = (props, ref) => {
const [isOnline, setIsOnline] = useState(false) const [isOnline, setIsOnline] = useState(false)
window.addEventListener('setItemEvent', function (e) { const handleSetItemEvent = (e) => {
if (e.key === 'chapterTitleNum') { if (e.key === 'chapterTitleNum') {
setTitleInfo(JSON.parse(e.newValue)) setTitleInfo(JSON.parse(e.newValue))
setTitleVisible(true) setTitleVisible(true)
...@@ -240,7 +248,14 @@ const WangEditorCustomer = (props, ref) => { ...@@ -240,7 +248,14 @@ const WangEditorCustomer = (props, ref) => {
window.localStorage.removeItem('chapterExpand') window.localStorage.removeItem('chapterExpand')
}, 100) }, 100)
} }
}) }
useEffect(() => {
window.addEventListener('setItemEvent', handleSetItemEvent)
return () => {
window.removeEventListener('setItemEvent', handleSetItemEvent)
}
}, [])
const closePanel = () => { const closePanel = () => {
dispatch(setPracticeRandom({ practiceNum: null, practiceTitle: null })) dispatch(setPracticeRandom({ practiceNum: null, practiceTitle: null }))
...@@ -332,10 +347,11 @@ const WangEditorCustomer = (props, ref) => { ...@@ -332,10 +347,11 @@ const WangEditorCustomer = (props, ref) => {
'justifyJustify', 'justifyJustify',
'divider', 'divider',
'|', '|',
// 'AIImage',
'ImageAuto', 'ImageAuto',
'ImageAutoOnline', // 'ImageAutoOnline',
'GalleryAuto', 'GalleryAuto',
'GalleryAutoOnline', // 'GalleryAutoOnline',
'VideoAuto', 'VideoAuto',
'AudioAuto', 'AudioAuto',
'insertTable', 'insertTable',
...@@ -349,6 +365,8 @@ const WangEditorCustomer = (props, ref) => { ...@@ -349,6 +365,8 @@ const WangEditorCustomer = (props, ref) => {
'Practice', 'Practice',
'TooltipAuto', 'TooltipAuto',
'ExpandRead', 'ExpandRead',
'RemoveSpaces',
'ConvertTooltipType',
'|', '|',
'AIRewrite', 'AIRewrite',
'AIExpand', 'AIExpand',
...@@ -366,7 +384,8 @@ const WangEditorCustomer = (props, ref) => { ...@@ -366,7 +384,8 @@ const WangEditorCustomer = (props, ref) => {
'AIDigitalHuman', 'AIDigitalHuman',
'AITranslate', 'AITranslate',
'AISearch', 'AISearch',
'AIWrite', // 'AIWrite',
// 'AIBaiduSearch',
], ],
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论