remark-slate
Advanced tools
Comparing version 1.7.0 to 1.8.0
@@ -21,2 +21,3 @@ export interface NodeTypes { | ||
delete_mark: string; | ||
inline_code_mark: string; | ||
thematic_break: string; | ||
@@ -74,3 +75,3 @@ } | ||
value?: string | undefined; | ||
text: string; | ||
text: string | undefined; | ||
children?: MdastNode[] | undefined; | ||
@@ -77,0 +78,0 @@ depth?: 1 | 2 | 3 | 4 | 5 | 6 | undefined; |
@@ -46,2 +46,3 @@ 'use strict'; | ||
delete_mark: 'strikeThrough', | ||
inline_code_mark: 'code', | ||
thematic_break: 'thematic_break', | ||
@@ -51,3 +52,3 @@ image: 'image' | ||
function deserialize(node, opts) { | ||
var _opts$nodeTypes, _opts$linkDestination, _opts$imageSourceKey, _opts$imageCaptionKey, _ref, _ref2, _node$value, _extends2, _extends3, _extends4; | ||
var _opts$nodeTypes, _opts$linkDestination, _opts$imageSourceKey, _opts$imageCaptionKey, _ref, _ref2, _node$value, _extends2, _extends3, _extends4, _extends5; | ||
@@ -156,2 +157,5 @@ var types = _extends({}, defaultNodeTypes, opts === null || opts === void 0 ? void 0 : opts.nodeTypes, { | ||
case 'inlineCode': | ||
return _extends((_extends5 = {}, _extends5[types.inline_code_mark] = true, _extends5.text = node.value, _extends5), persistLeafFormats(children)); | ||
case 'thematicBreak': | ||
@@ -300,2 +304,6 @@ return { | ||
} | ||
if (chunk.code) { | ||
children = retainWhitespaceAndFormat(children, '`'); | ||
} | ||
} | ||
@@ -302,0 +310,0 @@ } |
@@ -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",thematic_break:"thematic_break",image:"image"};function i(e,r){var u,c,o,d,s,h,p,g,v,y,_=t({},n,null==r?void 0:r.nodeTypes,{heading:t({},n.heading,null==r||null===(u=r.nodeTypes)||void 0===u?void 0:u.heading)}),k=null!==(c=null==r?void 0:r.linkDestinationKey)&&void 0!==c?c:"link",f=null!==(o=null==r?void 0:r.imageSourceKey)&&void 0!==o?o:"link",m=null!==(d=null==r?void 0:r.imageCaptionKey)&&void 0!==d?d:"caption",b=[{text:""}];switch(e.children&&Array.isArray(e.children)&&e.children.length>0&&(b=e.children.map((function(n){return i(t({},n,{ordered:e.ordered||!1}),r)}))),e.type){case"heading":return{type:_.heading[e.depth||1],children:b};case"list":return{type:e.ordered?_.ol_list:_.ul_list,children:b};case"listItem":return{type:_.listItem,children:b};case"paragraph":return{type:_.paragraph,children:b};case"link":return(s={type:_.link})[k]=e.url,s.children=b,s;case"image":return(h={type:_.image,children:[{text:""}]})[f]=e.url,h[m]=e.alt,h;case"blockquote":return{type:_.block_quote,children:b};case"code":return{type:_.code_block,language:e.lang,children:[{text:e.value}]};case"html":var x;return(null===(p=e.value)||void 0===p?void 0:p.includes("<br>"))?{break:!0,type:_.paragraph,children:[{text:(null===(x=e.value)||void 0===x?void 0:x.replace(/<br>/g,""))||""}]}:{type:"paragraph",children:[{text:e.value||""}]};case"emphasis":return t(((g={})[_.emphasis_mark]=!0,g),a(b),l(b));case"strong":return t(((v={})[_.strong_mark]=!0,v),a(b),l(b));case"delete":return t(((y={})[_.delete_mark]=!0,y),a(b),l(b));case"thematicBreak":return{type:_.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 u=function(e){return"string"==typeof e.text},c=["thematic_break"];function o(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,v=i.text||"",y=i.type||"",_=t({},n,d,{heading:t({},n.heading,d.heading)}),k=[_.ul_list,_.ol_list],f=v;if(u(i)||(f=i.children.map((function(r){var n=!u(r)&&k.includes(r.type||""),a=k.includes(i.type||""),l=!1;return!u(i)&&Array.isArray(i.children)&&(l=i.children.some((function(e){return!u(e)&&e.type===_.link}))),e(t({},r,{parentType:y}),{nodeTypes:_,ignoreParagraphNewline:(h||n||a||l)&&!r.break,listDepth:k.includes(r.type||"")?g+1:g})})).join("")),h||""!==v&&"\n"!==v||i.parentType!==_.paragraph||(y=_.paragraph,f="<br>"),""!==f||c.find((function(e){return _[e]===y})))switch("<br>"!==f&&u(i)&&(i.strikeThrough&&i.bold&&i.italic?f=o(f,"~~***"):i.bold&&i.italic?f=o(f,"***"):(i.bold&&(f=o(f,"**")),i.italic&&(f=o(f,"_")),i.strikeThrough&&(f=o(f,"~~")))),y){case _.heading[1]:return"# "+f+"\n";case _.heading[2]:return"## "+f+"\n";case _.heading[3]:return"### "+f+"\n";case _.heading[4]:return"#### "+f+"\n";case _.heading[5]:return"##### "+f+"\n";case _.heading[6]:return"###### "+f+"\n";case _.block_quote:return"> "+f+"\n\n";case _.code_block:return"```"+(i.language||"")+"\n"+f+"\n```\n";case _.link:return"["+f+"]("+(i.link||"")+")";case _.image:return"!["+i.caption+"]("+(i.link||"")+")";case _.ul_list:case _.ol_list:return"\n"+f+"\n";case _.listItem:for(var m=i&&i.parentType===_.ol_list,b="",x=0;g>x;x++)b+=m?" ":" ";return b+(m?"1.":"-")+" "+f;case _.paragraph:return f+"\n";case _.thematic_break:return"---\n";default:return r(f)}}; | ||
"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?void 0: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"];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)}}; | ||
//# sourceMappingURL=remark-slate.cjs.production.min.js.map |
@@ -40,2 +40,3 @@ import escapeHtml from 'escape-html'; | ||
delete_mark: 'strikeThrough', | ||
inline_code_mark: 'code', | ||
thematic_break: 'thematic_break', | ||
@@ -45,3 +46,3 @@ image: 'image' | ||
function deserialize(node, opts) { | ||
var _opts$nodeTypes, _opts$linkDestination, _opts$imageSourceKey, _opts$imageCaptionKey, _ref, _ref2, _node$value, _extends2, _extends3, _extends4; | ||
var _opts$nodeTypes, _opts$linkDestination, _opts$imageSourceKey, _opts$imageCaptionKey, _ref, _ref2, _node$value, _extends2, _extends3, _extends4, _extends5; | ||
@@ -150,2 +151,5 @@ var types = _extends({}, defaultNodeTypes, opts === null || opts === void 0 ? void 0 : opts.nodeTypes, { | ||
case 'inlineCode': | ||
return _extends((_extends5 = {}, _extends5[types.inline_code_mark] = true, _extends5.text = node.value, _extends5), persistLeafFormats(children)); | ||
case 'thematicBreak': | ||
@@ -294,2 +298,6 @@ return { | ||
} | ||
if (chunk.code) { | ||
children = retainWhitespaceAndFormat(children, '`'); | ||
} | ||
} | ||
@@ -296,0 +304,0 @@ } |
@@ -7,2 +7,3 @@ import { NodeTypes } from './deserialize'; | ||
italic?: boolean; | ||
code?: boolean; | ||
parentType?: string; | ||
@@ -9,0 +10,0 @@ } |
{ | ||
"name": "remark-slate", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "remark plugin to compile Markdown to a slate compatible object", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -21,2 +21,3 @@ export interface NodeTypes { | ||
delete_mark: string; | ||
inline_code_mark: string; | ||
thematic_break: string; | ||
@@ -72,2 +73,3 @@ } | ||
delete_mark: 'strikeThrough', | ||
inline_code_mark: 'code', | ||
thematic_break: 'thematic_break', | ||
@@ -165,2 +167,8 @@ image: 'image', | ||
}; | ||
case 'inlineCode': | ||
return { | ||
[types.inline_code_mark]: true, | ||
text: node.value, | ||
...persistLeafFormats(children), | ||
}; | ||
case 'thematicBreak': | ||
@@ -167,0 +175,0 @@ return { |
@@ -10,2 +10,3 @@ import escapeHtml from 'escape-html'; | ||
italic?: boolean; | ||
code?: boolean; | ||
parentType?: string; | ||
@@ -158,2 +159,6 @@ } | ||
} | ||
if (chunk.code) { | ||
children = retainWhitespaceAndFormat(children, '`'); | ||
} | ||
} | ||
@@ -160,0 +165,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
123243
1231