vue-editify 0.1.17 → 0.1.19
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.
- package/README.md +3 -3
 - package/examples/App.vue +62 -53
 - package/examples/main.ts +4 -4
 - package/lib/components/button/button.vue.d.ts +11 -11
 - package/lib/components/checkbox/checkbox.vue.d.ts +8 -8
 - package/lib/components/colors/colors.vue.d.ts +4 -4
 - package/lib/components/icon/icon.vue.d.ts +1 -1
 - package/lib/components/insertImage/insertImage.vue.d.ts +9 -9
 - package/lib/components/insertLink/insertLink.vue.d.ts +2 -2
 - package/lib/components/insertTable/insertTable.vue.d.ts +2 -2
 - package/lib/components/insertVideo/insertVideo.vue.d.ts +9 -9
 - package/lib/components/layer/layer.vue.d.ts +9 -9
 - package/lib/components/menu/menu.vue.d.ts +4 -4
 - package/lib/components/toolbar/toolbar.vue.d.ts +9 -9
 - package/lib/components/tooltip/tooltip.vue.d.ts +1 -1
 - package/lib/components/triangle/triangle.vue.d.ts +4 -4
 - package/lib/editify/editify.vue.d.ts +88 -70
 - package/lib/editify/props.d.ts +11 -3
 - package/lib/editify.es.js +65 -46
 - package/lib/editify.umd.js +1 -1
 - package/lib/index.d.ts +1 -1
 - package/lib/style.css +1 -1
 - package/package.json +45 -45
 - package/src/components/button/button.less +145 -145
 - package/src/components/button/button.vue +197 -197
 - package/src/components/button/props.ts +95 -95
 - package/src/components/checkbox/checkbox.less +84 -84
 - package/src/components/checkbox/checkbox.vue +68 -68
 - package/src/components/checkbox/props.ts +49 -49
 - package/src/components/colors/colors.less +75 -75
 - package/src/components/colors/colors.vue +36 -36
 - package/src/components/colors/props.ts +29 -29
 - package/src/components/icon/icon.less +14 -14
 - package/src/components/icon/icon.vue +12 -12
 - package/src/components/icon/props.ts +11 -11
 - package/src/components/insertImage/insertImage.less +135 -135
 - package/src/components/insertImage/insertImage.vue +146 -146
 - package/src/components/insertImage/props.ts +43 -43
 - package/src/components/insertLink/insertLink.less +64 -64
 - package/src/components/insertLink/insertLink.vue +58 -58
 - package/src/components/insertLink/props.ts +16 -16
 - package/src/components/insertTable/insertTable.less +54 -54
 - package/src/components/insertTable/insertTable.vue +85 -85
 - package/src/components/insertTable/props.ts +27 -27
 - package/src/components/insertVideo/insertVideo.less +135 -135
 - package/src/components/insertVideo/insertVideo.vue +146 -146
 - package/src/components/insertVideo/props.ts +43 -43
 - package/src/components/layer/layer.less +49 -49
 - package/src/components/layer/layer.vue +598 -598
 - package/src/components/layer/props.ts +71 -71
 - package/src/components/menu/menu.less +63 -63
 - package/src/components/menu/menu.vue +1569 -1569
 - package/src/components/menu/props.ts +17 -17
 - package/src/components/toolbar/props.ts +35 -35
 - package/src/components/toolbar/toolbar.less +89 -89
 - package/src/components/toolbar/toolbar.vue +1101 -1101
 - package/src/components/tooltip/props.ts +21 -21
 - package/src/components/tooltip/tooltip.less +23 -23
 - package/src/components/tooltip/tooltip.vue +37 -37
 - package/src/components/triangle/props.ts +26 -26
 - package/src/components/triangle/triangle.less +79 -79
 - package/src/components/triangle/triangle.vue +65 -65
 - package/src/core/function.ts +1144 -1144
 - package/src/core/rule.ts +259 -259
 - package/src/core/tool.ts +1137 -1137
 - package/src/css/base.less +30 -30
 - package/src/css/hljs.less +54 -54
 - package/src/editify/editify.less +404 -403
 - package/src/editify/editify.vue +803 -792
 - package/src/editify/props.ts +156 -146
 - package/src/hljs/index.ts +197 -197
 - package/src/icon/iconfont.css +219 -219
 - package/src/index.ts +32 -32
 - package/src/locale/en_US.ts +88 -88
 - package/src/locale/index.ts +12 -12
 - package/src/locale/zh_CN.ts +88 -88
 - package/tsconfig.json +27 -27
 - package/tsconfig.node.json +11 -11
 - package/vite-env.d.ts +1 -1
 - package/vite.config.ts +42 -42
 
    
        package/src/core/rule.ts
    CHANGED
    
    | 
         @@ -1,259 +1,259 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import AlexEditor, { AlexElement } from 'alex-editor'
         
     | 
| 
       2 
     | 
    
         
            -
            import { LanguagesItemType, getHljsHtml } from '../hljs'
         
     | 
| 
       3 
     | 
    
         
            -
            import { getColNumbers } from './tool'
         
     | 
| 
       4 
     | 
    
         
            -
            import { isList, isTask } from './function'
         
     | 
| 
       5 
     | 
    
         
            -
            import { common as DapCommon } from 'dap-util'
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
            //更新代码块内的光标位置
         
     | 
