New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

remark-slate

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-slate - npm Package Compare versions

Comparing version 1.5.1 to 1.6.0

5

dist/remark-slate.cjs.development.js

@@ -125,9 +125,8 @@ 'use strict';

};
} // TODO: Handle other HTML?
}
return {
type: 'paragraph',
children: [{
text: ''
text: node.value || ''
}]

@@ -134,0 +133,0 @@ };

2

dist/remark-slate.cjs.production.min.js

@@ -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"};function a(e,r){var c,u,o,s,d,h,p,g=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)}),_=null!==(u=null==r?void 0:r.linkDestinationKey)&&void 0!==u?u:"link",y=[{text:""}];switch(e.children&&Array.isArray(e.children)&&e.children.length>0&&(y=e.children.map((function(n){return a(t({},n,{ordered:e.ordered||!1}),r)}))),e.type){case"heading":return{type:g.heading[e.depth||1],children:y};case"list":return{type:e.ordered?g.ol_list:g.ul_list,children:y};case"listItem":return{type:g.listItem,children:y};case"paragraph":return{type:g.paragraph,children:y};case"link":return(o={type:g.link})[_]=e.url,o.children=y,o;case"blockquote":return{type:g.block_quote,children:y};case"code":return{type:g.code_block,language:e.lang,children:[{text:e.value}]};case"html":var f;return(null===(s=e.value)||void 0===s?void 0:s.includes("<br>"))?{break:!0,type:g.paragraph,children:[{text:(null===(f=e.value)||void 0===f?void 0:f.replace(/<br>/g,""))||""}]}:{type:"paragraph",children:[{text:""}]};case"emphasis":return t(((d={})[g.emphasis_mark]=!0,d),i(y),l(y));case"strong":return t(((h={})[g.strong_mark]=!0,h),i(y),l(y));case"delete":return t(((p={})[g.delete_mark]=!0,p),i(y),l(y));case"thematicBreak":return{type:g.thematic_break,children:[{text:""}]};case"text":default:return{text:e.value||""}}}var i=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},u=["thematic_break"];function o(e,r){var t=e.trim(),n=t,a=""+r+n+s(r);if(n.length===e.length)return a;var i=r+n+s(r);return e.replace(t,i)}var s=function(e){return e.split("").reverse().join("")};exports.default=function(e){this.Compiler=function(r){return r.children.map((function(r){return a(r,e)}))}},exports.defaultNodeTypes=n,exports.deserialize=a,exports.serialize=function e(a,i){void 0===i&&(i={nodeTypes:n});var l=i.nodeTypes,s=void 0===l?n:l,d=i.ignoreParagraphNewline,h=void 0!==d&&d,p=i.listDepth,g=void 0===p?0:p,_=a.text||"",y=a.type||"",f=t({},n,s,{heading:t({},n.heading,s.heading)}),k=[f.ul_list,f.ol_list],v=_;if(c(a)||(v=a.children.map((function(r){var n=!c(r)&&k.includes(r.type||""),i=k.includes(a.type||""),l=!1;return!c(a)&&Array.isArray(a.children)&&(l=a.children.some((function(e){return!c(e)&&e.type===f.link}))),e(t({},r,{parentType:y}),{nodeTypes:f,ignoreParagraphNewline:(h||n||i||l)&&!r.break,listDepth:k.includes(r.type||"")?g+1:g})})).join("")),h||""!==_&&"\n"!==_||a.parentType!==f.paragraph||(y=f.paragraph,v="<br>"),""!==v||u.find((function(e){return f[e]===y})))switch("<br>"!==v&&c(a)&&(a.strikeThrough&&a.bold&&a.italic?v=o(v,"~~***"):a.bold&&a.italic?v=o(v,"***"):(a.bold&&(v=o(v,"**")),a.italic&&(v=o(v,"_")),a.strikeThrough&&(v=o(v,"~~")))),y){case f.heading[1]:return"# "+v+"\n";case f.heading[2]:return"## "+v+"\n";case f.heading[3]:return"### "+v+"\n";case f.heading[4]:return"#### "+v+"\n";case f.heading[5]:return"##### "+v+"\n";case f.heading[6]:return"###### "+v+"\n";case f.block_quote:return"> "+v+"\n\n";case f.code_block:return"```"+(a.language||"")+"\n"+v+"\n```\n";case f.link:return"["+v+"]("+(a.link||"")+")";case f.ul_list:case f.ol_list:return"\n"+v+"\n";case f.listItem:for(var b=a&&a.parentType===f.ol_list,m="",x=0;g>x;x++)m+=b?" ":" ";return m+(b?"1.":"-")+" "+v;case f.paragraph:return v+"\n";case f.thematic_break:return"---\n";default:return r(v)}};
"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"};function a(e,r){var c,u,o,s,d,h,p,g=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)}),_=null!==(u=null==r?void 0:r.linkDestinationKey)&&void 0!==u?u:"link",y=[{text:""}];switch(e.children&&Array.isArray(e.children)&&e.children.length>0&&(y=e.children.map((function(n){return a(t({},n,{ordered:e.ordered||!1}),r)}))),e.type){case"heading":return{type:g.heading[e.depth||1],children:y};case"list":return{type:e.ordered?g.ol_list:g.ul_list,children:y};case"listItem":return{type:g.listItem,children:y};case"paragraph":return{type:g.paragraph,children:y};case"link":return(o={type:g.link})[_]=e.url,o.children=y,o;case"blockquote":return{type:g.block_quote,children:y};case"code":return{type:g.code_block,language:e.lang,children:[{text:e.value}]};case"html":var f;return(null===(s=e.value)||void 0===s?void 0:s.includes("<br>"))?{break:!0,type:g.paragraph,children:[{text:(null===(f=e.value)||void 0===f?void 0:f.replace(/<br>/g,""))||""}]}:{type:"paragraph",children:[{text:e.value||""}]};case"emphasis":return t(((d={})[g.emphasis_mark]=!0,d),i(y),l(y));case"strong":return t(((h={})[g.strong_mark]=!0,h),i(y),l(y));case"delete":return t(((p={})[g.delete_mark]=!0,p),i(y),l(y));case"thematicBreak":return{type:g.thematic_break,children:[{text:""}]};case"text":default:return{text:e.value||""}}}var i=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},u=["thematic_break"];function o(e,r){var t=e.trim(),n=t,a=""+r+n+s(r);if(n.length===e.length)return a;var i=r+n+s(r);return e.replace(t,i)}var s=function(e){return e.split("").reverse().join("")};exports.default=function(e){this.Compiler=function(r){return r.children.map((function(r){return a(r,e)}))}},exports.defaultNodeTypes=n,exports.deserialize=a,exports.serialize=function e(a,i){void 0===i&&(i={nodeTypes:n});var l=i.nodeTypes,s=void 0===l?n:l,d=i.ignoreParagraphNewline,h=void 0!==d&&d,p=i.listDepth,g=void 0===p?0:p,_=a.text||"",y=a.type||"",f=t({},n,s,{heading:t({},n.heading,s.heading)}),v=[f.ul_list,f.ol_list],k=_;if(c(a)||(k=a.children.map((function(r){var n=!c(r)&&v.includes(r.type||""),i=v.includes(a.type||""),l=!1;return!c(a)&&Array.isArray(a.children)&&(l=a.children.some((function(e){return!c(e)&&e.type===f.link}))),e(t({},r,{parentType:y}),{nodeTypes:f,ignoreParagraphNewline:(h||n||i||l)&&!r.break,listDepth:v.includes(r.type||"")?g+1:g})})).join("")),h||""!==_&&"\n"!==_||a.parentType!==f.paragraph||(y=f.paragraph,k="<br>"),""!==k||u.find((function(e){return f[e]===y})))switch("<br>"!==k&&c(a)&&(a.strikeThrough&&a.bold&&a.italic?k=o(k,"~~***"):a.bold&&a.italic?k=o(k,"***"):(a.bold&&(k=o(k,"**")),a.italic&&(k=o(k,"_")),a.strikeThrough&&(k=o(k,"~~")))),y){case f.heading[1]:return"# "+k+"\n";case f.heading[2]:return"## "+k+"\n";case f.heading[3]:return"### "+k+"\n";case f.heading[4]:return"#### "+k+"\n";case f.heading[5]:return"##### "+k+"\n";case f.heading[6]:return"###### "+k+"\n";case f.block_quote:return"> "+k+"\n\n";case f.code_block:return"```"+(a.language||"")+"\n"+k+"\n```\n";case f.link:return"["+k+"]("+(a.link||"")+")";case f.ul_list:case f.ol_list:return"\n"+k+"\n";case f.listItem:for(var b=a&&a.parentType===f.ol_list,m="",x=0;g>x;x++)m+=b?" ":" ";return m+(b?"1.":"-")+" "+k;case f.paragraph:return k+"\n";case f.thematic_break:return"---\n";default:return r(k)}};
//# sourceMappingURL=remark-slate.cjs.production.min.js.map

