remark-slate
Advanced tools
Comparing version 1.8.2 to 1.8.3
@@ -66,3 +66,3 @@ 'use strict'; | ||
// @ts-ignore | ||
children = node.children.map(function (c) { | ||
children = node.children.flatMap(function (c) { | ||
return deserialize(_extends({}, c, { | ||
@@ -69,0 +69,0 @@ ordered: node.ordered || false |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=(e=require("escape-html"))&&"object"==typeof e&&"default"in e?e.default:e;function t(){return(t=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}var n={paragraph:"paragraph",block_quote:"block_quote",code_block:"code_block",link:"link",ul_list:"ul_list",ol_list:"ol_list",listItem:"list_item",heading:{1:"heading_one",2:"heading_two",3:"heading_three",4:"heading_four",5:"heading_five",6:"heading_six"},emphasis_mark:"italic",strong_mark:"bold",delete_mark:"strikeThrough",inline_code_mark:"code",thematic_break:"thematic_break",image:"image"};function i(e,r){var c,o,u,d,s,h,p,g,_,v,y,k=t({},n,null==r?void 0:r.nodeTypes,{heading:t({},n.heading,null==r||null===(c=r.nodeTypes)||void 0===c?void 0:c.heading)}),m=null!==(o=null==r?void 0:r.linkDestinationKey)&&void 0!==o?o:"link",f=null!==(u=null==r?void 0:r.imageSourceKey)&&void 0!==u?u:"link",b=null!==(d=null==r?void 0:r.imageCaptionKey)&&void 0!==d?d:"caption",x=[{text:""}];switch(e.children&&Array.isArray(e.children)&&e.children.length>0&&(x=e.children.map((function(n){return i(t({},n,{ordered:e.ordered||!1}),r)}))),e.type){case"heading":return{type:k.heading[e.depth||1],children:x};case"list":return{type:e.ordered?k.ol_list:k.ul_list,children:x};case"listItem":return{type:k.listItem,children:x};case"paragraph":return{type:k.paragraph,children:x};case"link":return(s={type:k.link})[m]=e.url,s.children=x,s;case"image":return(h={type:k.image,children:[{text:""}]})[f]=e.url,h[b]=e.alt,h;case"blockquote":return{type:k.block_quote,children:x};case"code":return{type:k.code_block,language:e.lang,children:[{text:e.value}]};case"html":var T;return null!==(p=e.value)&&void 0!==p&&p.includes("<br>")?{break:!0,type:k.paragraph,children:[{text:(null===(T=e.value)||void 0===T?void 0:T.replace(/<br>/g,""))||""}]}:{type:"paragraph",children:[{text:e.value||""}]};case"emphasis":return t(((g={})[k.emphasis_mark]=!0,g),a(x),l(x));case"strong":return t(((_={})[k.strong_mark]=!0,_),a(x),l(x));case"delete":return t(((v={})[k.delete_mark]=!0,v),a(x),l(x));case"inlineCode":return t(((y={})[k.inline_code_mark]=!0,y.text=e.value,y),l(x));case"thematicBreak":return{type:k.thematic_break,children:[{text:""}]};case"text":default:return{text:e.value||""}}}var a=function(e){return{text:e.map((function(e){return null==e?void 0:e.text})).join("")}};function l(e){return e.reduce((function(e,r){return Object.keys(r).forEach((function(t){"children"!==t&&"type"!==t&&"text"!==t&&(e[t]=r[t])})),e}),{})}var c=function(e){return"string"==typeof e.text},o=["thematic_break","image"];function u(e,r){var t=e.trim(),n=t,i=""+r+n+d(r);if(n.length===e.length)return i;var a=r+n+d(r);return e.replace(t,a)}var d=function(e){return e.split("").reverse().join("")};exports.default=function(e){this.Compiler=function(r){return r.children.map((function(r){return i(r,e)}))}},exports.defaultNodeTypes=n,exports.deserialize=i,exports.serialize=function e(i,a){void 0===a&&(a={nodeTypes:n});var l=a.nodeTypes,d=void 0===l?n:l,s=a.ignoreParagraphNewline,h=void 0!==s&&s,p=a.listDepth,g=void 0===p?0:p,_=i.text||"",v=i.type||"",y=t({},n,d,{heading:t({},n.heading,d.heading)}),k=[y.ul_list,y.ol_list],m=_;if(c(i)||(m=i.children.map((function(r){var n=!c(r)&&k.includes(r.type||""),a=k.includes(i.type||""),l=!1;return!c(i)&&Array.isArray(i.children)&&(l=i.children.some((function(e){return!c(e)&&e.type===y.link}))),e(t({},r,{parentType:v}),{nodeTypes:y,ignoreParagraphNewline:(h||n||a||l)&&!r.break,listDepth:k.includes(r.type||"")?g+1:g})})).join("")),h||""!==_&&"\n"!==_||i.parentType!==y.paragraph||(v=y.paragraph,m="<br>"),""!==m||o.find((function(e){return y[e]===v})))switch("<br>"!==m&&c(i)&&(i.strikeThrough&&i.bold&&i.italic?m=u(m,"~~***"):i.bold&&i.italic?m=u(m,"***"):(i.bold&&(m=u(m,"**")),i.italic&&(m=u(m,"_")),i.strikeThrough&&(m=u(m,"~~")),i.code&&(m=u(m,"`")))),v){case y.heading[1]:return"# "+m+"\n";case y.heading[2]:return"## "+m+"\n";case y.heading[3]:return"### "+m+"\n";case y.heading[4]:return"#### "+m+"\n";case y.heading[5]:return"##### "+m+"\n";case y.heading[6]:return"###### "+m+"\n";case y.block_quote:return"> "+m+"\n\n";case y.code_block:return"```"+(i.language||"")+"\n"+m+"\n```\n";case y.link:return"["+m+"]("+(i.link||"")+")";case y.image:return"!["+i.caption+"]("+(i.link||"")+")";case y.ul_list:case y.ol_list:return"\n"+m+"\n";case y.listItem:for(var f=i&&i.parentType===y.ol_list,b="",x=0;g>x;x++)b+=f?" ":" ";return b+(f?"1.":"-")+" "+m;case y.paragraph:return m+"\n";case y.thematic_break:return"---\n";default:return r(m)}}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=(e=require("escape-html"))&&"object"==typeof e&&"default"in e?e.default:e;function t(){return(t=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}var n={paragraph:"paragraph",block_quote:"block_quote",code_block:"code_block",link:"link",ul_list:"ul_list",ol_list:"ol_list",listItem:"list_item",heading:{1:"heading_one",2:"heading_two",3:"heading_three",4:"heading_four",5:"heading_five",6:"heading_six"},emphasis_mark:"italic",strong_mark:"bold",delete_mark:"strikeThrough",inline_code_mark:"code",thematic_break:"thematic_break",image:"image"};function i(e,r){var c,o,u,d,s,h,p,g,_,v,y,k=t({},n,null==r?void 0:r.nodeTypes,{heading:t({},n.heading,null==r||null===(c=r.nodeTypes)||void 0===c?void 0:c.heading)}),f=null!==(o=null==r?void 0:r.linkDestinationKey)&&void 0!==o?o:"link",m=null!==(u=null==r?void 0:r.imageSourceKey)&&void 0!==u?u:"link",b=null!==(d=null==r?void 0:r.imageCaptionKey)&&void 0!==d?d:"caption",x=[{text:""}];switch(e.children&&Array.isArray(e.children)&&e.children.length>0&&(x=e.children.flatMap((function(n){return i(t({},n,{ordered:e.ordered||!1}),r)}))),e.type){case"heading":return{type:k.heading[e.depth||1],children:x};case"list":return{type:e.ordered?k.ol_list:k.ul_list,children:x};case"listItem":return{type:k.listItem,children:x};case"paragraph":return{type:k.paragraph,children:x};case"link":return(s={type:k.link})[f]=e.url,s.children=x,s;case"image":return(h={type:k.image,children:[{text:""}]})[m]=e.url,h[b]=e.alt,h;case"blockquote":return{type:k.block_quote,children:x};case"code":return{type:k.code_block,language:e.lang,children:[{text:e.value}]};case"html":var T;return null!==(p=e.value)&&void 0!==p&&p.includes("<br>")?{break:!0,type:k.paragraph,children:[{text:(null===(T=e.value)||void 0===T?void 0:T.replace(/<br>/g,""))||""}]}:{type:"paragraph",children:[{text:e.value||""}]};case"emphasis":return t(((g={})[k.emphasis_mark]=!0,g),a(x),l(x));case"strong":return t(((_={})[k.strong_mark]=!0,_),a(x),l(x));case"delete":return t(((v={})[k.delete_mark]=!0,v),a(x),l(x));case"inlineCode":return t(((y={})[k.inline_code_mark]=!0,y.text=e.value,y),l(x));case"thematicBreak":return{type:k.thematic_break,children:[{text:""}]};case"text":default:return{text:e.value||""}}}var a=function(e){return{text:e.map((function(e){return null==e?void 0:e.text})).join("")}};function l(e){return e.reduce((function(e,r){return Object.keys(r).forEach((function(t){"children"!==t&&"type"!==t&&"text"!==t&&(e[t]=r[t])})),e}),{})}var c=function(e){return"string"==typeof e.text},o=["thematic_break","image"];function u(e,r){var t=e.trim(),n=t,i=""+r+n+d(r);if(n.length===e.length)return i;var a=r+n+d(r);return e.replace(t,a)}var d=function(e){return e.split("").reverse().join("")};exports.default=function(e){this.Compiler=function(r){return r.children.map((function(r){return i(r,e)}))}},exports.defaultNodeTypes=n,exports.deserialize=i,exports.serialize=function e(i,a){void 0===a&&(a={nodeTypes:n});var l=a.nodeTypes,d=void 0===l?n:l,s=a.ignoreParagraphNewline,h=void 0!==s&&s,p=a.listDepth,g=void 0===p?0:p,_=i.text||"",v=i.type||"",y=t({},n,d,{heading:t({},n.heading,d.heading)}),k=[y.ul_list,y.ol_list],f=_;if(c(i)||(f=i.children.map((function(r){var n=!c(r)&&k.includes(r.type||""),a=k.includes(i.type||""),l=!1;return!c(i)&&Array.isArray(i.children)&&(l=i.children.some((function(e){return!c(e)&&e.type===y.link}))),e(t({},r,{parentType:v}),{nodeTypes:y,ignoreParagraphNewline:(h||n||a||l)&&!r.break,listDepth:k.includes(r.type||"")?g+1:g})})).join("")),h||""!==_&&"\n"!==_||i.parentType!==y.paragraph||(v=y.paragraph,f="<br>"),""!==f||o.find((function(e){return y[e]===v})))switch("<br>"!==f&&c(i)&&(i.strikeThrough&&i.bold&&i.italic?f=u(f,"~~***"):i.bold&&i.italic?f=u(f,"***"):(i.bold&&(f=u(f,"**")),i.italic&&(f=u(f,"_")),i.strikeThrough&&(f=u(f,"~~")),i.code&&(f=u(f,"`")))),v){case y.heading[1]:return"# "+f+"\n";case y.heading[2]:return"## "+f+"\n";case y.heading[3]:return"### "+f+"\n";case y.heading[4]:return"#### "+f+"\n";case y.heading[5]:return"##### "+f+"\n";case y.heading[6]:return"###### "+f+"\n";case y.block_quote:return"> "+f+"\n\n";case y.code_block:return"```"+(i.language||"")+"\n"+f+"\n```\n";case y.link:return"["+f+"]("+(i.link||"")+")";case y.image:return"!["+i.caption+"]("+(i.link||"")+")";case y.ul_list:case y.ol_list:return"\n"+f+"\n";case y.listItem:for(var m=i&&i.parentType===y.ol_list,b="",x=0;g>x;x++)b+=m?" ":" ";return b+(m?"1.":"-")+" "+f;case y.paragraph:return f+"\n";case y.thematic_break:return"---\n";default:return r(f)}}; | ||
//# sourceMappingURL=remark-slate.cjs.production.min.js.map |
@@ -60,3 +60,3 @@ import escapeHtml from 'escape-html'; | ||
// @ts-ignore | ||
children = node.children.map(function (c) { | ||
children = node.children.flatMap(function (c) { | ||
return deserialize(_extends({}, c, { | ||
@@ -63,0 +63,0 @@ ordered: node.ordered || false |
{ | ||
"name": "remark-slate", | ||
"version": "1.8.2", | ||
"version": "1.8.3", | ||
"description": "remark plugin to compile Markdown to a slate compatible object", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -344,5 +344,1 @@ # remark-slate | ||
[remark]: https://github.com/remarkjs/remark | ||
``` | ||
``` |
@@ -99,3 +99,3 @@ export interface NodeTypes { | ||
// @ts-ignore | ||
children = node.children.map((c: MdastNode) => | ||
children = node.children.flatMap((c: MdastNode) => | ||
deserialize( | ||
@@ -102,0 +102,0 @@ { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
123540
344