| 
       8 
     | 
    
         
            -
            const updateRangeInPre = (editor: AlexEditor, element: AlexElement, originalTextElements: AlexElement[], newElements: AlexElement[]) => {
         
     | 
| 
       9 
     | 
    
         
            -
            	if (!editor.range) {
         
     | 
| 
       10 
     | 
    
         
            -
            		return
         
     | 
| 
       11 
     | 
    
         
            -
            	}
         
     | 
| 
       12 
     | 
    
         
            -
            	//如果虚拟光标的起点在代码块内对虚拟光标的起点进行重新定位
         
     | 
| 
       13 
     | 
    
         
            -
            	if (editor.range.anchor.element.getBlock().isEqual(element)) {
         
     | 
| 
       14 
     | 
    
         
            -
            		//获取起点所在文本元素的在所有文本元素中的序列
         
     | 
| 
       15 
     | 
    
         
            -
            		const elIndex = originalTextElements.findIndex(el => editor.range!.anchor.element.isEqual(el))
         
     | 
| 
       16 
     | 
    
         
            -
            		//起点在整个代码内容中的位置
         
     | 
| 
       17 
     | 
    
         
            -
            		const offset = originalTextElements.filter((_el, i) => i < elIndex).reduce((total, item) => total + item.textContent!.length, 0) + editor.range.anchor.offset
         
     | 
| 
       18 
     | 
    
         
            -
            		//获取pre下新的子孙元素中全部的文本元素
         
     | 
| 
       19 
     | 
    
         
            -
            		const newTextElements = AlexElement.flatElements(newElements).filter(el => el.isText() && !el.isEmpty())
         
     | 
| 
       20 
     | 
    
         
            -
            		let i = 0
         
     | 
| 
       21 
     | 
    
         
            -
            		let index = 0
         
     | 
| 
       22 
     | 
    
         
            -
            		//遍历
         
     | 
| 
       23 
     | 
    
         
            -
            		while (i < newTextElements.length) {
         
     | 
| 
       24 
     | 
    
         
            -
            			let newIndex = index + newTextElements[i].textContent!.length
         
     | 
| 
       25 
     | 
    
         
            -
            			if (offset >= index && offset <= newIndex) {
         
     | 
| 
       26 
     | 
    
         
            -
            				editor.range.anchor.element = newTextElements[i]
         
     | 
| 
       27 
     | 
    
         
            -
            				editor.range.anchor.offset = offset - index
         
     | 
| 
       28 
     | 
    
         
            -
            				break
         
     | 
| 
       29 
     | 
    
         
            -
            			}
         
     | 
| 
       30 
     | 
    
         
            -
            			i++
         
     | 
| 
       31 
     | 
    
         
            -
            			index = newIndex
         
     | 
| 
       32 
     | 
    
         
            -
            		}
         
     | 
| 
       33 
     | 
    
         
            -
            	}
         
     | 
| 
       34 
     | 
    
         
            -
            	//如果虚拟光标的终点在代码块内需要对虚拟光标的终点进行重新定位
         
     | 
| 
       35 
     | 
    
         
            -
            	if (editor.range.focus.element.getBlock().isEqual(element)) {
         
     | 
| 
       36 
     | 
    
         
            -
            		//获取终点所在文本元素的在所有文本元素中的序列
         
     | 
| 
       37 
     | 
    
         
            -
            		const elIndex = originalTextElements.findIndex(el => editor.range!.focus.element.isEqual(el))
         
     | 
| 
       38 
     | 
    
         
            -
            		//终点在整个代码内容中的位置
         
     | 
| 
       39 
     | 
    
         
            -
            		const offset = originalTextElements.filter((_el, i) => i < elIndex).reduce((total, item) => total + item.textContent!.length, 0) + editor.range.focus.offset
         
     | 
| 
       40 
     | 
    
         
            -
            		//获取全部的新文本元素
         
     | 
| 
       41 
     | 
    
         
            -
            		const newTextElements = AlexElement.flatElements(newElements).filter(el => el.isText() && !el.isEmpty())
         
     | 
| 
       42 
     | 
    
         
            -
            		let i = 0
         
     | 
| 
       43 
     | 
    
         
            -
            		let index = 0
         
     | 
| 
       44 
     | 
    
         
            -
            		//遍历
         
     | 
| 
       45 
     | 
    
         
            -
            		while (i < newTextElements.length) {
         
     | 
| 
       46 
     | 
    
         
            -
            			let newIndex = index + newTextElements[i].textContent!.length
         
     | 
| 
       47 
     | 
    
         
            -
            			if (offset >= index && offset <= newIndex) {
         
     | 
| 
       48 
     | 
    
         
            -
            				editor.range.focus.element = newTextElements[i]
         
     | 
| 
       49 
     | 
    
         
            -
            				editor.range.focus.offset = offset - index
         
     | 
| 
       50 
     | 
    
         
            -
            				break
         
     | 
| 
       51 
     | 
    
         
            -
            			}
         
     | 
| 
       52 
     | 
    
         
            -
            			i++
         
     | 
| 
       53 
     | 
    
         
            -
            			index = newIndex
         
     | 
| 
       54 
     | 
    
         
            -
            		}
         
     | 
| 
       55 
     | 
    
         
            -
            	}
         
     | 
| 
       56 
     | 
    
         
            -
            }
         
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
            //元素格式化时转换ol和li标签
         
     | 
| 
       59 
     | 
    
         
            -
            export const parseList = (editor: AlexEditor, element: AlexElement) => {
         
     | 
| 
       60 
     | 
    
         
            -
            	//ol标签和ul标签转为div
         
     | 
| 
       61 
     | 
    
         
            -
            	if (element.parsedom == 'ol' || element.parsedom == 'ul') {
         
     | 
| 
       62 
     | 
    
         
            -
            		if (element.hasChildren()) {
         
     | 
| 
       63 
     | 
    
         
            -
            			element.children!.forEach(el => {
         
     | 
| 
       64 
     | 
    
         
            -
            				const newEl = el.clone()
         
     | 
| 
       65 
     | 
    
         
            -
            				newEl.parsedom = 'div'
         
     | 
| 
       66 
     | 
    
         
            -
            				newEl.type = element.type
         
     | 
| 
       67 
     | 
    
         
            -
            				if (!newEl.hasMarks()) {
         
     | 
| 
       68 
     | 
    
         
            -
            					newEl.marks = {}
         
     | 
| 
       69 
     | 
    
         
            -
            				}
         
     | 
| 
       70 
     | 
    
         
            -
            				newEl.marks!['data-editify-list'] = element.parsedom
         
     | 
| 
       71 
     | 
    
         
            -
            				//插入到该元素之前
         
     | 
| 
       72 
     | 
    
         
            -
            				editor.addElementBefore(newEl, element)
         
     | 
| 
       73 
     | 
    
         
            -
            			})
         
     | 
| 
       74 
     | 
    
         
            -
            		}
         
     | 
| 
       75 
     | 
    
         
            -
            		element.toEmpty()
         
     | 
| 
       76 
     | 
    
         
            -
            	}
         
     | 
| 
       77 
     | 
    
         
            -
            }
         
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
            //元素格式化时处理有序列表的序号值
         
     | 
| 
       80 
     | 
    
         
            -
            export const orderdListHandle = function (editor: AlexEditor, element: AlexElement) {
         
     | 
| 
       81 
     | 
    
         
            -
            	//有序列表的序号处理
         
     | 
| 
       82 
     | 
    
         
            -
            	if (isList(element, true)) {
         
     | 
| 
       83 
     | 
    
         
            -
            		//获取前一个元素
         
     | 
| 
       84 
     | 
    
         
            -
            		const previousElement = editor.getPreviousElement(element)
         
     | 
| 
       85 
     | 
    
         
            -
            		//如果前一个元素存在并且也是有序列表
         
     | 
| 
       86 
     | 
    
         
            -
            		if (previousElement && isList(previousElement, true)) {
         
     | 
| 
       87 
     | 
    
         
            -
            			const previousValue = Number(previousElement.marks!['data-editify-value'])
         
     | 
| 
       88 
     | 
    
         
            -
            			element.marks!['data-editify-value'] = previousValue + 1
         
     | 
| 
       89 
     | 
    
         
            -
            		}
         
     | 
| 
       90 
     | 
    
         
            -
            		//前一个元素不是有序列表,则从0开始
         
     | 
| 
       91 
     | 
    
         
            -
            		else {
         
     | 
| 
       92 
     | 
    
         
            -
            			element.marks!['data-editify-value'] = 1
         
     | 
| 
       93 
     | 
    
         
            -
            		}
         
     | 
| 
       94 
     | 
    
         
            -
            	}
         
     | 
| 
       95 
     | 
    
         
            -
            }
         
     | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
            //元素格式化时处理媒体元素和链接
         
     | 