@@ -119,9 +119,8 @@ import escapeHtml from 'escape-html';

};
} // TODO: Handle other HTML?
}
return {
type: 'paragraph',
children: [{
text: ''
text: node.value || ''
}]

@@ -128,0 +127,0 @@ };

{
"name": "remark-slate",
"version": "1.5.1",
"version": "1.6.0",
"description": "remark plugin to compile Markdown to a slate compatible object",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -10,5 +10,14 @@ # remark-slate

- [Slate ➡️ Markdown:](#slate-object-to-markdown)
- [Markdown ➡️ Slate object:](#markdown-to-slate-object)
- [Miscellaneous](#miscellaneous)
- [Local Development](#local-development)
- [`npm start` or `yarn start`](#npm-start-or-yarn-start)
- [`npm run build` or `yarn build`](#npm-run-build-or-yarn-build)
- [`npm test` or `yarn test`](#npm-test-or-yarn-test)
- [License (MIT)](#license-mit)
## Usage
### Serializing from slate object to markdown:
### Slate object to Markdown:

@@ -42,8 +51,25 @@ `remark-slate` exports an opinionated `serialize` function that is meant to be invoked with a `slate 0.50+` state object and will transform the object into a markdown document.

### Deserializing from markdown to slate object:
### Markdown to Slate object:
When deserializing, this package is meant to be used with [remark-parse](https://github.com/remarkjs/remark/tree/master/packages/remark-parse)
When deserializing from markdown to slate, this package is meant to be used with [remark-parse](https://github.com/remarkjs/remark/tree/master/packages/remark-parse) and [unified](https://github.com/unifiedjs/unified).
Say we have the following file, `example.md`:
Our JS looks something like this:
```js
import fs from 'fs';
import unified from 'unified';
import markdown from 'remark-parse';
import slate from 'remark-slate';
unified()
.use(markdown)
.use(slate)
.process(fs.readFileSync('example.md'), (err, file) => {
if (err) throw err;
console.log({ file });
});
```
And `example.md` looks like this:
```markdown

@@ -81,21 +107,6 @@ # Heading one

And our script, `example.js`, looks as follows:
Results in the following Slate object
```js
import fs from 'fs';
import unified from 'unified';
import markdown from 'remark-parse';
import slate from 'remark-slate';
<details><summary>Click me reveal!</summary>
unified()
.use(markdown)
.use(slate)
.process(fs.readFileSync('example.md'), (err, file) => {
if (err) throw err;
console.log({ file });
});
```
Would result in the following:
```json

@@ -278,19 +289,10 @@ [

```js
{
type: 'heading',
depth: 1,
children: [{ value: 'Big text' }]
}
```
</details>
…would yield:
<br>
```json
{
"type": "heading_one",
"children": [{ "text": "Big text" }]
}
```
### Miscellaneous
remark-slate makes some assumptions around unordered and ordered lists, the package pairs nicely with [slate-edit-list](https://github.com/productboard/slate-edit-list#readme)
## Local Development

@@ -346,1 +348,5 @@

[remark]: https://github.com/remarkjs/remark
```
```

@@ -129,4 +129,3 @@ export interface NodeTypes {

}
// TODO: Handle other HTML?
return { type: 'paragraph', children: [{ text: '' }] };
return { type: 'paragraph', children: [{ text: node.value || '' }] };

@@ -133,0 +132,0 @@ case 'emphasis':

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc