@lexical/markdown 0.7.6 → 0.7.8
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/LexicalMarkdown.dev.js +7 -1
- package/LexicalMarkdown.prod.js +5 -5
- package/MarkdownTransformers.d.ts +1 -0
- package/index.d.ts +2 -2
- package/package.json +8 -8
package/LexicalMarkdown.dev.js
CHANGED
|
@@ -1006,6 +1006,11 @@ const INLINE_CODE = {
|
|
|
1006
1006
|
tag: '`',
|
|
1007
1007
|
type: 'text-format'
|
|
1008
1008
|
};
|
|
1009
|
+
const HIGHLIGHT = {
|
|
1010
|
+
format: ['highlight'],
|
|
1011
|
+
tag: '==',
|
|
1012
|
+
type: 'text-format'
|
|
1013
|
+
};
|
|
1009
1014
|
const BOLD_ITALIC_STAR = {
|
|
1010
1015
|
format: ['bold', 'italic'],
|
|
1011
1016
|
tag: '***',
|
|
@@ -1085,7 +1090,7 @@ const ELEMENT_TRANSFORMERS = [HEADING, QUOTE, CODE, UNORDERED_LIST, ORDERED_LIST
|
|
|
1085
1090
|
// - code should go first as it prevents any transformations inside
|
|
1086
1091
|
// - then longer tags match (e.g. ** or __ should go before * or _)
|
|
1087
1092
|
|
|
1088
|
-
const TEXT_FORMAT_TRANSFORMERS = [INLINE_CODE, BOLD_ITALIC_STAR, BOLD_ITALIC_UNDERSCORE, BOLD_STAR, BOLD_UNDERSCORE, ITALIC_STAR, ITALIC_UNDERSCORE, STRIKETHROUGH];
|
|
1093
|
+
const TEXT_FORMAT_TRANSFORMERS = [INLINE_CODE, BOLD_ITALIC_STAR, BOLD_ITALIC_UNDERSCORE, BOLD_STAR, BOLD_UNDERSCORE, HIGHLIGHT, ITALIC_STAR, ITALIC_UNDERSCORE, STRIKETHROUGH];
|
|
1089
1094
|
const TEXT_MATCH_TRANSFORMERS = [LINK];
|
|
1090
1095
|
const TRANSFORMERS = [...ELEMENT_TRANSFORMERS, ...TEXT_FORMAT_TRANSFORMERS, ...TEXT_MATCH_TRANSFORMERS];
|
|
1091
1096
|
|
|
@@ -1109,6 +1114,7 @@ exports.CHECK_LIST = CHECK_LIST;
|
|
|
1109
1114
|
exports.CODE = CODE;
|
|
1110
1115
|
exports.ELEMENT_TRANSFORMERS = ELEMENT_TRANSFORMERS;
|
|
1111
1116
|
exports.HEADING = HEADING;
|
|
1117
|
+
exports.HIGHLIGHT = HIGHLIGHT;
|
|
1112
1118
|
exports.INLINE_CODE = INLINE_CODE;
|
|
1113
1119
|
exports.ITALIC_STAR = ITALIC_STAR;
|
|
1114
1120
|
exports.ITALIC_UNDERSCORE = ITALIC_UNDERSCORE;
|
package/LexicalMarkdown.prod.js
CHANGED
|
@@ -23,12 +23,12 @@ let W=a=>(b,c,d)=>{d=a(d);d.append(...c);b.replace(d);d.select(0,0)},X=a=>(b,c,d
|
|
|
23
23
|
(e=k.getFirstChild(),A.$isListNode(e))){d.push(Y(e,b,c+1));continue}e=" ".repeat(4*c);var l=a.getListType();l="number"===l?`${a.getStart()+f}. `:"check"===l?`- [${k.getChecked()?"x":" "}] `:"- ";d.push(e+l+b(k));f++}return d.join("\n")},ja={dependencies:[C.HeadingNode],export:(a,b)=>{if(!C.$isHeadingNode(a))return null;const c=Number(a.getTag().slice(1));return"#".repeat(c)+" "+b(a)},regExp:/^(#{1,6})\s/,replace:W(a=>C.$createHeadingNode("h"+a[1].length)),type:"element"},ka={dependencies:[C.QuoteNode],
|
|
24
24
|
export:(a,b)=>{if(!C.$isQuoteNode(a))return null;a=b(a).split("\n");b=[];for(const c of a)b.push("> "+c);return b.join("\n")},regExp:/^>\s/,replace:(a,b,c,d)=>{if(d&&(c=a.getPreviousSibling(),C.$isQuoteNode(c))){c.splice(c.getChildrenSize(),0,[h.$createLineBreakNode(),...b]);c.select(0,0);a.remove();return}c=C.$createQuoteNode();c.append(...b);a.replace(c);c.select(0,0)},type:"element"},la={dependencies:[t.CodeNode],export:a=>{if(!t.$isCodeNode(a))return null;const b=a.getTextContent();return"```"+
|
|
25
25
|
(a.getLanguage()||"")+(b?"\n"+b:"")+"\n```"},regExp:/^```(\w{1,10})?\s/,replace:W(a=>t.$createCodeNode(a?a[1]:void 0)),type:"element"},ma={dependencies:[A.ListNode,A.ListItemNode],export:(a,b)=>A.$isListNode(a)?Y(a,b,0):null,regExp:/^(\s*)[-*+]\s/,replace:X("bullet"),type:"element"},na={dependencies:[A.ListNode,A.ListItemNode],export:(a,b)=>A.$isListNode(a)?Y(a,b,0):null,regExp:/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,replace:X("check"),type:"element"},oa={dependencies:[A.ListNode,A.ListItemNode],export:(a,
|
|
26
|
-
b)=>A.$isListNode(a)?Y(a,b,0):null,regExp:/^(\s*)(\d{1,})\.\s/,replace:X("number"),type:"element"},pa={format:["code"],tag:"`",type:"text-format"},qa={format:["
|
|
27
|
-
intraword:!1,tag:"_",type:"text-format"},
|
|
28
|
-
|
|
29
|
-
exports.ORDERED_LIST=oa;exports.QUOTE=ka;exports.STRIKETHROUGH=
|
|
26
|
+
b)=>A.$isListNode(a)?Y(a,b,0):null,regExp:/^(\s*)(\d{1,})\.\s/,replace:X("number"),type:"element"},pa={format:["code"],tag:"`",type:"text-format"},qa={format:["highlight"],tag:"==",type:"text-format"},ra={format:["bold","italic"],tag:"***",type:"text-format"},sa={format:["bold","italic"],intraword:!1,tag:"___",type:"text-format"},ua={format:["bold"],tag:"**",type:"text-format"},va={format:["bold"],intraword:!1,tag:"__",type:"text-format"},wa={format:["strikethrough"],tag:"~~",type:"text-format"},
|
|
27
|
+
xa={format:["italic"],tag:"*",type:"text-format"},ya={format:["italic"],intraword:!1,tag:"_",type:"text-format"},za={dependencies:[G.LinkNode],export:(a,b,c)=>{if(!G.$isLinkNode(a))return null;b=`[${a.getTextContent()}](${a.getURL()})`;const d=a.getFirstChild();return 1===a.getChildrenSize()&&h.$isTextNode(d)?c(d,b):b},importRegExp:/(?:\[([^[]+)\])(?:\(([^()]+)\))/,regExp:/(?:\[([^[]+)\])(?:\(([^()]+)\))$/,replace:(a,b)=>{const [,c,d]=b;b=G.$createLinkNode(d);const e=h.$createTextNode(c);e.setFormat(a.getFormat());
|
|
28
|
+
b.append(e);a.replace(b)},trigger:")",type:"text-match"},Aa=[ja,ka,la,ma,oa],Ba=[pa,ra,sa,ua,va,qa,xa,ya,wa],Ca=[za],Z=[...Aa,...Ba,...Ca];exports.$convertFromMarkdownString=function(a,b=Z){return fa(b)(a)};exports.$convertToMarkdownString=function(a=Z){return ba(a)()};exports.BOLD_ITALIC_STAR=ra;exports.BOLD_ITALIC_UNDERSCORE=sa;exports.BOLD_STAR=ua;exports.BOLD_UNDERSCORE=va;exports.CHECK_LIST=na;exports.CODE=la;exports.ELEMENT_TRANSFORMERS=Aa;exports.HEADING=ja;exports.HIGHLIGHT=qa;
|
|
29
|
+
exports.INLINE_CODE=pa;exports.ITALIC_STAR=xa;exports.ITALIC_UNDERSCORE=ya;exports.LINK=za;exports.ORDERED_LIST=oa;exports.QUOTE=ka;exports.STRIKETHROUGH=wa;exports.TEXT_FORMAT_TRANSFORMERS=Ba;exports.TEXT_MATCH_TRANSFORMERS=Ca;exports.TRANSFORMERS=Z;exports.UNORDERED_LIST=ma;
|
|
30
30
|
exports.registerMarkdownShortcuts=function(a,b=Z){let c=I(b),d=H(c.textFormat,({tag:f})=>f[f.length-1]),e=H(c.textMatch,({trigger:f})=>f);for(let f of b)if(b=f.type,("element"===b||"text-match"===b)&&!a.hasNodes(f.dependencies))throw Error("Minified Lexical error #79; visit https://lexical.dev/docs/error?code=79 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return a.registerUpdateListener(({tags:f,dirtyLeaves:l,editorState:k,prevEditorState:p})=>
|
|
31
31
|
{if(!f.has("historic")){var r=k.read(h.$getSelection);f=p.read(h.$getSelection);if(h.$isRangeSelection(f)&&h.$isRangeSelection(r)&&r.isCollapsed()){p=r.anchor.key;var y=r.anchor.offset,q=k._nodeMap.get(p);h.$isTextNode(q)&&l.has(p)&&(1===y||y===f.anchor.offset+1)&&a.update(()=>{if(!q.hasFormat("code")){var m=q.getParent();if(null!==m&&!t.$isCodeNode(m)){var w=r.anchor.offset;b:{var g=c.element,n=m.getParent();if(h.$isRootOrShadowRoot(n)&&m.getFirstChild()===q&&(n=q.getTextContent()," "===n[w-1]))for(let {regExp:D,
|
|
32
|
-
replace:E}of g)if((g=n.match(D))&&g[0].length===w){n=q.getNextSiblings();let [F,
|
|
32
|
+
replace:E}of g)if((g=n.match(D))&&g[0].length===w){n=q.getNextSiblings();let [F,ta]=q.splitText(w);F.remove();n=ta?[ta,...n]:n;E(m,n,g,!1);m=!0;break b}m=!1}if(!m){b:{g=q.getTextContent();m=e[g[w-1]];if(null!=m){w<g.length&&(g=g.slice(0,w));for(x of m)if(m=g.match(x.regExp),null!==m){g=m.index||0;n=g+m[0].length;var v=void 0;0===g?[v]=q.splitText(n):[,v]=q.splitText(g,n);v.selectNext(0,0);x.replace(v,m);var x=!0;break b}}x=!1}if(!x)b:{n=q.getTextContent();--w;var u=n[w];if(x=d[u])for(let D of x){var {tag:B}=
|
|
33
33
|
D;x=B.length;let E=w-x+1;if(!(1<x&&!V(n,E,B,0,x)||" "===n[E-1])&&(v=n[w+1],!1!==D.intraword||!v||J.test(v))){m=v=q;g=U(n,E,B);for(var z=m;0>g&&(z=z.getPreviousSibling())&&!h.$isLineBreakNode(z);)h.$isTextNode(z)&&(g=z.getTextContent(),m=z,g=U(g,g.length,B));if(!(0>g||m===v&&g+x===E||(B=m.getTextContent(),0<g&&B[g-1]===u||(z=B[g-1],!1===D.intraword&&z&&!J.test(z))))){n=v.getTextContent();n=n.slice(0,E)+n.slice(w+1);v.setTextContent(n);n=m===v?n:B;m.setTextContent(n.slice(0,g)+n.slice(g+x));n=h.$getSelection();
|
|
34
34
|
u=h.$createRangeSelection();h.$setSelection(u);w=w-x*(m===v?2:1)+1;u.anchor.set(m.__key,g,"text");u.focus.set(v.__key,w,"text");for(let F of D.format)u.hasFormat(F)||u.formatText(F);u.anchor.set(u.focus.key,u.focus.offset,u.focus.type);for(let F of D.format)u.hasFormat(F)&&u.toggleFormat(F);h.$isRangeSelection(n)&&(u.format=n.format);break b}}}}}}}})}}})}
|
|
@@ -36,6 +36,7 @@ export declare const UNORDERED_LIST: ElementTransformer;
|
|
|
36
36
|
export declare const CHECK_LIST: ElementTransformer;
|
|
37
37
|
export declare const ORDERED_LIST: ElementTransformer;
|
|
38
38
|
export declare const INLINE_CODE: TextFormatTransformer;
|
|
39
|
+
export declare const HIGHLIGHT: TextFormatTransformer;
|
|
39
40
|
export declare const BOLD_ITALIC_STAR: TextFormatTransformer;
|
|
40
41
|
export declare const BOLD_ITALIC_UNDERSCORE: TextFormatTransformer;
|
|
41
42
|
export declare const BOLD_STAR: TextFormatTransformer;
|
package/index.d.ts
CHANGED
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import type { ElementTransformer, TextFormatTransformer, TextMatchTransformer, Transformer } from './MarkdownTransformers';
|
|
10
10
|
import { registerMarkdownShortcuts } from './MarkdownShortcuts';
|
|
11
|
-
import { BOLD_ITALIC_STAR, BOLD_ITALIC_UNDERSCORE, BOLD_STAR, BOLD_UNDERSCORE, CHECK_LIST, CODE, HEADING, INLINE_CODE, ITALIC_STAR, ITALIC_UNDERSCORE, LINK, ORDERED_LIST, QUOTE, STRIKETHROUGH, UNORDERED_LIST } from './MarkdownTransformers';
|
|
11
|
+
import { BOLD_ITALIC_STAR, BOLD_ITALIC_UNDERSCORE, BOLD_STAR, BOLD_UNDERSCORE, CHECK_LIST, CODE, HEADING, HIGHLIGHT, INLINE_CODE, ITALIC_STAR, ITALIC_UNDERSCORE, LINK, ORDERED_LIST, QUOTE, STRIKETHROUGH, UNORDERED_LIST } from './MarkdownTransformers';
|
|
12
12
|
declare const ELEMENT_TRANSFORMERS: Array<ElementTransformer>;
|
|
13
13
|
declare const TEXT_FORMAT_TRANSFORMERS: Array<TextFormatTransformer>;
|
|
14
14
|
declare const TEXT_MATCH_TRANSFORMERS: Array<TextMatchTransformer>;
|
|
15
15
|
declare const TRANSFORMERS: Array<Transformer>;
|
|
16
16
|
declare function $convertFromMarkdownString(markdown: string, transformers?: Array<Transformer>): void;
|
|
17
17
|
declare function $convertToMarkdownString(transformers?: Array<Transformer>): string;
|
|
18
|
-
export { $convertFromMarkdownString, $convertToMarkdownString, BOLD_ITALIC_STAR, BOLD_ITALIC_UNDERSCORE, BOLD_STAR, BOLD_UNDERSCORE, CHECK_LIST, CODE, ELEMENT_TRANSFORMERS, ElementTransformer, HEADING, INLINE_CODE, ITALIC_STAR, ITALIC_UNDERSCORE, LINK, ORDERED_LIST, QUOTE, registerMarkdownShortcuts, STRIKETHROUGH, TEXT_FORMAT_TRANSFORMERS, TEXT_MATCH_TRANSFORMERS, TextFormatTransformer, TextMatchTransformer, Transformer, TRANSFORMERS, UNORDERED_LIST, };
|
|
18
|
+
export { $convertFromMarkdownString, $convertToMarkdownString, BOLD_ITALIC_STAR, BOLD_ITALIC_UNDERSCORE, BOLD_STAR, BOLD_UNDERSCORE, CHECK_LIST, CODE, ELEMENT_TRANSFORMERS, ElementTransformer, HEADING, HIGHLIGHT, INLINE_CODE, ITALIC_STAR, ITALIC_UNDERSCORE, LINK, ORDERED_LIST, QUOTE, registerMarkdownShortcuts, STRIKETHROUGH, TEXT_FORMAT_TRANSFORMERS, TEXT_MATCH_TRANSFORMERS, TextFormatTransformer, TextMatchTransformer, Transformer, TRANSFORMERS, UNORDERED_LIST, };
|
package/package.json
CHANGED
|
@@ -8,18 +8,18 @@
|
|
|
8
8
|
"markdown"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.7.
|
|
11
|
+
"version": "0.7.8",
|
|
12
12
|
"main": "LexicalMarkdown.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.7.
|
|
14
|
+
"lexical": "0.7.8"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.7.
|
|
18
|
-
"@lexical/code": "0.7.
|
|
19
|
-
"@lexical/text": "0.7.
|
|
20
|
-
"@lexical/rich-text": "0.7.
|
|
21
|
-
"@lexical/list": "0.7.
|
|
22
|
-
"@lexical/link": "0.7.
|
|
17
|
+
"@lexical/utils": "0.7.8",
|
|
18
|
+
"@lexical/code": "0.7.8",
|
|
19
|
+
"@lexical/text": "0.7.8",
|
|
20
|
+
"@lexical/rich-text": "0.7.8",
|
|
21
|
+
"@lexical/list": "0.7.8",
|
|
22
|
+
"@lexical/link": "0.7.8"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|