| 
       98 
     | 
    
         
            -
            export const mediaHandle = function (editor: AlexEditor, element: AlexElement) {
         
     | 
| 
       99 
     | 
    
         
            -
            	//图片、视频和链接设置marks
         
     | 
| 
       100 
     | 
    
         
            -
            	if (element.parsedom == 'img' || element.parsedom == 'video' || element.parsedom == 'a') {
         
     | 
| 
       101 
     | 
    
         
            -
            		const marks = {
         
     | 
| 
       102 
     | 
    
         
            -
            			'data-editify-element': element.key
         
     | 
| 
       103 
     | 
    
         
            -
            		}
         
     | 
| 
       104 
     | 
    
         
            -
            		if (element.hasMarks()) {
         
     | 
| 
       105 
     | 
    
         
            -
            			Object.assign(element.marks!, marks)
         
     | 
| 
       106 
     | 
    
         
            -
            		} else {
         
     | 
| 
       107 
     | 
    
         
            -
            			element.marks = marks
         
     | 
| 
       108 
     | 
    
         
            -
            		}
         
     | 
| 
       109 
     | 
    
         
            -
            	}
         
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
            	//视频的特殊处理,两侧无元素时在两侧加上空白文本
         
     | 
| 
       112 
     | 
    
         
            -
            	if (element.parsedom == 'video') {
         
     | 
| 
       113 
     | 
    
         
            -
            		const previousElement = editor.getPreviousElement(element)
         
     | 
| 
       114 
     | 
    
         
            -
            		const newTextElement = editor.getNextElement(element)
         
     | 
| 
       115 
     | 
    
         
            -
            		//如果不存在前一个元素
         
     | 
| 
       116 
     | 
    
         
            -
            		if (!previousElement || previousElement.isEmpty()) {
         
     | 
| 
       117 
     | 
    
         
            -
            			const spaceText = AlexElement.getSpaceElement()
         
     | 
| 
       118 
     | 
    
         
            -
            			editor.addElementBefore(spaceText, element)
         
     | 
| 
       119 
     | 
    
         
            -
            		}
         
     | 
| 
       120 
     | 
    
         
            -
            		//如果不存在后一个元素
         
     | 
| 
       121 
     | 
    
         
            -
            		if (!newTextElement || newTextElement.isEmpty()) {
         
     | 
| 
       122 
     | 
    
         
            -
            			const spaceText = AlexElement.getSpaceElement()
         
     | 
| 
       123 
     | 
    
         
            -
            			editor.addElementAfter(spaceText, element)
         
     | 
| 
       124 
     | 
    
         
            -
            		}
         
     | 
| 
       125 
     | 
    
         
            -
            	}
         
     | 
| 
       126 
     | 
    
         
            -
            }
         
     | 
| 
       127 
     | 
    
         
            -
             
     | 
| 
       128 
     | 
    
         
            -
            //元素格式化时处理表格
         
     | 
| 
       129 
     | 
    
         
            -
            export const tableHandle = function (editor: AlexEditor, element: AlexElement) {
         
     | 
| 
       130 
     | 
    
         
            -
            	if (element.parsedom == 'table') {
         
     | 
| 
       131 
     | 
    
         
            -
            		const marks = {
         
     | 
| 
       132 
     | 
    
         
            -
            			'data-editify-element': element.key
         
     | 
| 
       133 
     | 
    
         
            -
            		}
         
     | 
| 
       134 
     | 
    
         
            -
            		if (element.hasMarks()) {
         
     | 
| 
       135 
     | 
    
         
            -
            			Object.assign(element.marks!, marks)
         
     | 
| 
       136 
     | 
    
         
            -
            		} else {
         
     | 
| 
       137 
     | 
    
         
            -
            			element.marks = marks
         
     | 
| 
       138 
     | 
    
         
            -
            		}
         
     | 
| 
       139 
     | 
    
         
            -
            		const styles = {
         
     | 
| 
       140 
     | 
    
         
            -
            			'white-space': 'pre-wrap',
         
     | 
| 
       141 
     | 
    
         
            -
            			'word-break': 'break-word'
         
     | 
| 
       142 
     | 
    
         
            -
            		}
         
     | 
| 
       143 
     | 
    
         
            -
            		if (element.hasStyles()) {
         
     | 
| 
       144 
     | 
    
         
            -
            			Object.assign(element.styles!, styles)
         
     | 
| 
       145 
     | 
    
         
            -
            		} else {
         
     | 
| 
       146 
     | 
    
         
            -
            			element.styles = styles
         
     | 
| 
       147 
     | 
    
         
            -
            		}
         
     | 
| 
       148 
     | 
    
         
            -
            		const elements = AlexElement.flatElements(element.children!)
         
     | 
| 
       149 
     | 
    
         
            -
            		const rows = elements.filter(el => {
         
     | 
| 
       150 
     | 
    
         
            -
            			return el.parsedom == 'tr'
         
     | 
| 
       151 
     | 
    
         
            -
            		})
         
     | 
| 
       152 
     | 
    
         
            -
            		let colgroup = elements.find(el => {
         
     | 
| 
       153 
     | 
    
         
            -
            			return el.parsedom == 'colgroup'
         
     | 
| 
       154 
     | 
    
         
            -
            		})
         
     | 
| 
       155 
     | 
    
         
            -
            		if (colgroup) {
         
     | 
| 
       156 
     | 
    
         
            -
            			colgroup.children!.forEach(col => {
         
     | 
| 
       157 
     | 
    
         
            -
            				if (!col.hasMarks()) {
         
     | 
| 
       158 
     | 
    
         
            -
            					col.marks = {
         
     | 
| 
       159 
     | 
    
         
            -
            						width: 'auto'
         
     | 
| 
       160 
     | 
    
         
            -
            					}
         
     | 
| 
       161 
     | 
    
         
            -
            				} else if (!col.marks!['width']) {
         
     | 
| 
       162 
     | 
    
         
            -
            					col.marks!['width'] = 'auto'
         
     | 
| 
       163 
     | 
    
         
            -
            				}
         
     | 
| 
       164 
     | 
    
         
            -
            			})
         
     | 
| 
       165 
     | 
    
         
            -
            		} else {
         
     | 
| 
       166 
     | 
    
         
            -
            			colgroup = new AlexElement('inblock', 'colgroup', null, null, null)
         
     | 
| 
       167 
     | 
    
         
            -
            			const colNumber = getColNumbers(rows[0])
         
     | 
| 
       168 
     | 
    
         
            -
            			for (let i = colNumber - 1; i >= 0; i--) {
         
     | 
| 
       169 
     | 
    
         
            -
            				const col = new AlexElement(
         
     | 
| 
       170 
     | 
    
         
            -
            					'closed',
         
     | 
| 
       171 
     | 
    
         
            -
            					'col',
         
     | 
| 
       172 
     | 
    
         
            -
            					{
         
     | 
| 
       173 
     | 
    
         
            -
            						width: 'auto'
         
     | 
| 
       174 
     | 
    
         
            -
            					},
         
     | 
| 
       175 
     | 
    
         
            -
            					null,
         
     | 
| 
       176 
     | 
    
         
            -
            					null
         
     | 
| 
       177 
     | 
    
         
            -
            				)
         
     | 
| 
       178 
     | 
    
         
            -
            				editor.addElementTo(col, colgroup)
         
     | 
| 
       179 
     | 
    
         
            -
            			}
         
     | 
| 
       180 
     | 
    
         
            -
            		}
         
     | 
| 
       181 
     | 
    
         
            -
            		element.children = []
         
     | 
| 
       182 
     | 
    
         
            -
            		const tbody = new AlexElement('inblock', 'tbody', null, null, null)
         
     | 
| 
       183 
     | 
    
         
            -
            		rows.reverse().forEach(row => {
         
     | 
| 
       184 
     | 
    
         
            -
            			editor.addElementTo(row, tbody)
         
     | 
| 
       185 
     | 
    
         
            -
            		})
         
     | 
| 
       186 
     | 
    
         
            -
            		editor.addElementTo(tbody, element)
         
     | 
| 
       187 
     | 
    
         
            -
            		editor.addElementTo(colgroup, element)
         
     | 
| 
       188 
     | 
    
         
            -
            	}
         
     | 
| 
       189 
     | 
    
         
            -
            	if (element.parsedom == 'th') {
         
     | 
| 
       190 
     | 
    
         
            -
            		element.parsedom = 'td'
         
     | 
| 
       191 
     | 
    
         
            -
            	}
         
     | 
| 
       192 
     | 
    
         
            -
            }
         
     | 
| 
       193 
     | 
    
         
            -
             
     | 
| 
       194 
     | 
    
         
            -
            //元素格式化时处理pre,将pre的内容根据语言进行样式处理
         
     | 
| 
       195 
     | 
    
         
            -
            export const preHandle = function (editor: AlexEditor, element: AlexElement, highlight: boolean, languages: (string | LanguagesItemType)[]) {
         
     | 
| 
       196 
     | 
    
         
            -
            	//如果是代码块进行处理
         
     | 
| 
       197 
     | 
    
         
            -
            	if (element.parsedom == 'pre') {
         
     | 
| 
       198 
     | 
    
         
            -
            		const marks = {
         
     | 
| 
       199 
     | 
    
         
            -
            			'data-editify-element': element.key
         
     | 
| 
       200 
     | 
    
         
            -
            		}
         
     | 
| 
       201 
     | 
    
         
            -
            		if (element.hasMarks()) {
         
     | 
| 
       202 
     | 
    
         
            -
            			Object.assign(element.marks!, marks)
         
     | 
| 
       203 
     | 
    
         
            -
            		} else {
         
     | 
| 
       204 
     | 
    
         
            -
            			element.marks = marks
         
     | 
| 
       205 
     | 
    
         
            -
            		}
         
     | 
| 
       206 
     | 
    
         
            -
            		//高亮处理
         
     | 
| 
       207 
     | 
    
         
            -
            		if (highlight && element.hasChildren()) {
         
     | 
| 
       208 
     | 
    
         
            -
            			//获取语言类型
         
     | 
| 
       209 
     | 
    
         
            -
            			let language: string = element.marks!['data-editify-hljs'] || ''
         
     | 
| 
       210 
     | 
    
         
            -
            			if (language && languages) {
         
     | 
| 
       211 
     | 
    
         
            -
            				//语言类型是否是列表内的
         
     | 
| 
       212 
     | 
    
         
            -
            				const flag = languages.some(item => {
         
     | 
| 
       213 
     | 
    
         
            -
            					if (DapCommon.isObject(item)) {
         
     | 
| 
       214 
     | 
    
         
            -
            						return (<LanguagesItemType>item).value == language
         
     | 
| 
       215 
     | 
    
         
            -
            					}
         
     | 
| 
       216 
     | 
    
         
            -
            					return <string>item == language
         
     | 
| 
       217 
     | 
    
         
            -
            				})
         
     | 
| 
       218 
     | 
    
         
            -
            				//如果不是列表内的则清除
         
     | 
| 
       219 
     | 
    
         
            -
            				if (!flag) {
         
     | 
| 
       220 
     | 
    
         
            -
            					language = ''
         
     | 
| 
       221 
     | 
    
         
            -
            				}
         
     | 
| 
       222 
     | 
    
         
            -
            			}
         
     | 
| 
       223 
     | 
    
         
            -
            			//获取pre标签下所有的文本元素
         
     | 
| 
       224 
     | 
    
         
            -
            			const originalTextElements = AlexElement.flatElements(element.children!).filter(el => el.isText() && !el.isEmpty())
         
     | 
| 
       225 
     | 
    
         
            -
            			//获取pre下的代码文本值
         
     | 
| 
       226 
     | 
    
         
            -
            			const textContent = originalTextElements.reduce((val, item) => {
         
     | 
| 
       227 
     | 
    
         
            -
            				return val + item.textContent
         
     | 
| 
       228 
     | 
    
         
            -
            			}, '')
         
     | 
| 
       229 
     | 
    
         
            -
            			//将文本元素的内容转为经过hljs处理的内容
         
     | 
| 
       230 
     | 
    
         
            -
            			const html = getHljsHtml(textContent, language)
         
     | 
| 
       231 
     | 
    
         
            -
            			if (html) {
         
     | 
| 
       232 
     | 
    
         
            -
            				//将经过hljs处理的内容转为元素数组
         
     | 
| 
       233 
     | 
    
         
            -
            				const newElements = editor.parseHtml(html)
         
     | 
| 
       234 
     | 
    
         
            -
            				//将新文本元素全部加入到pre子元素数组中
         
     | 
| 
       235 
     | 
    
         
            -
            				element.children = newElements
         
     | 
| 
       236 
     | 
    
         
            -
            				newElements.forEach(newEl => {
         
     | 
| 
       237 
     | 
    
         
            -
            					newEl.parent = element
         
     | 
| 
       238 
     | 
    
         
            -
            				})
         
     | 
| 
       239 
     | 
    
         
            -
            				//处理光标位置
         
     | 
| 
       240 
     | 
    
         
            -
            				updateRangeInPre(editor, element, originalTextElements, newElements)
         
     | 
| 
       241 
     | 
    
         
            -
            			}
         
     | 
| 
       242 
     | 
    
         
            -
            		}
         
     | 
| 
       243 
     | 
    
         
            -
            	}
         
     | 
| 
       244 
     | 
    
         
            -
            }
         
     | 
| 
       245 
     | 
    
         
            -
             
     | 
| 
       246 
     | 
    
         
            -
            //元素格式化时处理一些特殊的内部块元素,转为根级块元素
         
     | 
| 
       247 
     | 
    
         
            -
            export const specialInblockHandle = function (editor: AlexEditor, element: AlexElement) {
         
     | 
| 
       248 
     | 
    
         
            -
            	if (element.hasChildren()) {
         
     | 
| 
       249 
     | 
    
         
            -
            		element.children!.forEach(el => {
         
     | 
| 
       250 
     | 
    
         
            -
            			if (isList(el, true) || isList(el, false) || isTask(el) || ['blockquote', 'pre', 'table', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p'].includes(el.parsedom!)) {
         
     | 
| 
       251 
     | 
    
         
            -
            				const newEl = el.clone()
         
     | 
| 
       252 
     | 
    
         
            -
            				newEl.type = 'block'
         
     | 
| 
       253 
     | 
    
         
            -
            				const block = element.getBlock()
         
     | 
| 
       254 
     | 
    
         
            -
            				editor.addElementAfter(newEl, block)
         
     | 
| 
       255 
     | 
    
         
            -
            				el.toEmpty()
         
     | 
| 
       256 
     | 
    
         
            -
            			}
         
     | 
| 
       257 
     | 
    
         
            -
            		})
         
     | 
| 
       258 
     | 
    
         
            -
            	}
         
     | 
| 
       259 
     | 
    
         
            -
            }
         
     | 
| 
      
 1 
     | 
    
         
            +
            import AlexEditor, { AlexElement } from 'alex-editor'
         
     | 
| 
      
 2 
     | 
    
         
            +
            import { LanguagesItemType, getHljsHtml } from '../hljs'
         
     | 
| 
      
 3 
     | 
    
         
            +
            import { getColNumbers } from './tool'
         
     | 
| 
      
 4 
     | 
    
         
            +
            import { isList, isTask } from './function'
         
     | 
| 
      
 5 
     | 
    
         
            +
            import { common as DapCommon } from 'dap-util'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            //更新代码块内的光标位置
         
     | 
| 
      
 8 
     | 
    
         
            +
            const updateRangeInPre = (editor: AlexEditor, element: AlexElement, originalTextElements: AlexElement[], newElements: AlexElement[]) => {
         
     | 
| 
      
 9 
     | 
    
         
            +
            	if (!editor.range) {
         
     | 
| 
      
 10 
     | 
    
         
            +
            		return
         
     | 
| 
      
 11 
     | 
    
         
            +
            	}
         
     | 
| 
      
 12 
     | 
    
         
            +
            	//如果虚拟光标的起点在代码块内对虚拟光标的起点进行重新定位
         
     | 
| 
      
 13 
     | 
    
         
            +
            	if (editor.range.anchor.element.getBlock().isEqual(element)) {
         
     | 
| 
      
 14 
     | 
    
         
            +
            		//获取起点所在文本元素的在所有文本元素中的序列
         
     | 
| 
      
 15 
     | 
    
         
            +
            		const elIndex = originalTextElements.findIndex(el => editor.range!.anchor.element.isEqual(el))
         
     | 
| 
      
 16 
     | 
    
         
            +
            		//起点在整个代码内容中的位置
         
     | 
| 
      
 17 
     | 
    
         
            +
            		const offset = originalTextElements.filter((_el, i) => i < elIndex).reduce((total, item) => total + item.textContent!.length, 0) + editor.range.anchor.offset
         
     | 
| 
      
 18 
     | 
    
         
            +
            		//获取pre下新的子孙元素中全部的文本元素
         
     | 
| 
      
 19 
     | 
    
         
            +
            		const newTextElements = AlexElement.flatElements(newElements).filter(el => el.isText() && !el.isEmpty())
         
     | 
| 
      
 20 
     | 
    
         
            +
            		let i = 0
         
     | 
| 
      
 21 
     | 
    
         
            +
            		let index = 0
         
     | 
| 
      
 22 
     | 
    
         
            +
            		//遍历
         
     | 
| 
      
 23 
     | 
    
         
            +
            		while (i < newTextElements.length) {
         
     | 
| 
      
 24 
     | 
    
         
            +
            			let newIndex = index + newTextElements[i].textContent!.length
         
     | 
| 
      
 25 
     | 
    
         
            +
            			if (offset >= index && offset <= newIndex) {
         
     | 
| 
      
 26 
     | 
    
         
            +
            				editor.range.anchor.element = newTextElements[i]
         
     | 
| 
      
 27 
     | 
    
         
            +
            				editor.range.anchor.offset = offset - index
         
     | 
| 
      
 28 
     | 
    
         
            +
            				break
         
     | 
| 
      
 29 
     | 
    
         
            +
            			}
         
     | 
| 
      
 30 
     | 
    
         
            +
            			i++
         
     | 
| 
      
 31 
     | 
    
         
            +
            			index = newIndex
         
     | 
| 
      
 32 
     | 
    
         
            +
            		}
         
     | 
| 
      
 33 
     | 
    
         
            +
            	}
         
     | 
| 
      
 34 
     | 
    
         
            +
            	//如果虚拟光标的终点在代码块内需要对虚拟光标的终点进行重新定位
         
     | 
| 
      
 35 
     | 
    
         
            +
            	if (editor.range.focus.element.getBlock().isEqual(element)) {
         
     | 
| 
      
 36 
     | 
    
         
            +
            		//获取终点所在文本元素的在所有文本元素中的序列
         
     | 
| 
      
 37 
     | 
    
         
            +
            		const elIndex = originalTextElements.findIndex(el => editor.range!.focus.element.isEqual(el))
         
     | 
| 
      
 38 
     | 
    
         
            +
            		//终点在整个代码内容中的位置
         
     | 
| 
      
 39 
     | 
    
         
            +
            		const offset = originalTextElements.filter((_el, i) => i < elIndex).reduce((total, item) => total + item.textContent!.length, 0) + editor.range.focus.offset
         
     | 
| 
      
 40 
     | 
    
         
            +
            		//获取全部的新文本元素
         
     | 
| 
      
 41 
     | 
    
         
            +
            		const newTextElements = AlexElement.flatElements(newElements).filter(el => el.isText() && !el.isEmpty())
         
     | 
| 
      
 42 
     | 
    
         
            +
            		let i = 0
         
     | 
| 
      
 43 
     | 
    
         
            +
            		let index = 0
         
     | 
| 
      
 44 
     | 
    
         
            +
            		//遍历
         
     | 
| 
      
 45 
     | 
    
         
            +
            		while (i < newTextElements.length) {
         
     | 
| 
      
 46 
     | 
    
         
            +
            			let newIndex = index + newTextElements[i].textContent!.length
         
     | 
| 
      
 47 
     | 
    
         
            +
            			if (offset >= index && offset <= newIndex) {
         
     | 
| 
      
 48 
     | 
    
         
            +
            				editor.range.focus.element = newTextElements[i]
         
     | 
| 
      
 49 
     | 
    
         
            +
            				editor.range.focus.offset = offset - index
         
     | 
| 
      
 50 
     | 
    
         
            +
            				break
         
     | 
| 
      
 51 
     | 
    
         
            +
            			}
         
     | 
| 
      
 52 
     | 
    
         
            +
            			i++
         
     | 
| 
      
 53 
     | 
    
         
            +
            			index = newIndex
         
     | 
| 
      
 54 
     | 
    
         
            +
            		}
         
     | 
| 
      
 55 
     | 
    
         
            +
            	}
         
     | 
| 
      
 56 
     | 
    
         
            +
            }
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
            //元素格式化时转换ol和li标签
         
     | 
| 
      
 59 
     | 
    
         
            +
            export const parseList = (editor: AlexEditor, element: AlexElement) => {
         
     | 
| 
      
 60 
     | 
    
         
            +
            	//ol标签和ul标签转为div
         
     | 
| 
      
 61 
     | 
    
         
            +
            	if (element.parsedom == 'ol' || element.parsedom == 'ul') {
         
     | 
| 
      
 62 
     | 
    
         
            +
            		if (element.hasChildren()) {
         
     | 
| 
      
 63 
     | 
    
         
            +
            			element.children!.forEach(el => {
         
     | 
| 
      
 64 
     | 
    
         
            +
            				const newEl = el.clone()
         
     | 
| 
      
 65 
     | 
    
         
            +
            				newEl.parsedom = 'div'
         
     | 
| 
      
 66 
     | 
    
         
            +
            				newEl.type = element.type
         
     | 
| 
      
 67 
     | 
    
         
            +
            				if (!newEl.hasMarks()) {
         
     | 
| 
      
 68 
     | 
    
         
            +
            					newEl.marks = {}
         
     | 
| 
      
 69 
     | 
    
         
            +
            				}
         
     | 
| 
      
 70 
     | 
    
         
            +
            				newEl.marks!['data-editify-list'] = element.parsedom
         
     | 
| 
      
 71 
     | 
    
         
            +
            				//插入到该元素之前
         
     | 
| 
      
 72 
     | 
    
         
            +
            				editor.addElementBefore(newEl, element)
         
     | 
| 
      
 73 
     | 
    
         
            +
            			})
         
     | 
| 
      
 74 
     | 
    
         
            +
            		}
         
     | 
| 
      
 75 
     | 
    
         
            +
            		element.toEmpty()
         
     | 
| 
      
 76 
     | 
    
         
            +
            	}
         
     | 
| 
      
 77 
     | 
    
         
            +
            }
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
            //元素格式化时处理有序列表的序号值
         
     | 
| 
      
 80 
     | 
    
         
            +
            export const orderdListHandle = function (editor: AlexEditor, element: AlexElement) {
         
     | 
| 
      
 81 
     | 
    
         
            +
            	//有序列表的序号处理
         
     | 
| 
      
 82 
     | 
    
         
            +
            	if (isList(element, true)) {
         
     | 
| 
      
 83 
     | 
    
         
            +
            		//获取前一个元素
         
     | 
| 
      
 84 
     | 
    
         
            +
            		const previousElement = editor.getPreviousElement(element)
         
     | 
| 
      
 85 
     | 
    
         
            +
            		//如果前一个元素存在并且也是有序列表
         
     | 
| 
      
 86 
     | 
    
         
            +
            		if (previousElement && isList(previousElement, true)) {
         
     | 
| 
      
 87 
     | 
    
         
            +
            			const previousValue = Number(previousElement.marks!['data-editify-value'])
         
     | 
| 
      
 88 
     | 
    
         
            +
            			element.marks!['data-editify-value'] = previousValue + 1
         
     | 
| 
      
 89 
     | 
    
         
            +
            		}
         
     | 
| 
      
 90 
     | 
    
         
            +
            		//前一个元素不是有序列表,则从0开始
         
     | 
| 
      
 91 
     | 
    
         
            +
            		else {
         
     | 
| 
      
 92 
     | 
    
         
            +
            			element.marks!['data-editify-value'] = 1
         
     | 
| 
      
 93 
     | 
    
         
            +
            		}
         
     | 
| 
      
 94 
     | 
    
         
            +
            	}
         
     | 
| 
      
 95 
     | 
    
         
            +
            }
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
            //元素格式化时处理媒体元素和链接
         
     | 
| 
      
 98 
     | 
    
         
            +
            export const mediaHandle = function (editor: AlexEditor, element: AlexElement) {
         
     | 
| 
      
 99 
     | 
    
         
            +
            	//图片、视频和链接设置marks
         
     | 
| 
      
 100 
     | 
    
         
            +
            	if (element.parsedom == 'img' || element.parsedom == 'video' || element.parsedom == 'a') {
         
     | 
| 
      
 101 
     | 
    
         
            +
            		const marks = {
         
     | 
| 
      
 102 
     | 
    
         
            +
            			'data-editify-element': element.key
         
     | 
| 
      
 103 
     | 
    
         
            +
            		}
         
     | 
| 
      
 104 
     | 
    
         
            +
            		if (element.hasMarks()) {
         
     | 
| 
      
 105 
     | 
    
         
            +
            			Object.assign(element.marks!, marks)
         
     | 
| 
      
 106 
     | 
    
         
            +
            		} else {
         
     | 
| 
      
 107 
     | 
    
         
            +
            			element.marks = marks
         
     | 
| 
      
 108 
     | 
    
         
            +
            		}
         
     | 
| 
      
 109 
     | 
    
         
            +
            	}
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
            	//视频的特殊处理,两侧无元素时在两侧加上空白文本
         
     | 
| 
      
 112 
     | 
    
         
            +
            	if (element.parsedom == 'video') {
         
     | 
| 
      
 113 
     | 
    
         
            +
            		const previousElement = editor.getPreviousElement(element)
         
     | 
| 
      
 114 
     | 
    
         
            +
            		const newTextElement = editor.getNextElement(element)
         
     | 
| 
      
 115 
     | 
    
         
            +
            		//如果不存在前一个元素
         
     | 
| 
      
 116 
     | 
    
         
            +
            		if (!previousElement || previousElement.isEmpty()) {
         
     | 
| 
      
 117 
     | 
    
         
            +
            			const spaceText = AlexElement.getSpaceElement()
         
     | 
| 
      
 118 
     | 
    
         
            +
            			editor.addElementBefore(spaceText, element)
         
     | 
| 
      
 119 
     | 
    
         
            +
            		}
         
     | 
| 
      
 120 
     | 
    
         
            +
            		//如果不存在后一个元素
         
     | 
| 
      
 121 
     | 
    
         
            +
            		if (!newTextElement || newTextElement.isEmpty()) {
         
     | 
| 
      
 122 
     | 
    
         
            +
            			const spaceText = AlexElement.getSpaceElement()
         
     | 
| 
      
 123 
     | 
    
         
            +
            			editor.addElementAfter(spaceText, element)
         
     | 
| 
      
 124 
     | 
    
         
            +
            		}
         
     | 
| 
      
 125 
     | 
    
         
            +
            	}
         
     | 
| 
      
 126 
     | 
    
         
            +
            }
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
            //元素格式化时处理表格
         
     | 
| 
      
 129 
     | 
    
         
            +
            export const tableHandle = function (editor: AlexEditor, element: AlexElement) {
         
     | 
| 
      
 130 
     | 
    
         
            +
            	if (element.parsedom == 'table') {
         
     | 
| 
      
 131 
     | 
    
         
            +
            		const marks = {
         
     | 
| 
      
 132 
     | 
    
         
            +
            			'data-editify-element': element.key
         
     | 
| 
      
 133 
     | 
    
         
            +
            		}
         
     | 
| 
      
 134 
     | 
    
         
            +
            		if (element.hasMarks()) {
         
     | 
| 
      
 135 
     | 
    
         
            +
            			Object.assign(element.marks!, marks)
         
     | 
| 
      
 136 
     | 
    
         
            +
            		} else {
         
     | 
| 
      
 137 
     | 
    
         
            +
            			element.marks = marks
         
     | 
| 
      
 138 
     | 
    
         
            +
            		}
         
     | 
| 
      
 139 
     | 
    
         
            +
            		const styles = {
         
     | 
| 
      
 140 
     | 
    
         
            +
            			'white-space': 'pre-wrap',
         
     | 
| 
      
 141 
     | 
    
         
            +
            			'word-break': 'break-word'
         
     | 
| 
      
 142 
     | 
    
         
            +
            		}
         
     | 
| 
      
 143 
     | 
    
         
            +
            		if (element.hasStyles()) {
         
     | 
| 
      
 144 
     | 
    
         
            +
            			Object.assign(element.styles!, styles)
         
     | 
| 
      
 145 
     | 
    
         
            +
            		} else {
         
     | 
| 
      
 146 
     | 
    
         
            +
            			element.styles = styles
         
     | 
| 
      
 147 
     | 
    
         
            +
            		}
         
     | 
| 
      
 148 
     | 
    
         
            +
            		const elements = AlexElement.flatElements(element.children!)
         
     | 
| 
      
 149 
     | 
    
         
            +
            		const rows = elements.filter(el => {
         
     | 
| 
      
 150 
     | 
    
         
            +
            			return el.parsedom == 'tr'
         
     | 
| 
      
 151 
     | 
    
         
            +
            		})
         
     | 
| 
      
 152 
     | 
    
         
            +
            		let colgroup = elements.find(el => {
         
     | 
| 
      
 153 
     | 
    
         
            +
            			return el.parsedom == 'colgroup'
         
     | 
| 
      
 154 
     | 
    
         
            +
            		})
         
     | 
| 
      
 155 
     | 
    
         
            +
            		if (colgroup) {
         
     | 
| 
      
 156 
     | 
    
         
            +
            			colgroup.children!.forEach(col => {
         
     | 
| 
      
 157 
     | 
    
         
            +
            				if (!col.hasMarks()) {
         
     | 
| 
      
 158 
     | 
    
         
            +
            					col.marks = {
         
     | 
| 
      
 159 
     | 
    
         
            +
            						width: 'auto'
         
     | 
| 
      
 160 
     | 
    
         
            +
            					}
         
     | 
| 
      
 161 
     | 
    
         
            +
            				} else if (!col.marks!['width']) {
         
     | 
| 
      
 162 
     | 
    
         
            +
            					col.marks!['width'] = 'auto'
         
     | 
| 
      
 163 
     | 
    
         
            +
            				}
         
     | 
| 
      
 164 
     | 
    
         
            +
            			})
         
     | 
| 
      
 165 
     | 
    
         
            +
            		} else {
         
     | 
| 
      
 166 
     | 
    
         
            +
            			colgroup = new AlexElement('inblock', 'colgroup', null, null, null)
         
     | 
| 
      
 167 
     | 
    
         
            +
            			const colNumber = getColNumbers(rows[0])
         
     | 
| 
      
 168 
     | 
    
         
            +
            			for (let i = colNumber - 1; i >= 0; i--) {
         
     | 
| 
      
 169 
     | 
    
         
            +
            				const col = new AlexElement(
         
     | 
| 
      
 170 
     | 
    
         
            +
            					'closed',
         
     | 
| 
      
 171 
     | 
    
         
            +
            					'col',
         
     | 
| 
      
 172 
     | 
    
         
            +
            					{
         
     | 
| 
      
 173 
     | 
    
         
            +
            						width: 'auto'
         
     | 
| 
      
 174 
     | 
    
         
            +
            					},
         
     | 
| 
      
 175 
     | 
    
         
            +
            					null,
         
     | 
| 
      
 176 
     | 
    
         
            +
            					null
         
     | 
| 
      
 177 
     | 
    
         
            +
            				)
         
     | 
| 
      
 178 
     | 
    
         
            +
            				editor.addElementTo(col, colgroup)
         
     | 
| 
      
 179 
     | 
    
         
            +
            			}
         
     | 
| 
      
 180 
     | 
    
         
            +
            		}
         
     | 
| 
      
 181 
     | 
    
         
            +
            		element.children = []
         
     | 
| 
      
 182 
     | 
    
         
            +
            		const tbody = new AlexElement('inblock', 'tbody', null, null, null)
         
     | 
| 
      
 183 
     | 
    
         
            +
            		rows.reverse().forEach(row => {
         
     | 
| 
      
 184 
     | 
    
         
            +
            			editor.addElementTo(row, tbody)
         
     | 
| 
      
 185 
     | 
    
         
            +
            		})
         
     | 
| 
      
 186 
     | 
    
         
            +
            		editor.addElementTo(tbody, element)
         
     | 
| 
      
 187 
     | 
    
         
            +
            		editor.addElementTo(colgroup, element)
         
     | 
| 
      
 188 
     | 
    
         
            +
            	}
         
     | 
| 
      
 189 
     | 
    
         
            +
            	if (element.parsedom == 'th') {
         
     | 
| 
      
 190 
     | 
    
         
            +
            		element.parsedom = 'td'
         
     | 
| 
      
 191 
     | 
    
         
            +
            	}
         
     | 
| 
      
 192 
     | 
    
         
            +
            }
         
     | 
| 
      
 193 
     | 
    
         
            +
             
     | 
| 
      
 194 
     | 
    
         
            +
            //元素格式化时处理pre,将pre的内容根据语言进行样式处理
         
     | 
| 
      
 195 
     | 
    
         
            +
            export const preHandle = function (editor: AlexEditor, element: AlexElement, highlight: boolean, languages: (string | LanguagesItemType)[]) {
         
     | 
| 
      
 196 
     | 
    
         
            +
            	//如果是代码块进行处理
         
     | 
| 
      
 197 
     | 
    
         
            +
            	if (element.parsedom == 'pre') {
         
     | 
| 
      
 198 
     | 
    
         
            +
            		const marks = {
         
     | 
| 
      
 199 
     | 
    
         
            +
            			'data-editify-element': element.key
         
     | 
| 
      
 200 
     | 
    
         
            +
            		}
         
     | 
| 
      
 201 
     | 
    
         
            +
            		if (element.hasMarks()) {
         
     | 
| 
      
 202 
     | 
    
         
            +
            			Object.assign(element.marks!, marks)
         
     | 
| 
      
 203 
     | 
    
         
            +
            		} else {
         
     | 
| 
      
 204 
     | 
    
         
            +
            			element.marks = marks
         
     | 
| 
      
 205 
     | 
    
         
            +
            		}
         
     | 
| 
      
 206 
     | 
    
         
            +
            		//高亮处理
         
     | 
| 
      
 207 
     | 
    
         
            +
            		if (highlight && element.hasChildren()) {
         
     | 
| 
      
 208 
     | 
    
         
            +
            			//获取语言类型
         
     | 
| 
      
 209 
     | 
    
         
            +
            			let language: string = element.marks!['data-editify-hljs'] || ''
         
     | 
| 
      
 210 
     | 
    
         
            +
            			if (language && languages) {
         
     | 
| 
      
 211 
     | 
    
         
            +
            				//语言类型是否是列表内的
         
     | 
| 
      
 212 
     | 
    
         
            +
            				const flag = languages.some(item => {
         
     | 
| 
      
 213 
     | 
    
         
            +
            					if (DapCommon.isObject(item)) {
         
     | 
| 
      
 214 
     | 
    
         
            +
            						return (<LanguagesItemType>item).value == language
         
     | 
| 
      
 215 
     | 
    
         
            +
            					}
         
     | 
| 
      
 216 
     | 
    
         
            +
            					return <string>item == language
         
     | 
| 
      
 217 
     | 
    
         
            +
            				})
         
     | 
| 
      
 218 
     | 
    
         
            +
            				//如果不是列表内的则清除
         
     | 
| 
      
 219 
     | 
    
         
            +
            				if (!flag) {
         
     | 
| 
      
 220 
     | 
    
         
            +
            					language = ''
         
     | 
| 
      
 221 
     | 
    
         
            +
            				}
         
     | 
| 
      
 222 
     | 
    
         
            +
            			}
         
     | 
| 
      
 223 
     | 
    
         
            +
            			//获取pre标签下所有的文本元素
         
     | 
| 
      
 224 
     | 
    
         
            +
            			const originalTextElements = AlexElement.flatElements(element.children!).filter(el => el.isText() && !el.isEmpty())
         
     | 
| 
      
 225 
     | 
    
         
            +
            			//获取pre下的代码文本值
         
     | 
| 
      
 226 
     | 
    
         
            +
            			const textContent = originalTextElements.reduce((val, item) => {
         
     | 
| 
      
 227 
     | 
    
         
            +
            				return val + item.textContent
         
     | 
| 
      
 228 
     | 
    
         
            +
            			}, '')
         
     | 
| 
      
 229 
     | 
    
         
            +
            			//将文本元素的内容转为经过hljs处理的内容
         
     | 
| 
      
 230 
     | 
    
         
            +
            			const html = getHljsHtml(textContent, language)
         
     | 
| 
      
 231 
     | 
    
         
            +
            			if (html) {
         
     | 
| 
      
 232 
     | 
    
         
            +
            				//将经过hljs处理的内容转为元素数组
         
     | 
| 
      
 233 
     | 
    
         
            +
            				const newElements = editor.parseHtml(html)
         
     | 
| 
      
 234 
     | 
    
         
            +
            				//将新文本元素全部加入到pre子元素数组中
         
     | 
| 
      
 235 
     | 
    
         
            +
            				element.children = newElements
         
     | 
| 
      
 236 
     | 
    
         
            +
            				newElements.forEach(newEl => {
         
     | 
| 
      
 237 
     | 
    
         
            +
            					newEl.parent = element
         
     | 
| 
      
 238 
     | 
    
         
            +
            				})
         
     | 
| 
      
 239 
     | 
    
         
            +
            				//处理光标位置
         
     | 
| 
      
 240 
     | 
    
         
            +
            				updateRangeInPre(editor, element, originalTextElements, newElements)
         
     | 
| 
      
 241 
     | 
    
         
            +
            			}
         
     | 
| 
      
 242 
     | 
    
         
            +
            		}
         
     | 
| 
      
 243 
     | 
    
         
            +
            	}
         
     | 
| 
      
 244 
     | 
    
         
            +
            }
         
     | 
| 
      
 245 
     | 
    
         
            +
             
     | 
| 
      
 246 
     | 
    
         
            +
            //元素格式化时处理一些特殊的内部块元素,转为根级块元素
         
     | 
| 
      
 247 
     | 
    
         
            +
            export const specialInblockHandle = function (editor: AlexEditor, element: AlexElement) {
         
     | 
| 
      
 248 
     | 
    
         
            +
            	if (element.hasChildren()) {
         
     | 
| 
      
 249 
     | 
    
         
            +
            		element.children!.forEach(el => {
         
     | 
| 
      
 250 
     | 
    
         
            +
            			if (isList(el, true) || isList(el, false) || isTask(el) || ['blockquote', 'pre', 'table', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p'].includes(el.parsedom!)) {
         
     | 
| 
      
 251 
     | 
    
         
            +
            				const newEl = el.clone()
         
     | 
| 
      
 252 
     | 
    
         
            +
            				newEl.type = 'block'
         
     | 
| 
      
 253 
     | 
    
         
            +
            				const block = element.getBlock()
         
     | 
| 
      
 254 
     | 
    
         
            +
            				editor.addElementAfter(newEl, block)
         
     | 
| 
      
 255 
     | 
    
         
            +
            				el.toEmpty()
         
     | 
| 
      
 256 
     | 
    
         
            +
            			}
         
     | 
| 
      
 257 
     | 
    
         
            +
            		})
         
     | 
| 
      
 258 
     | 
    
         
            +
            	}
         
     | 
| 
      
 259 
     | 
    
         
            +
            }
         
     |