@mnykj/wangeditoroptimize-code-highlight 1.0.0
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 -0
- package/dist/code-highlight/src/constants/svg.d.ts +10 -0
- package/dist/code-highlight/src/custom-types.d.ts +19 -0
- package/dist/code-highlight/src/decorate/index.d.ts +7 -0
- package/dist/code-highlight/src/index.d.ts +9 -0
- package/dist/code-highlight/src/locale/en.d.ts +10 -0
- package/dist/code-highlight/src/locale/index.d.ts +5 -0
- package/dist/code-highlight/src/locale/zh-CN.d.ts +10 -0
- package/dist/code-highlight/src/module/elem-to-html.d.ts +11 -0
- package/dist/code-highlight/src/module/index.d.ts +7 -0
- package/dist/code-highlight/src/module/menu/SelectLangMenu.d.ts +23 -0
- package/dist/code-highlight/src/module/menu/config.d.ts +8 -0
- package/dist/code-highlight/src/module/menu/index.d.ts +15 -0
- package/dist/code-highlight/src/module/parse-style-html.d.ts +8 -0
- package/dist/code-highlight/src/module/render-style.d.ts +13 -0
- package/dist/code-highlight/src/utils/dom.d.ts +15 -0
- package/dist/code-highlight/src/utils/vdom.d.ts +17 -0
- package/dist/code-highlight/src/vendor/prism.d.ts +36 -0
- package/dist/css/style.css +1 -0
- package/dist/index.esm.js +6447 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description icon svg
|
|
3
|
+
* @author wangfupeng
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 【注意】svg 字符串的长度 ,否则会导致代码体积过大
|
|
7
|
+
* 尽量选择 https://www.iconfont.cn/collections/detail?spm=a313x.7781069.0.da5a778a4&cid=20293
|
|
8
|
+
* 找不到再从 iconfont.com 搜索
|
|
9
|
+
*/
|
|
10
|
+
export declare const JS_SVG = "<svg viewBox=\"0 0 1024 1024\"><path d=\"M64 64v896h896V64H64z m487.6 698.8c0 87.2-51.2 127-125.8 127-67.4 0-106.4-34.8-126.4-77l68.6-41.4c13.2 23.4 25.2 43.2 54.2 43.2 27.6 0 45.2-10.8 45.2-53V475.4h84.2v287.4z m199.2 127c-78.2 0-128.8-37.2-153.4-86l68.6-39.6c18 29.4 41.6 51.2 83 51.2 34.8 0 57.2-17.4 57.2-41.6 0-28.8-22.8-39-61.4-56l-21-9c-60.8-25.8-101-58.4-101-127 0-63.2 48.2-111.2 123.2-111.2 53.6 0 92 18.6 119.6 67.4L800 580c-14.4-25.8-30-36-54.2-36-24.6 0-40.2 15.6-40.2 36 0 25.2 15.6 35.4 51.8 51.2l21 9c71.6 30.6 111.8 62 111.8 132.4 0 75.6-59.6 117.2-139.4 117.2z\"></path></svg>";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description 自定义 element
|
|
3
|
+
* @author wangfupeng
|
|
4
|
+
*/
|
|
5
|
+
declare type PureText = {
|
|
6
|
+
text: string;
|
|
7
|
+
};
|
|
8
|
+
export declare type PreElement = {
|
|
9
|
+
type: 'pre';
|
|
10
|
+
children: CodeElement[];
|
|
11
|
+
};
|
|
12
|
+
export declare type CodeElement = {
|
|
13
|
+
type: 'code';
|
|
14
|
+
language: string;
|
|
15
|
+
/** 代码块自动换行(HTML: data-word-wrap) */
|
|
16
|
+
wordWrap?: boolean;
|
|
17
|
+
children: PureText[];
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description code-highlight
|
|
3
|
+
* @author wangfupeng
|
|
4
|
+
*/
|
|
5
|
+
import './assets/index.less';
|
|
6
|
+
import './locale/index';
|
|
7
|
+
import wangEditorCodeHighlightModule from './module/index';
|
|
8
|
+
import wangEditorCodeHighLightDecorate from './decorate';
|
|
9
|
+
export { wangEditorCodeHighlightModule, wangEditorCodeHighLightDecorate };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description to html
|
|
3
|
+
* @author wangfupeng
|
|
4
|
+
*/
|
|
5
|
+
import { Element } from 'slate';
|
|
6
|
+
declare function codeToHtml(elem: Element, childrenHtml: string): string;
|
|
7
|
+
export declare const codeToHtmlConf: {
|
|
8
|
+
type: string;
|
|
9
|
+
elemToHtml: typeof codeToHtml;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description code-highlight select lang
|
|
3
|
+
* @author wangfupeng
|
|
4
|
+
*/
|
|
5
|
+
import { ISelectMenu, IDomEditor, IOption } from '@mnykj/wangeditoroptimize-core';
|
|
6
|
+
declare class SelectLangMenu implements ISelectMenu {
|
|
7
|
+
readonly title: string;
|
|
8
|
+
readonly iconSvg = "<svg viewBox=\"0 0 1024 1024\"><path d=\"M64 64v896h896V64H64z m487.6 698.8c0 87.2-51.2 127-125.8 127-67.4 0-106.4-34.8-126.4-77l68.6-41.4c13.2 23.4 25.2 43.2 54.2 43.2 27.6 0 45.2-10.8 45.2-53V475.4h84.2v287.4z m199.2 127c-78.2 0-128.8-37.2-153.4-86l68.6-39.6c18 29.4 41.6 51.2 83 51.2 34.8 0 57.2-17.4 57.2-41.6 0-28.8-22.8-39-61.4-56l-21-9c-60.8-25.8-101-58.4-101-127 0-63.2 48.2-111.2 123.2-111.2 53.6 0 92 18.6 119.6 67.4L800 580c-14.4-25.8-30-36-54.2-36-24.6 0-40.2 15.6-40.2 36 0 25.2 15.6 35.4 51.8 51.2l21 9c71.6 30.6 111.8 62 111.8 132.4 0 75.6-59.6 117.2-139.4 117.2z\"></path></svg>";
|
|
9
|
+
readonly tag = "select";
|
|
10
|
+
readonly width = 95;
|
|
11
|
+
readonly selectPanelWidth = 115;
|
|
12
|
+
getOptions(editor: IDomEditor): IOption[];
|
|
13
|
+
isActive(editor: IDomEditor): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* 获取语言类型
|
|
16
|
+
* @param editor editor
|
|
17
|
+
*/
|
|
18
|
+
getValue(editor: IDomEditor): string | boolean;
|
|
19
|
+
isDisabled(editor: IDomEditor): boolean;
|
|
20
|
+
exec(editor: IDomEditor, value: string | boolean): void;
|
|
21
|
+
private getSelectCodeElem;
|
|
22
|
+
}
|
|
23
|
+
export default SelectLangMenu;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description code-highlight menu
|
|
3
|
+
* @author wangfupeng
|
|
4
|
+
*/
|
|
5
|
+
import SelectLangMenu from './SelectLangMenu';
|
|
6
|
+
export declare const selectLangMenuConf: {
|
|
7
|
+
key: string;
|
|
8
|
+
factory(): SelectLangMenu;
|
|
9
|
+
config: {
|
|
10
|
+
codeLangs: {
|
|
11
|
+
text: string;
|
|
12
|
+
value: string;
|
|
13
|
+
}[];
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description parse style html
|
|
3
|
+
* @author wangfupeng
|
|
4
|
+
*/
|
|
5
|
+
import { DOMElement } from '../utils/dom';
|
|
6
|
+
import { Descendant } from 'slate';
|
|
7
|
+
import { IDomEditor } from '@mnykj/wangeditoroptimize-core';
|
|
8
|
+
export declare function parseCodeStyleHtml(elem: DOMElement, node: Descendant, editor: IDomEditor): Descendant;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description render code highlight style
|
|
3
|
+
* @author wangfupeng
|
|
4
|
+
*/
|
|
5
|
+
import { Descendant } from 'slate';
|
|
6
|
+
import { VNode } from 'snabbdom';
|
|
7
|
+
/**
|
|
8
|
+
* 添加样式
|
|
9
|
+
* @param node slate text
|
|
10
|
+
* @param vnode vnode
|
|
11
|
+
* @returns vnode
|
|
12
|
+
*/
|
|
13
|
+
export declare function renderStyle(node: Descendant, vnode: VNode): VNode;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description DOM 操作
|
|
3
|
+
* @author wangfupeng
|
|
4
|
+
*/
|
|
5
|
+
import $ from 'dom7';
|
|
6
|
+
export { Dom7Array } from 'dom7';
|
|
7
|
+
export default $;
|
|
8
|
+
import DOMNode = globalThis.Node;
|
|
9
|
+
import DOMComment = globalThis.Comment;
|
|
10
|
+
import DOMElement = globalThis.Element;
|
|
11
|
+
import DOMText = globalThis.Text;
|
|
12
|
+
import DOMRange = globalThis.Range;
|
|
13
|
+
import DOMSelection = globalThis.Selection;
|
|
14
|
+
import DOMStaticRange = globalThis.StaticRange;
|
|
15
|
+
export { DOMNode, DOMComment, DOMElement, DOMText, DOMRange, DOMSelection, DOMStaticRange };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description vdom utils fn
|
|
3
|
+
* @author wangfupeng
|
|
4
|
+
*/
|
|
5
|
+
import { VNode, VNodeStyle } from 'snabbdom';
|
|
6
|
+
/**
|
|
7
|
+
* 给 vnode 添加 className
|
|
8
|
+
* @param vnode vnode
|
|
9
|
+
* @param className css class
|
|
10
|
+
*/
|
|
11
|
+
export declare function addVnodeClassName(vnode: VNode, className: string): void;
|
|
12
|
+
/**
|
|
13
|
+
* 给 vnode 添加样式
|
|
14
|
+
* @param vnode vnode
|
|
15
|
+
* @param newStyle { key: val }
|
|
16
|
+
*/
|
|
17
|
+
export declare function addVnodeStyle(vnode: VNode, newStyle: VNodeStyle): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description prismjs
|
|
3
|
+
* @author wangfupeng
|
|
4
|
+
*/
|
|
5
|
+
import { Text } from 'slate';
|
|
6
|
+
import Prism from 'prismjs';
|
|
7
|
+
import 'prismjs/components/prism-jsx';
|
|
8
|
+
import 'prismjs/components/prism-typescript';
|
|
9
|
+
import 'prismjs/components/prism-markup';
|
|
10
|
+
import 'prismjs/components/prism-go';
|
|
11
|
+
import 'prismjs/components/prism-php';
|
|
12
|
+
import 'prismjs/components/prism-c';
|
|
13
|
+
import 'prismjs/components/prism-python';
|
|
14
|
+
import 'prismjs/components/prism-java';
|
|
15
|
+
import 'prismjs/components/prism-cpp';
|
|
16
|
+
import 'prismjs/components/prism-csharp';
|
|
17
|
+
import 'prismjs/components/prism-visual-basic';
|
|
18
|
+
import 'prismjs/components/prism-sql';
|
|
19
|
+
import 'prismjs/components/prism-ruby';
|
|
20
|
+
import 'prismjs/components/prism-swift';
|
|
21
|
+
import 'prismjs/components/prism-bash';
|
|
22
|
+
import 'prismjs/components/prism-markdown';
|
|
23
|
+
import 'prismjs/components/prism-lua';
|
|
24
|
+
import 'prismjs/components/prism-groovy';
|
|
25
|
+
export declare const prismTokenTypes: string[];
|
|
26
|
+
/**
|
|
27
|
+
* 获取 prism token 的字符串长度
|
|
28
|
+
* @param token prism token
|
|
29
|
+
*/
|
|
30
|
+
export declare function getPrismTokenLength(token: any): any;
|
|
31
|
+
/**
|
|
32
|
+
* 获取 prism 解析的 token 列表
|
|
33
|
+
* @param textNode text node
|
|
34
|
+
* @param language 代码语言
|
|
35
|
+
*/
|
|
36
|
+
export declare function getPrismTokens(textNode: Text, language: string): (string | Prism.Token)[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.w-e-text-container [data-slate-editor] pre>code{word-wrap:normal;font-family:Consolas,Monaco,Andale Mono,Ubuntu Mono,monospace;-webkit-hyphens:none;hyphens:none;line-height:1.5;margin:.5em 0;overflow:auto;padding:1em;-moz-tab-size:4;-o-tab-size:4;tab-size:4;text-align:left;text-shadow:0 1px #fff;white-space:pre;word-break:normal;word-spacing:normal}.w-e-text-container [data-slate-editor] pre>code .token.cdata,.w-e-text-container [data-slate-editor] pre>code .token.comment,.w-e-text-container [data-slate-editor] pre>code .token.doctype,.w-e-text-container [data-slate-editor] pre>code .token.prolog{color:#708090}.w-e-text-container [data-slate-editor] pre>code .token.punctuation{color:#999}.w-e-text-container [data-slate-editor] pre>code .token.namespace{opacity:.7}.w-e-text-container [data-slate-editor] pre>code .token.boolean,.w-e-text-container [data-slate-editor] pre>code .token.constant,.w-e-text-container [data-slate-editor] pre>code .token.deleted,.w-e-text-container [data-slate-editor] pre>code .token.number,.w-e-text-container [data-slate-editor] pre>code .token.property,.w-e-text-container [data-slate-editor] pre>code .token.symbol,.w-e-text-container [data-slate-editor] pre>code .token.tag{color:#905}.w-e-text-container [data-slate-editor] pre>code .token.attr-name,.w-e-text-container [data-slate-editor] pre>code .token.builtin,.w-e-text-container [data-slate-editor] pre>code .token.char,.w-e-text-container [data-slate-editor] pre>code .token.inserted,.w-e-text-container [data-slate-editor] pre>code .token.selector,.w-e-text-container [data-slate-editor] pre>code .token.string{color:#690}.w-e-text-container [data-slate-editor] pre>code .language-css .token.string,.w-e-text-container [data-slate-editor] pre>code .style .token.string,.w-e-text-container [data-slate-editor] pre>code .token.entity,.w-e-text-container [data-slate-editor] pre>code .token.operator,.w-e-text-container [data-slate-editor] pre>code .token.url{color:#9a6e3a}.w-e-text-container [data-slate-editor] pre>code .token.atrule,.w-e-text-container [data-slate-editor] pre>code .token.attr-value,.w-e-text-container [data-slate-editor] pre>code .token.keyword{color:#07a}.w-e-text-container [data-slate-editor] pre>code .token.class-name,.w-e-text-container [data-slate-editor] pre>code .token.function{color:#dd4a68}.w-e-text-container [data-slate-editor] pre>code .token.important,.w-e-text-container [data-slate-editor] pre>code .token.regex,.w-e-text-container [data-slate-editor] pre>code .token.variable{color:#e90}.w-e-text-container [data-slate-editor] pre>code .token.bold,.w-e-text-container [data-slate-editor] pre>code .token.important{font-weight:700}.w-e-text-container [data-slate-editor] pre>code .token.italic{font-style:italic}.w-e-text-container [data-slate-editor] pre>code .token.entity{cursor:help}
|