planning
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s

This commit is contained in:
2024-10-14 09:15:30 +02:00
parent bcba00a730
commit 6e64e138e2
21059 changed files with 2317811 additions and 1 deletions

344
node_modules/remark-slate/README.md generated vendored Normal file
View File

@@ -0,0 +1,344 @@
# remark-slate
> Transform the contents of a slate 0.50+ editor into markdown and back again.
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[**remark**][remark] plugin to compile Markdown as a [Slate](https://www.slatejs.org/) 0.50+ compatible object.
- [Slate ➡️ Markdown:](#slate-object-to-markdown)
- [Markdown ➡️ Slate:](#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
### Slate object to Markdown:
`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.
```js
import { serialize } from 'remark-slate';
export default ({ onChange }) => {
const [value, setValue] = useState(initialValue);
const handleChange = useCallback((nextValue) => {
setValue(nextValue);
// serialize slate state to a markdown string
onChange(value.map((v) => serialize(v)).join(''));
}, [onChange]);
return (
<Slate editor={editor} value={value} onChange={handleChange}>
<Editable
renderElement={renderElement}
renderLeaf={renderLeaf}
placeholder="Enter some rich text…"
...
/>
...
</Slate>
);
};
```
### Markdown to Slate object:
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).
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
# Heading one
## Heading two
### Heading three
#### Heading four
##### Heading five
###### Heading six
Normal paragraph
_italic text_
**bold text**
~~strike through text~~
[hyperlink](https://jackhanford.com)
> A block quote.
- bullet list item 1
- bullet list item 2
1. ordered list item 1
1. ordered list item 2
```
Results in the following Slate object
<details><summary>Reveal</summary>
```json
[
{
"type": "heading_one",
"children": [
{
"text": "Heading one"
}
]
},
{
"type": "heading_two",
"children": [
{
"text": "Heading two"
}
]
},
{
"type": "heading_three",
"children": [
{
"text": "Heading three"
}
]
},
{
"type": "heading_four",
"children": [
{
"text": "Heading four"
}
]
},
{
"type": "heading_five",
"children": [
{
"text": "Heading five"
}
]
},
{
"type": "heading_six",
"children": [
{
"text": "Heading six"
}
]
},
{
"type": "paragraph",
"children": [
{
"text": "Normal paragraph"
}
]
},
{
"type": "paragraph",
"children": [
{
"text": "italic text",
"italic": true
}
]
},
{
"type": "paragraph",
"children": [
{
"text": "bold text",
"italic": true
}
]
},
{
"type": "paragraph",
"children": [
{
"text": "strike through text",
"strikeThrough": true
}
]
},
{
"type": "paragraph",
"children": [
{
"type": "link",
"link": "https://jackhanford.com",
"children": [
{
"text": "hyperkink"
}
]
}
]
},
{
"type": "block_quote",
"children": [
{
"type": "paragraph",
"children": [
{
"text": "A block quote."
}
]
}
]
},
{
"type": "ul_list",
"children": [
{
"type": "list_item",
"children": [
{
"type": "paragraph",
"children": [
{
"text": "bullet list item 1"
}
]
}
]
},
{
"type": "list_item",
"children": [
{
"type": "paragraph",
"children": [
{
"text": "bullet list item 2"
}
]
}
]
}
]
},
{
"type": "ol_list",
"children": [
{
"type": "list_item",
"children": [
{
"type": "paragraph",
"children": [
{
"text": "ordered list item 1"
}
]
}
]
},
{
"type": "list_item",
"children": [
{
"type": "paragraph",
"children": [
{
"text": "ordered list item 2"
}
]
}
]
}
]
}
]
```
</details>
<br>
### 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
Below is a list of commands you will probably find useful.
### `npm start` or `yarn start`
Runs the project in development/watch mode. The project will be rebuilt upon changes.
Your library will be rebuilt if you make edits.
### `npm run build` or `yarn build`
Bundles the package to the `dist` folder.
The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).
### `npm test` or `yarn test`
Runs the test watcher (Jest) in an interactive mode.
By default, runs tests related to files changed since the last commit.
## License (MIT)
```
WWWWWW||WWWWWW
W W W||W W W
||
( OO )__________
/ | \
/o o| MIT \
\___/||_||__||_|| *
|| || || ||
_||_|| _||_||
(__|__|(__|__|
```
Copyright © 2020-present [Jack Hanford](http://jackhanford.com), jackhanford@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
<!-- Definitions -->
[downloads-badge]: https://img.shields.io/npm/dm/remark-slate.svg
[downloads]: https://www.npmjs.com/package/remark-slate
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-slate.svg
[size]: https://bundlephobia.com/result?p=remark-slate
[remark]: https://github.com/remarkjs/remark

156
node_modules/remark-slate/dist/ast-types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,156 @@
export interface NodeTypes {
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';
}
export declare type MdastNodeType = 'paragraph' | 'heading' | 'list' | 'listItem' | 'link' | 'image' | 'blockquote' | 'code' | 'html' | 'emphasis' | 'strong' | 'delete' | 'inlineCode' | 'thematicBreak' | 'text';
export declare const defaultNodeTypes: NodeTypes;
export interface LeafType {
text: string;
strikeThrough?: boolean;
bold?: boolean;
italic?: boolean;
code?: boolean;
parentType?: string;
}
export interface BlockType {
type: string;
parentType?: string;
link?: string;
caption?: string;
language?: string;
break?: boolean;
children: Array<BlockType | LeafType>;
}
export interface InputNodeTypes {
paragraph: string;
block_quote: string;
code_block: string;
link: string;
ul_list: string;
ol_list: string;
listItem: string;
heading: {
1: string;
2: string;
3: string;
4: string;
5: string;
6: string;
};
emphasis_mark: string;
strong_mark: string;
delete_mark: string;
inline_code_mark: string;
thematic_break: string;
image: string;
}
declare type RecursivePartial<T> = {
[P in keyof T]?: RecursivePartial<T[P]>;
};
export interface OptionType<T extends InputNodeTypes = InputNodeTypes> {
nodeTypes?: RecursivePartial<T>;
linkDestinationKey?: string;
imageSourceKey?: string;
imageCaptionKey?: string;
}
export interface MdastNode {
type?: MdastNodeType;
ordered?: boolean;
value?: string;
text?: string;
children?: Array<MdastNode>;
depth?: 1 | 2 | 3 | 4 | 5 | 6;
url?: string;
alt?: string;
lang?: string;
position?: any;
spread?: any;
checked?: any;
indent?: any;
}
export declare type TextNode = {
text?: string | undefined;
};
export declare type CodeBlockNode<T extends InputNodeTypes> = {
type: T['code_block'];
language: string | undefined;
children: Array<TextNode>;
};
export declare type HeadingNode<T extends InputNodeTypes> = {
type: T['heading'][1] | T['heading'][2] | T['heading'][3] | T['heading'][4] | T['heading'][5] | T['heading'][6];
children: Array<DeserializedNode<T>>;
};
export declare type ListNode<T extends InputNodeTypes> = {
type: T['ol_list'] | T['ul_list'];
children: Array<DeserializedNode<T>>;
};
export declare type ListItemNode<T extends InputNodeTypes> = {
type: T['listItem'];
children: Array<DeserializedNode<T>>;
};
export declare type ParagraphNode<T extends InputNodeTypes> = {
type: T['paragraph'];
break?: true;
children: Array<DeserializedNode<T>>;
};
export declare type LinkNode<T extends InputNodeTypes> = {
type: T['link'];
children: Array<DeserializedNode<T>>;
[urlKey: string]: string | undefined | Array<DeserializedNode<T>>;
};
export declare type ImageNode<T extends InputNodeTypes> = {
type: T['image'];
children: Array<DeserializedNode<T>>;
[sourceOrCaptionKey: string]: string | undefined | Array<DeserializedNode<T>>;
};
export declare type BlockQuoteNode<T extends InputNodeTypes> = {
type: T['block_quote'];
children: Array<DeserializedNode<T>>;
};
export declare type InlineCodeMarkNode<T extends InputNodeTypes> = {
type: T['inline_code_mark'];
children: Array<TextNode>;
language: string | undefined;
};
export declare type ThematicBreakNode<T extends InputNodeTypes> = {
type: T['thematic_break'];
children: Array<DeserializedNode<T>>;
};
export declare type ItalicNode<T extends InputNodeTypes> = {
[K in T['emphasis_mark']]: true;
} & {
children: TextNode;
};
export declare type BoldNode = {
bold: true;
children: TextNode;
};
export declare type StrikeThoughNode = {
strikeThrough: true;
children: TextNode;
};
export declare type InlineCodeNode = {
code: true;
text: string | undefined;
};
export declare type DeserializedNode<T extends InputNodeTypes> = CodeBlockNode<T> | HeadingNode<T> | ListNode<T> | ListItemNode<T> | ParagraphNode<T> | LinkNode<T> | ImageNode<T> | BlockQuoteNode<T> | InlineCodeMarkNode<T> | ThematicBreakNode<T> | ItalicNode<T> | BoldNode | StrikeThoughNode | InlineCodeNode | TextNode;
export {};

14
node_modules/remark-slate/dist/deserialize.d.ts generated vendored Normal file
View File

@@ -0,0 +1,14 @@
import { HeadingNode, InputNodeTypes, ItalicNode, MdastNode, OptionType } from './ast-types';
export default function deserialize<T extends InputNodeTypes>(node: MdastNode, opts?: OptionType<T>): HeadingNode<T> | ItalicNode<T> | {
ordered?: boolean | undefined;
value?: string | undefined;
depth?: 1 | 2 | 3 | 4 | 5 | 6 | undefined;
url?: string | undefined;
alt?: string | undefined;
lang?: string | undefined;
position?: any;
spread?: any;
checked?: any;
indent?: any;
text: string | undefined;
};

6
node_modules/remark-slate/dist/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,6 @@
import deserialize from './deserialize';
import serialize from './serialize';
import plugin from './plugin';
export * from './ast-types';
export { deserialize, serialize };
export default plugin;

8
node_modules/remark-slate/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,8 @@
'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./remark-slate.cjs.production.min.js')
} else {
module.exports = require('./remark-slate.cjs.development.js')
}

2
node_modules/remark-slate/dist/plugin.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
import { OptionType } from './ast-types';
export default function plugin(opts?: OptionType): void;

View File

@@ -0,0 +1,417 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var escapeHtml = _interopDefault(require('escape-html'));
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
var defaultNodeTypes = {
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 deserialize(node, opts) {
var _opts$nodeTypes, _opts$linkDestination, _opts$imageSourceKey, _opts$imageCaptionKey, _ref, _ref2, _node$value, _extends2, _extends3, _extends4, _extends5;
var types = _extends({}, defaultNodeTypes, opts === null || opts === void 0 ? void 0 : opts.nodeTypes, {
heading: _extends({}, defaultNodeTypes.heading, opts === null || opts === void 0 ? void 0 : (_opts$nodeTypes = opts.nodeTypes) === null || _opts$nodeTypes === void 0 ? void 0 : _opts$nodeTypes.heading)
});
var linkDestinationKey = (_opts$linkDestination = opts === null || opts === void 0 ? void 0 : opts.linkDestinationKey) !== null && _opts$linkDestination !== void 0 ? _opts$linkDestination : 'link';
var imageSourceKey = (_opts$imageSourceKey = opts === null || opts === void 0 ? void 0 : opts.imageSourceKey) !== null && _opts$imageSourceKey !== void 0 ? _opts$imageSourceKey : 'link';
var imageCaptionKey = (_opts$imageCaptionKey = opts === null || opts === void 0 ? void 0 : opts.imageCaptionKey) !== null && _opts$imageCaptionKey !== void 0 ? _opts$imageCaptionKey : 'caption';
var children = [{
text: ''
}];
var nodeChildren = node.children;
if (nodeChildren && Array.isArray(nodeChildren) && nodeChildren.length > 0) {
children = nodeChildren.flatMap(function (c) {
return deserialize(_extends({}, c, {
ordered: node.ordered || false
}), opts);
});
}
switch (node.type) {
case 'heading':
return {
type: types.heading[node.depth || 1],
children: children
};
case 'list':
return {
type: node.ordered ? types.ol_list : types.ul_list,
children: children
};
case 'listItem':
return {
type: types.listItem,
children: children
};
case 'paragraph':
return {
type: types.paragraph,
children: children
};
case 'link':
return _ref = {
type: types.link
}, _ref[linkDestinationKey] = node.url, _ref.children = children, _ref;
case 'image':
return _ref2 = {
type: types.image,
children: [{
text: ''
}]
}, _ref2[imageSourceKey] = node.url, _ref2[imageCaptionKey] = node.alt, _ref2;
case 'blockquote':
return {
type: types.block_quote,
children: children
};
case 'code':
return {
type: types.code_block,
language: node.lang,
children: [{
text: node.value
}]
};
case 'html':
if ((_node$value = node.value) !== null && _node$value !== void 0 && _node$value.includes('<br>')) {
var _node$value2;
return {
"break": true,
type: types.paragraph,
children: [{
text: ((_node$value2 = node.value) === null || _node$value2 === void 0 ? void 0 : _node$value2.replace(/<br>/g, '')) || ''
}]
};
}
return {
type: 'paragraph',
children: [{
text: node.value || ''
}]
};
case 'emphasis':
return _extends((_extends2 = {}, _extends2[types.emphasis_mark] = true, _extends2), forceLeafNode(children), persistLeafFormats(children));
case 'strong':
return _extends((_extends3 = {}, _extends3[types.strong_mark] = true, _extends3), forceLeafNode(children), persistLeafFormats(children));
case 'delete':
return _extends((_extends4 = {}, _extends4[types.delete_mark] = true, _extends4), forceLeafNode(children), persistLeafFormats(children));
case 'inlineCode':
return _extends((_extends5 = {}, _extends5[types.inline_code_mark] = true, _extends5.text = node.value, _extends5), persistLeafFormats(children));
case 'thematicBreak':
return {
type: types.thematic_break,
children: [{
text: ''
}]
};
case 'text':
default:
return {
text: node.value || ''
};
}
}
var forceLeafNode = function forceLeafNode(children) {
return {
text: children.map(function (k) {
return k === null || k === void 0 ? void 0 : k.text;
}).join('')
};
}; // This function is will take any unknown keys, and bring them up a level
// allowing leaf nodes to have many different formats at once
// for example, bold and italic on the same node
function persistLeafFormats(children) {
return children.reduce(function (acc, node) {
Object.keys(node).forEach(function (key) {
if (key === 'children' || key === 'type' || key === 'text') return;
acc[key] = node[key];
});
return acc;
}, {});
}
var isLeafNode = function isLeafNode(node) {
return typeof node.text === 'string';
};
var VOID_ELEMENTS = ['thematic_break', 'image'];
var BREAK_TAG = '<br>';
function serialize(chunk, opts) {
if (opts === void 0) {
opts = {
nodeTypes: defaultNodeTypes
};
}
var _opts = opts,
_opts$nodeTypes = _opts.nodeTypes,
userNodeTypes = _opts$nodeTypes === void 0 ? defaultNodeTypes : _opts$nodeTypes,
_opts$ignoreParagraph = _opts.ignoreParagraphNewline,
ignoreParagraphNewline = _opts$ignoreParagraph === void 0 ? false : _opts$ignoreParagraph,
_opts$listDepth = _opts.listDepth,
listDepth = _opts$listDepth === void 0 ? 0 : _opts$listDepth;
var text = chunk.text || '';
var type = chunk.type || '';
var nodeTypes = _extends({}, defaultNodeTypes, userNodeTypes, {
heading: _extends({}, defaultNodeTypes.heading, userNodeTypes.heading)
});
var LIST_TYPES = [nodeTypes.ul_list, nodeTypes.ol_list];
var children = text;
if (!isLeafNode(chunk)) {
children = chunk.children.map(function (c) {
var isList = !isLeafNode(c) ? LIST_TYPES.includes(c.type || '') : false;
var selfIsList = LIST_TYPES.includes(chunk.type || ''); // Links can have the following shape
// In which case we don't want to surround
// with break tags
// {
// type: 'paragraph',
// children: [
// { text: '' },
// { type: 'link', children: [{ text: foo.com }]}
// { text: '' }
// ]
// }
var childrenHasLink = false;
if (!isLeafNode(chunk) && Array.isArray(chunk.children)) {
childrenHasLink = chunk.children.some(function (f) {
return !isLeafNode(f) && f.type === nodeTypes.link;
});
}
return serialize(_extends({}, c, {
parentType: type
}), {
nodeTypes: nodeTypes,
// WOAH.
// what we're doing here is pretty tricky, it relates to the block below where
// we check for ignoreParagraphNewline and set type to paragraph.
// We want to strip out empty paragraphs sometimes, but other times we don't.
// If we're the descendant of a list, we know we don't want a bunch
// of whitespace. If we're parallel to a link we also don't want
// to respect neighboring paragraphs
ignoreParagraphNewline: (ignoreParagraphNewline || isList || selfIsList || childrenHasLink) && // if we have c.break, never ignore empty paragraph new line
!c["break"],
// track depth of nested lists so we can add proper spacing
listDepth: LIST_TYPES.includes(c.type || '') ? listDepth + 1 : listDepth
});
}).join('');
} // This is pretty fragile code, check the long comment where we iterate over children
if (!ignoreParagraphNewline && (text === '' || text === '\n') && chunk.parentType === nodeTypes.paragraph) {
type = nodeTypes.paragraph;
children = BREAK_TAG;
}
if (children === '' && !VOID_ELEMENTS.find(function (k) {
return nodeTypes[k] === type;
})) return; // Never allow decorating break tags with rich text formatting,
// this can malform generated markdown
// Also ensure we're only ever applying text formatting to leaf node
// level chunks, otherwise we can end up in a situation where
// we try applying formatting like to a node like this:
// "Text foo bar **baz**" resulting in "**Text foo bar **baz****"
// which is invalid markup and can mess everything up
if (children !== BREAK_TAG && isLeafNode(chunk)) {
if (chunk.strikeThrough && chunk.bold && chunk.italic) {
children = retainWhitespaceAndFormat(children, '~~***');
} else if (chunk.bold && chunk.italic) {
children = retainWhitespaceAndFormat(children, '***');
} else {
if (chunk.bold) {
children = retainWhitespaceAndFormat(children, '**');
}
if (chunk.italic) {
children = retainWhitespaceAndFormat(children, '_');
}
if (chunk.strikeThrough) {
children = retainWhitespaceAndFormat(children, '~~');
}
if (chunk.code) {
children = retainWhitespaceAndFormat(children, '`');
}
}
}
switch (type) {
case nodeTypes.heading[1]:
return "# " + children + "\n";
case nodeTypes.heading[2]:
return "## " + children + "\n";
case nodeTypes.heading[3]:
return "### " + children + "\n";
case nodeTypes.heading[4]:
return "#### " + children + "\n";
case nodeTypes.heading[5]:
return "##### " + children + "\n";
case nodeTypes.heading[6]:
return "###### " + children + "\n";
case nodeTypes.block_quote:
// For some reason, marked is parsing blockquotes w/ one new line
// as contiued blockquotes, so adding two new lines ensures that doesn't
// happen
return "> " + children + "\n\n";
case nodeTypes.code_block:
return "```" + (chunk.language || '') + "\n" + children + "\n```\n";
case nodeTypes.link:
return "[" + children + "](" + (chunk.link || '') + ")";
case nodeTypes.image:
return "![" + chunk.caption + "](" + (chunk.link || '') + ")";
case nodeTypes.ul_list:
case nodeTypes.ol_list:
return "\n" + children + "\n";
case nodeTypes.listItem:
var isOL = chunk && chunk.parentType === nodeTypes.ol_list;
var treatAsLeaf = chunk.children.length === 1 && isLeafNode(chunk.children[0]);
var spacer = '';
for (var k = 0; listDepth > k; k++) {
if (isOL) {
// https://github.com/remarkjs/remark-react/issues/65
spacer += ' ';
} else {
spacer += ' ';
}
}
return "" + spacer + (isOL ? '1.' : '-') + " " + children + (treatAsLeaf ? '\n' : '');
case nodeTypes.paragraph:
return children + "\n";
case nodeTypes.thematic_break:
return "---\n";
default:
return escapeHtml(children);
}
} // This function handles the case of a string like this: " foo "
// Where it would be invalid markdown to generate this: "** foo **"
// We instead, want to trim the whitespace out, apply formatting, and then
// bring the whitespace back. So our returned string looks like this: " **foo** "
function retainWhitespaceAndFormat(string, format) {
// we keep this for a comparison later
var frozenString = string.trim(); // children will be mutated
var children = frozenString; // We reverse the right side formatting, to properly handle bold/italic and strikeThrough
// formats, so we can create ~~***FooBar***~~
var fullFormat = "" + format + children + reverseStr(format); // This conditions accounts for no whitespace in our string
// if we don't have any, we can return early.
if (children.length === string.length) {
return fullFormat;
} // if we do have whitespace, let's add our formatting around our trimmed string
// We reverse the right side formatting, to properly handle bold/italic and strikeThrough
// formats, so we can create ~~***FooBar***~~
var formattedString = format + children + reverseStr(format); // and replace the non-whitespace content of the string
return string.replace(frozenString, formattedString);
}
var reverseStr = function reverseStr(string) {
return string.split('').reverse().join('');
};
function plugin(opts) {
var compiler = function compiler(node) {
return node.children.map(function (c) {
return deserialize(c, opts);
});
}; // @ts-ignore
this.Compiler = compiler;
}
exports.default = plugin;
exports.defaultNodeTypes = defaultNodeTypes;
exports.deserialize = deserialize;
exports.serialize = serialize;
//# sourceMappingURL=remark-slate.cjs.development.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,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)}),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:""}],T=e.children;switch(T&&Array.isArray(T)&&T.length>0&&(x=T.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 j;return null!==(p=e.value)&&void 0!==p&&p.includes("<br>")?{break:!0,type:k.paragraph,children:[{text:(null===(j=e.value)||void 0===j?void 0:j.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=1===i.children.length&&c(i.children[0]),x="",T=0;g>T;T++)x+=m?" ":" ";return x+(m?"1.":"-")+" "+f+(b?"\n":"");case y.paragraph:return f+"\n";case y.thematic_break:return"---\n";default:return r(f)}};
//# sourceMappingURL=remark-slate.cjs.production.min.js.map

File diff suppressed because one or more lines are too long

409
node_modules/remark-slate/dist/remark-slate.esm.js generated vendored Normal file
View File

@@ -0,0 +1,409 @@
import escapeHtml from 'escape-html';
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
var defaultNodeTypes = {
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 deserialize(node, opts) {
var _opts$nodeTypes, _opts$linkDestination, _opts$imageSourceKey, _opts$imageCaptionKey, _ref, _ref2, _node$value, _extends2, _extends3, _extends4, _extends5;
var types = _extends({}, defaultNodeTypes, opts === null || opts === void 0 ? void 0 : opts.nodeTypes, {
heading: _extends({}, defaultNodeTypes.heading, opts === null || opts === void 0 ? void 0 : (_opts$nodeTypes = opts.nodeTypes) === null || _opts$nodeTypes === void 0 ? void 0 : _opts$nodeTypes.heading)
});
var linkDestinationKey = (_opts$linkDestination = opts === null || opts === void 0 ? void 0 : opts.linkDestinationKey) !== null && _opts$linkDestination !== void 0 ? _opts$linkDestination : 'link';
var imageSourceKey = (_opts$imageSourceKey = opts === null || opts === void 0 ? void 0 : opts.imageSourceKey) !== null && _opts$imageSourceKey !== void 0 ? _opts$imageSourceKey : 'link';
var imageCaptionKey = (_opts$imageCaptionKey = opts === null || opts === void 0 ? void 0 : opts.imageCaptionKey) !== null && _opts$imageCaptionKey !== void 0 ? _opts$imageCaptionKey : 'caption';
var children = [{
text: ''
}];
var nodeChildren = node.children;
if (nodeChildren && Array.isArray(nodeChildren) && nodeChildren.length > 0) {
children = nodeChildren.flatMap(function (c) {
return deserialize(_extends({}, c, {
ordered: node.ordered || false
}), opts);
});
}
switch (node.type) {
case 'heading':
return {
type: types.heading[node.depth || 1],
children: children
};
case 'list':
return {
type: node.ordered ? types.ol_list : types.ul_list,
children: children
};
case 'listItem':
return {
type: types.listItem,
children: children
};
case 'paragraph':
return {
type: types.paragraph,
children: children
};
case 'link':
return _ref = {
type: types.link
}, _ref[linkDestinationKey] = node.url, _ref.children = children, _ref;
case 'image':
return _ref2 = {
type: types.image,
children: [{
text: ''
}]
}, _ref2[imageSourceKey] = node.url, _ref2[imageCaptionKey] = node.alt, _ref2;
case 'blockquote':
return {
type: types.block_quote,
children: children
};
case 'code':
return {
type: types.code_block,
language: node.lang,
children: [{
text: node.value
}]
};
case 'html':
if ((_node$value = node.value) !== null && _node$value !== void 0 && _node$value.includes('<br>')) {
var _node$value2;
return {
"break": true,
type: types.paragraph,
children: [{
text: ((_node$value2 = node.value) === null || _node$value2 === void 0 ? void 0 : _node$value2.replace(/<br>/g, '')) || ''
}]
};
}
return {
type: 'paragraph',
children: [{
text: node.value || ''
}]
};
case 'emphasis':
return _extends((_extends2 = {}, _extends2[types.emphasis_mark] = true, _extends2), forceLeafNode(children), persistLeafFormats(children));
case 'strong':
return _extends((_extends3 = {}, _extends3[types.strong_mark] = true, _extends3), forceLeafNode(children), persistLeafFormats(children));
case 'delete':
return _extends((_extends4 = {}, _extends4[types.delete_mark] = true, _extends4), forceLeafNode(children), persistLeafFormats(children));
case 'inlineCode':
return _extends((_extends5 = {}, _extends5[types.inline_code_mark] = true, _extends5.text = node.value, _extends5), persistLeafFormats(children));
case 'thematicBreak':
return {
type: types.thematic_break,
children: [{
text: ''
}]
};
case 'text':
default:
return {
text: node.value || ''
};
}
}
var forceLeafNode = function forceLeafNode(children) {
return {
text: children.map(function (k) {
return k === null || k === void 0 ? void 0 : k.text;
}).join('')
};
}; // This function is will take any unknown keys, and bring them up a level
// allowing leaf nodes to have many different formats at once
// for example, bold and italic on the same node
function persistLeafFormats(children) {
return children.reduce(function (acc, node) {
Object.keys(node).forEach(function (key) {
if (key === 'children' || key === 'type' || key === 'text') return;
acc[key] = node[key];
});
return acc;
}, {});
}
var isLeafNode = function isLeafNode(node) {
return typeof node.text === 'string';
};
var VOID_ELEMENTS = ['thematic_break', 'image'];
var BREAK_TAG = '<br>';
function serialize(chunk, opts) {
if (opts === void 0) {
opts = {
nodeTypes: defaultNodeTypes
};
}
var _opts = opts,
_opts$nodeTypes = _opts.nodeTypes,
userNodeTypes = _opts$nodeTypes === void 0 ? defaultNodeTypes : _opts$nodeTypes,
_opts$ignoreParagraph = _opts.ignoreParagraphNewline,
ignoreParagraphNewline = _opts$ignoreParagraph === void 0 ? false : _opts$ignoreParagraph,
_opts$listDepth = _opts.listDepth,
listDepth = _opts$listDepth === void 0 ? 0 : _opts$listDepth;
var text = chunk.text || '';
var type = chunk.type || '';
var nodeTypes = _extends({}, defaultNodeTypes, userNodeTypes, {
heading: _extends({}, defaultNodeTypes.heading, userNodeTypes.heading)
});
var LIST_TYPES = [nodeTypes.ul_list, nodeTypes.ol_list];
var children = text;
if (!isLeafNode(chunk)) {
children = chunk.children.map(function (c) {
var isList = !isLeafNode(c) ? LIST_TYPES.includes(c.type || '') : false;
var selfIsList = LIST_TYPES.includes(chunk.type || ''); // Links can have the following shape
// In which case we don't want to surround
// with break tags
// {
// type: 'paragraph',
// children: [
// { text: '' },
// { type: 'link', children: [{ text: foo.com }]}
// { text: '' }
// ]
// }
var childrenHasLink = false;
if (!isLeafNode(chunk) && Array.isArray(chunk.children)) {
childrenHasLink = chunk.children.some(function (f) {
return !isLeafNode(f) && f.type === nodeTypes.link;
});
}
return serialize(_extends({}, c, {
parentType: type
}), {
nodeTypes: nodeTypes,
// WOAH.
// what we're doing here is pretty tricky, it relates to the block below where
// we check for ignoreParagraphNewline and set type to paragraph.
// We want to strip out empty paragraphs sometimes, but other times we don't.
// If we're the descendant of a list, we know we don't want a bunch
// of whitespace. If we're parallel to a link we also don't want
// to respect neighboring paragraphs
ignoreParagraphNewline: (ignoreParagraphNewline || isList || selfIsList || childrenHasLink) && // if we have c.break, never ignore empty paragraph new line
!c["break"],
// track depth of nested lists so we can add proper spacing
listDepth: LIST_TYPES.includes(c.type || '') ? listDepth + 1 : listDepth
});
}).join('');
} // This is pretty fragile code, check the long comment where we iterate over children
if (!ignoreParagraphNewline && (text === '' || text === '\n') && chunk.parentType === nodeTypes.paragraph) {
type = nodeTypes.paragraph;
children = BREAK_TAG;
}
if (children === '' && !VOID_ELEMENTS.find(function (k) {
return nodeTypes[k] === type;
})) return; // Never allow decorating break tags with rich text formatting,
// this can malform generated markdown
// Also ensure we're only ever applying text formatting to leaf node
// level chunks, otherwise we can end up in a situation where
// we try applying formatting like to a node like this:
// "Text foo bar **baz**" resulting in "**Text foo bar **baz****"
// which is invalid markup and can mess everything up
if (children !== BREAK_TAG && isLeafNode(chunk)) {
if (chunk.strikeThrough && chunk.bold && chunk.italic) {
children = retainWhitespaceAndFormat(children, '~~***');
} else if (chunk.bold && chunk.italic) {
children = retainWhitespaceAndFormat(children, '***');
} else {
if (chunk.bold) {
children = retainWhitespaceAndFormat(children, '**');
}
if (chunk.italic) {
children = retainWhitespaceAndFormat(children, '_');
}
if (chunk.strikeThrough) {
children = retainWhitespaceAndFormat(children, '~~');
}
if (chunk.code) {
children = retainWhitespaceAndFormat(children, '`');
}
}
}
switch (type) {
case nodeTypes.heading[1]:
return "# " + children + "\n";
case nodeTypes.heading[2]:
return "## " + children + "\n";
case nodeTypes.heading[3]:
return "### " + children + "\n";
case nodeTypes.heading[4]:
return "#### " + children + "\n";
case nodeTypes.heading[5]:
return "##### " + children + "\n";
case nodeTypes.heading[6]:
return "###### " + children + "\n";
case nodeTypes.block_quote:
// For some reason, marked is parsing blockquotes w/ one new line
// as contiued blockquotes, so adding two new lines ensures that doesn't
// happen
return "> " + children + "\n\n";
case nodeTypes.code_block:
return "```" + (chunk.language || '') + "\n" + children + "\n```\n";
case nodeTypes.link:
return "[" + children + "](" + (chunk.link || '') + ")";
case nodeTypes.image:
return "![" + chunk.caption + "](" + (chunk.link || '') + ")";
case nodeTypes.ul_list:
case nodeTypes.ol_list:
return "\n" + children + "\n";
case nodeTypes.listItem:
var isOL = chunk && chunk.parentType === nodeTypes.ol_list;
var treatAsLeaf = chunk.children.length === 1 && isLeafNode(chunk.children[0]);
var spacer = '';
for (var k = 0; listDepth > k; k++) {
if (isOL) {
// https://github.com/remarkjs/remark-react/issues/65
spacer += ' ';
} else {
spacer += ' ';
}
}
return "" + spacer + (isOL ? '1.' : '-') + " " + children + (treatAsLeaf ? '\n' : '');
case nodeTypes.paragraph:
return children + "\n";
case nodeTypes.thematic_break:
return "---\n";
default:
return escapeHtml(children);
}
} // This function handles the case of a string like this: " foo "
// Where it would be invalid markdown to generate this: "** foo **"
// We instead, want to trim the whitespace out, apply formatting, and then
// bring the whitespace back. So our returned string looks like this: " **foo** "
function retainWhitespaceAndFormat(string, format) {
// we keep this for a comparison later
var frozenString = string.trim(); // children will be mutated
var children = frozenString; // We reverse the right side formatting, to properly handle bold/italic and strikeThrough
// formats, so we can create ~~***FooBar***~~
var fullFormat = "" + format + children + reverseStr(format); // This conditions accounts for no whitespace in our string
// if we don't have any, we can return early.
if (children.length === string.length) {
return fullFormat;
} // if we do have whitespace, let's add our formatting around our trimmed string
// We reverse the right side formatting, to properly handle bold/italic and strikeThrough
// formats, so we can create ~~***FooBar***~~
var formattedString = format + children + reverseStr(format); // and replace the non-whitespace content of the string
return string.replace(frozenString, formattedString);
}
var reverseStr = function reverseStr(string) {
return string.split('').reverse().join('');
};
function plugin(opts) {
var compiler = function compiler(node) {
return node.children.map(function (c) {
return deserialize(c, opts);
});
}; // @ts-ignore
this.Compiler = compiler;
}
export default plugin;
export { defaultNodeTypes, deserialize, serialize };
//# sourceMappingURL=remark-slate.esm.js.map

File diff suppressed because one or more lines are too long

8
node_modules/remark-slate/dist/serialize.d.ts generated vendored Normal file
View File

@@ -0,0 +1,8 @@
import { BlockType, LeafType, NodeTypes } from './ast-types';
interface Options {
nodeTypes: NodeTypes;
listDepth?: number;
ignoreParagraphNewline?: boolean;
}
export default function serialize(chunk: BlockType | LeafType, opts?: Options): string | undefined;
export {};

65
node_modules/remark-slate/package.json generated vendored Normal file
View File

@@ -0,0 +1,65 @@
{
"name": "remark-slate",
"version": "1.8.6",
"description": "remark plugin to compile Markdown to a slate compatible object",
"license": "MIT",
"module": "dist/remark-slate.esm.js",
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test",
"lint": "tsdx lint",
"prepare": "tsdx build"
},
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"keywords": [
"remark",
"remark-plugin",
"plugin",
"mdast",
"markdown",
"slate",
"RTE",
"text editor",
"slate markdown"
],
"repository": "hanford/remark-slate",
"bugs": "https://github.com/hanford/remark-slate/issues",
"author": "Jack Hanford <jackhanford@gmail.com> (https://jackhanford.com)",
"contributors": [
"Jack Hanford <jackhanford@gmail.com> (https://jackhanford.com)",
"Horacio Herrera <hi@horacioh.com> (https://horacioh.com)"
],
"files": [
"dist",
"src"
],
"dependencies": {
"@types/escape-html": "^1.0.0",
"escape-html": "^1.0.3"
},
"devDependencies": {
"eslint-plugin-prettier": "^3.1.3",
"husky": "^4.2.5",
"jest": "^25.2.4",
"prettier": "^2.0.0",
"remark": "^13.0.0",
"remark-parse": "^9.0.0",
"tsdx": "^0.13.2",
"tslib": "^2.0.0",
"typescript": "^4.2.2",
"unified": "^9.0.0"
},
"prettier": {
"printWidth": 80,
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
}
}
}

236
node_modules/remark-slate/src/ast-types.ts generated vendored Normal file
View File

@@ -0,0 +1,236 @@
export interface NodeTypes {
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';
}
export type MdastNodeType =
| 'paragraph'
| 'heading'
| 'list'
| 'listItem'
| 'link'
| 'image'
| 'blockquote'
| 'code'
| 'html'
| 'emphasis'
| 'strong'
| 'delete'
| 'inlineCode'
| 'thematicBreak'
| 'text';
export const defaultNodeTypes: NodeTypes = {
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',
};
export interface LeafType {
text: string;
strikeThrough?: boolean;
bold?: boolean;
italic?: boolean;
code?: boolean;
parentType?: string;
}
export interface BlockType {
type: string;
parentType?: string;
link?: string;
caption?: string;
language?: string;
break?: boolean;
children: Array<BlockType | LeafType>;
}
export interface InputNodeTypes {
paragraph: string;
block_quote: string;
code_block: string;
link: string;
ul_list: string;
ol_list: string;
listItem: string;
heading: {
1: string;
2: string;
3: string;
4: string;
5: string;
6: string;
};
emphasis_mark: string;
strong_mark: string;
delete_mark: string;
inline_code_mark: string;
thematic_break: string;
image: string;
}
type RecursivePartial<T> = {
[P in keyof T]?: RecursivePartial<T[P]>;
};
export interface OptionType<T extends InputNodeTypes = InputNodeTypes> {
nodeTypes?: RecursivePartial<T>;
linkDestinationKey?: string;
imageSourceKey?: string;
imageCaptionKey?: string;
}
export interface MdastNode {
type?: MdastNodeType;
ordered?: boolean;
value?: string;
text?: string;
children?: Array<MdastNode>;
depth?: 1 | 2 | 3 | 4 | 5 | 6;
url?: string;
alt?: string;
lang?: string;
// mdast metadata
position?: any;
spread?: any;
checked?: any;
indent?: any;
}
export type TextNode = { text?: string | undefined };
export type CodeBlockNode<T extends InputNodeTypes> = {
type: T['code_block'];
language: string | undefined;
children: Array<TextNode>;
};
export type HeadingNode<T extends InputNodeTypes> = {
type:
| T['heading'][1]
| T['heading'][2]
| T['heading'][3]
| T['heading'][4]
| T['heading'][5]
| T['heading'][6];
children: Array<DeserializedNode<T>>;
};
export type ListNode<T extends InputNodeTypes> = {
type: T['ol_list'] | T['ul_list'];
children: Array<DeserializedNode<T>>;
};
export type ListItemNode<T extends InputNodeTypes> = {
type: T['listItem'];
children: Array<DeserializedNode<T>>;
};
export type ParagraphNode<T extends InputNodeTypes> = {
type: T['paragraph'];
break?: true;
children: Array<DeserializedNode<T>>;
};
export type LinkNode<T extends InputNodeTypes> = {
type: T['link'];
children: Array<DeserializedNode<T>>;
[urlKey: string]: string | undefined | Array<DeserializedNode<T>>;
};
export type ImageNode<T extends InputNodeTypes> = {
type: T['image'];
children: Array<DeserializedNode<T>>;
[sourceOrCaptionKey: string]: string | undefined | Array<DeserializedNode<T>>;
};
export type BlockQuoteNode<T extends InputNodeTypes> = {
type: T['block_quote'];
children: Array<DeserializedNode<T>>;
};
export type InlineCodeMarkNode<T extends InputNodeTypes> = {
type: T['inline_code_mark'];
children: Array<TextNode>;
language: string | undefined;
};
export type ThematicBreakNode<T extends InputNodeTypes> = {
type: T['thematic_break'];
children: Array<DeserializedNode<T>>;
};
export type ItalicNode<T extends InputNodeTypes> = {
[K in T['emphasis_mark']]: true;
} & {
children: TextNode;
};
export type BoldNode = {
bold: true;
children: TextNode;
};
export type StrikeThoughNode = {
strikeThrough: true;
children: TextNode;
};
export type InlineCodeNode = {
code: true;
text: string | undefined;
};
export type DeserializedNode<T extends InputNodeTypes> =
| CodeBlockNode<T>
| HeadingNode<T>
| ListNode<T>
| ListItemNode<T>
| ParagraphNode<T>
| LinkNode<T>
| ImageNode<T>
| BlockQuoteNode<T>
| InlineCodeMarkNode<T>
| ThematicBreakNode<T>
| ItalicNode<T>
| BoldNode
| StrikeThoughNode
| InlineCodeNode
| TextNode;

154
node_modules/remark-slate/src/deserialize.ts generated vendored Normal file
View File

@@ -0,0 +1,154 @@
import {
BlockQuoteNode,
CodeBlockNode,
defaultNodeTypes,
DeserializedNode,
HeadingNode,
ImageNode,
InputNodeTypes,
ItalicNode,
LinkNode,
ListItemNode,
ListNode,
MdastNode,
OptionType,
ParagraphNode,
TextNode,
ThematicBreakNode,
} from './ast-types';
export default function deserialize<T extends InputNodeTypes>(
node: MdastNode,
opts?: OptionType<T>
) {
const types = {
...defaultNodeTypes,
...opts?.nodeTypes,
heading: {
...defaultNodeTypes.heading,
...opts?.nodeTypes?.heading,
},
};
const linkDestinationKey = opts?.linkDestinationKey ?? 'link';
const imageSourceKey = opts?.imageSourceKey ?? 'link';
const imageCaptionKey = opts?.imageCaptionKey ?? 'caption';
let children: Array<DeserializedNode<T>> = [{ text: '' }];
const nodeChildren = node.children;
if (nodeChildren && Array.isArray(nodeChildren) && nodeChildren.length > 0) {
children = nodeChildren.flatMap((c: MdastNode) =>
deserialize(
{
...c,
ordered: node.ordered || false,
},
opts
)
);
}
switch (node.type) {
case 'heading':
return {
type: types.heading[node.depth || 1],
children,
} as HeadingNode<T>;
case 'list':
return {
type: node.ordered ? types.ol_list : types.ul_list,
children,
} as ListNode<T>;
case 'listItem':
return { type: types.listItem, children } as ListItemNode<T>;
case 'paragraph':
return { type: types.paragraph, children } as ParagraphNode<T>;
case 'link':
return {
type: types.link,
[linkDestinationKey]: node.url,
children,
} as LinkNode<T>;
case 'image':
return {
type: types.image,
children: [{ text: '' }],
[imageSourceKey]: node.url,
[imageCaptionKey]: node.alt,
} as ImageNode<T>;
case 'blockquote':
return { type: types.block_quote, children } as BlockQuoteNode<T>;
case 'code':
return {
type: types.code_block,
language: node.lang,
children: [{ text: node.value }],
} as CodeBlockNode<T>;
case 'html':
if (node.value?.includes('<br>')) {
return {
break: true,
type: types.paragraph,
children: [{ text: node.value?.replace(/<br>/g, '') || '' }],
} as ParagraphNode<T>;
}
return { type: 'paragraph', children: [{ text: node.value || '' }] };
case 'emphasis':
return {
[types.emphasis_mark as string]: true,
...forceLeafNode(children as Array<TextNode>),
...persistLeafFormats(children as Array<MdastNode>),
} as unknown as ItalicNode<T>;
case 'strong':
return {
[types.strong_mark as string]: true,
...forceLeafNode(children as Array<TextNode>),
...persistLeafFormats(children as Array<MdastNode>),
};
case 'delete':
return {
[types.delete_mark as string]: true,
...forceLeafNode(children as Array<TextNode>),
...persistLeafFormats(children as Array<MdastNode>),
};
case 'inlineCode':
return {
[types.inline_code_mark as string]: true,
text: node.value,
...persistLeafFormats(children as Array<MdastNode>),
};
case 'thematicBreak':
return {
type: types.thematic_break,
children: [{ text: '' }],
} as ThematicBreakNode<T>;
case 'text':
default:
return { text: node.value || '' };
}
}
const forceLeafNode = (children: Array<TextNode>) => ({
text: children.map((k) => k?.text).join(''),
});
// This function is will take any unknown keys, and bring them up a level
// allowing leaf nodes to have many different formats at once
// for example, bold and italic on the same node
function persistLeafFormats(
children: Array<MdastNode>
): Omit<MdastNode, 'children' | 'type' | 'text'> {
return children.reduce((acc, node) => {
(Object.keys(node) as Array<keyof MdastNode>).forEach(function (key) {
if (key === 'children' || key === 'type' || key === 'text') return;
acc[key] = node[key];
});
return acc;
}, {});
}

9
node_modules/remark-slate/src/index.ts generated vendored Normal file
View File

@@ -0,0 +1,9 @@
import deserialize from './deserialize';
import serialize from './serialize';
import plugin from './plugin';
export * from './ast-types';
export { deserialize, serialize };
export default plugin;

11
node_modules/remark-slate/src/plugin.ts generated vendored Normal file
View File

@@ -0,0 +1,11 @@
import { MdastNode, OptionType } from './ast-types';
import transform from './deserialize';
export default function plugin(opts?: OptionType) {
const compiler = (node: { children: Array<MdastNode> }) => {
return node.children.map((c) => transform(c, opts));
};
// @ts-ignore
this.Compiler = compiler;
}

243
node_modules/remark-slate/src/serialize.ts generated vendored Normal file
View File

@@ -0,0 +1,243 @@
import { BlockType, defaultNodeTypes, LeafType, NodeTypes } from './ast-types';
import escapeHtml from 'escape-html';
interface Options {
nodeTypes: NodeTypes;
listDepth?: number;
ignoreParagraphNewline?: boolean;
}
const isLeafNode = (node: BlockType | LeafType): node is LeafType => {
return typeof (node as LeafType).text === 'string';
};
const VOID_ELEMENTS: Array<keyof NodeTypes> = ['thematic_break', 'image'];
const BREAK_TAG = '<br>';
export default function serialize(
chunk: BlockType | LeafType,
opts: Options = { nodeTypes: defaultNodeTypes }
) {
const {
nodeTypes: userNodeTypes = defaultNodeTypes,
ignoreParagraphNewline = false,
listDepth = 0,
} = opts;
let text = (chunk as LeafType).text || '';
let type = (chunk as BlockType).type || '';
const nodeTypes: NodeTypes = {
...defaultNodeTypes,
...userNodeTypes,
heading: {
...defaultNodeTypes.heading,
...userNodeTypes.heading,
},
};
const LIST_TYPES = [nodeTypes.ul_list, nodeTypes.ol_list];
let children = text;
if (!isLeafNode(chunk)) {
children = chunk.children
.map((c: BlockType | LeafType) => {
const isList = !isLeafNode(c)
? (LIST_TYPES as string[]).includes(c.type || '')
: false;
const selfIsList = (LIST_TYPES as string[]).includes(chunk.type || '');
// Links can have the following shape
// In which case we don't want to surround
// with break tags
// {
// type: 'paragraph',
// children: [
// { text: '' },
// { type: 'link', children: [{ text: foo.com }]}
// { text: '' }
// ]
// }
let childrenHasLink = false;
if (!isLeafNode(chunk) && Array.isArray(chunk.children)) {
childrenHasLink = chunk.children.some(
(f) => !isLeafNode(f) && f.type === nodeTypes.link
);
}
return serialize(
{ ...c, parentType: type },
{
nodeTypes,
// WOAH.
// what we're doing here is pretty tricky, it relates to the block below where
// we check for ignoreParagraphNewline and set type to paragraph.
// We want to strip out empty paragraphs sometimes, but other times we don't.
// If we're the descendant of a list, we know we don't want a bunch
// of whitespace. If we're parallel to a link we also don't want
// to respect neighboring paragraphs
ignoreParagraphNewline:
(ignoreParagraphNewline ||
isList ||
selfIsList ||
childrenHasLink) &&
// if we have c.break, never ignore empty paragraph new line
!(c as BlockType).break,
// track depth of nested lists so we can add proper spacing
listDepth: (LIST_TYPES as string[]).includes(
(c as BlockType).type || ''
)
? listDepth + 1
: listDepth,
}
);
})
.join('');
}
// This is pretty fragile code, check the long comment where we iterate over children
if (
!ignoreParagraphNewline &&
(text === '' || text === '\n') &&
chunk.parentType === nodeTypes.paragraph
) {
type = nodeTypes.paragraph;
children = BREAK_TAG;
}
if (children === '' && !VOID_ELEMENTS.find((k) => nodeTypes[k] === type))
return;
// Never allow decorating break tags with rich text formatting,
// this can malform generated markdown
// Also ensure we're only ever applying text formatting to leaf node
// level chunks, otherwise we can end up in a situation where
// we try applying formatting like to a node like this:
// "Text foo bar **baz**" resulting in "**Text foo bar **baz****"
// which is invalid markup and can mess everything up
if (children !== BREAK_TAG && isLeafNode(chunk)) {
if (chunk.strikeThrough && chunk.bold && chunk.italic) {
children = retainWhitespaceAndFormat(children, '~~***');
} else if (chunk.bold && chunk.italic) {
children = retainWhitespaceAndFormat(children, '***');
} else {
if (chunk.bold) {
children = retainWhitespaceAndFormat(children, '**');
}
if (chunk.italic) {
children = retainWhitespaceAndFormat(children, '_');
}
if (chunk.strikeThrough) {
children = retainWhitespaceAndFormat(children, '~~');
}
if (chunk.code) {
children = retainWhitespaceAndFormat(children, '`');
}
}
}
switch (type) {
case nodeTypes.heading[1]:
return `# ${children}\n`;
case nodeTypes.heading[2]:
return `## ${children}\n`;
case nodeTypes.heading[3]:
return `### ${children}\n`;
case nodeTypes.heading[4]:
return `#### ${children}\n`;
case nodeTypes.heading[5]:
return `##### ${children}\n`;
case nodeTypes.heading[6]:
return `###### ${children}\n`;
case nodeTypes.block_quote:
// For some reason, marked is parsing blockquotes w/ one new line
// as contiued blockquotes, so adding two new lines ensures that doesn't
// happen
return `> ${children}\n\n`;
case nodeTypes.code_block:
return `\`\`\`${
(chunk as BlockType).language || ''
}\n${children}\n\`\`\`\n`;
case nodeTypes.link:
return `[${children}](${(chunk as BlockType).link || ''})`;
case nodeTypes.image:
return `![${(chunk as BlockType).caption}](${
(chunk as BlockType).link || ''
})`;
case nodeTypes.ul_list:
case nodeTypes.ol_list:
return `\n${children}\n`;
case nodeTypes.listItem:
const isOL = chunk && chunk.parentType === nodeTypes.ol_list;
const treatAsLeaf =
(chunk as BlockType).children.length === 1 &&
isLeafNode((chunk as BlockType).children[0]);
let spacer = '';
for (let k = 0; listDepth > k; k++) {
if (isOL) {
// https://github.com/remarkjs/remark-react/issues/65
spacer += ' ';
} else {
spacer += ' ';
}
}
return `${spacer}${isOL ? '1.' : '-'} ${children}${
treatAsLeaf ? '\n' : ''
}`;
case nodeTypes.paragraph:
return `${children}\n`;
case nodeTypes.thematic_break:
return `---\n`;
default:
return escapeHtml(children);
}
}
// This function handles the case of a string like this: " foo "
// Where it would be invalid markdown to generate this: "** foo **"
// We instead, want to trim the whitespace out, apply formatting, and then
// bring the whitespace back. So our returned string looks like this: " **foo** "
function retainWhitespaceAndFormat(string: string, format: string) {
// we keep this for a comparison later
const frozenString = string.trim();
// children will be mutated
let children = frozenString;
// We reverse the right side formatting, to properly handle bold/italic and strikeThrough
// formats, so we can create ~~***FooBar***~~
const fullFormat = `${format}${children}${reverseStr(format)}`;
// This conditions accounts for no whitespace in our string
// if we don't have any, we can return early.
if (children.length === string.length) {
return fullFormat;
}
// if we do have whitespace, let's add our formatting around our trimmed string
// We reverse the right side formatting, to properly handle bold/italic and strikeThrough
// formats, so we can create ~~***FooBar***~~
const formattedString = format + children + reverseStr(format);
// and replace the non-whitespace content of the string
return string.replace(frozenString, formattedString);
}
const reverseStr = (string: string) => string.split('').reverse().join('');