@lofcz/platejs-markdown 53.4.4 → 53.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -6
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as platejs2 from "platejs";
|
|
2
2
|
import { Descendant, NodeKey, Nullable, OmitFirst, PluginConfig, SlateEditor, TElement, TListElement, TNodeMap, TText, Value } from "platejs";
|
|
3
3
|
import { MdxJsxFlowElement, MdxJsxFlowElement as MdMdxJsxFlowElement, MdxJsxTextElement, MdxJsxTextElement as MdMdxJsxTextElement } from "mdast-util-mdx";
|
|
4
|
+
import { Token } from "marked";
|
|
4
5
|
import { Plugin } from "unified";
|
|
5
6
|
import { Options } from "remark-stringify";
|
|
6
|
-
import { Token } from "marked";
|
|
7
7
|
import baseRemarkMdx from "remark-mdx";
|
|
8
8
|
import { Blockquote as MdBlockquote, Break as MdBreak, Code as MdCode, Content as MdContent, Definition as MdDefinition, Delete as MdDelete, Emphasis as MdEmphasis, FootnoteDefinition as MdFootnoteDefinition, FootnoteReference as MdFootnoteReference, Heading as MdHeading, Html as MdHtml, Image as MdImage, ImageReference as MdImageReference, InlineCode as MdInlineCode, Link as MdLink, LinkReference as MdLinkReference, List as MdList, ListItem as MdListItem, Paragraph as MdParagraph, PhrasingContent as MDPhrasingContent, Root, Root as MdRoot, RootContent as MdRootContent, Strong as MdStrong, Table as MdTable, TableCell as MdTableCell, TableRow as MdTableRow, Text as MdText, ThematicBreak as MdThematicBreak, Yaml as MdYaml } from "mdast";
|
|
9
9
|
import { InlineMath as MdInlineMath, Math as MdMath } from "mdast-util-math";
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ElementApi, KEYS, TextApi, bindFirst, createTSlatePlugin, getPluginKey, getPluginType, isUrl } from "platejs";
|
|
2
2
|
import "mdast-util-mdx";
|
|
3
3
|
import { normalizeDateValue } from "@platejs/date";
|
|
4
|
+
import { Lexer, marked } from "marked";
|
|
4
5
|
import kebabCase from "lodash/kebabCase.js";
|
|
5
6
|
import { defaultHandlers, toMarkdown } from "mdast-util-to-markdown";
|
|
6
7
|
import { unified } from "unified";
|
|
7
8
|
import remarkStringify from "remark-stringify";
|
|
8
9
|
import remarkParse from "remark-parse";
|
|
9
|
-
import { marked } from "marked";
|
|
10
10
|
import baseRemarkMdx from "remark-mdx";
|
|
11
11
|
import { visit } from "unist-util-visit";
|
|
12
12
|
|
|
@@ -1456,7 +1456,7 @@ const slateToMdast = ({ children, options }) => {
|
|
|
1456
1456
|
|
|
1457
1457
|
//#endregion
|
|
1458
1458
|
//#region src/lib/rules/defaultRules.ts
|
|
1459
|
-
const
|
|
1459
|
+
const BARE_AUTOLINK_REGEX = /^https?:\/\/[^\s<>\\]+$/i;
|
|
1460
1460
|
const LEADING_NEWLINE_REGEX = /^\n/;
|
|
1461
1461
|
function isBoolean(value) {
|
|
1462
1462
|
return value === true || value === false || !!value && typeof value === "object" && Object.prototype.toString.call(value) === "[object Boolean]";
|
|
@@ -1527,10 +1527,14 @@ const defaultRules = {
|
|
|
1527
1527
|
}),
|
|
1528
1528
|
serialize: (node, options) => {
|
|
1529
1529
|
const children = convertNodesSerialize(node.children, options);
|
|
1530
|
-
if (children.length === 1 && children[0]?.type === "text" && children[0].value === node.url && options.remarkStringifyOptions?.resourceLink !== true &&
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1530
|
+
if (children.length === 1 && children[0]?.type === "text" && children[0].value === node.url && options.remarkStringifyOptions?.resourceLink !== true && BARE_AUTOLINK_REGEX.test(node.url ?? "")) {
|
|
1531
|
+
const tokens = Lexer.lexInline(node.url, { gfm: true });
|
|
1532
|
+
const token = tokens[0];
|
|
1533
|
+
if (tokens.length === 1 && token?.type === "link" && token.href === node.url && token.text === node.url) return {
|
|
1534
|
+
type: "html",
|
|
1535
|
+
value: node.url
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1534
1538
|
return {
|
|
1535
1539
|
children,
|
|
1536
1540
|
type: "link",
|
|
@@ -2525,6 +2529,7 @@ const remarkToSlate = function(options = {}) {
|
|
|
2525
2529
|
|
|
2526
2530
|
//#endregion
|
|
2527
2531
|
//#region src/lib/deserializer/utils/splitIncompleteMdx.ts
|
|
2532
|
+
const HTTP_AUTOLINK_REGEX = /^<https?:\/\/[^\s<>]*>/i;
|
|
2528
2533
|
/** Check if character is valid for tag name: A-Z / a-z / 0-9 / $ - . _ : */
|
|
2529
2534
|
const isNameChar = (c) => c >= 48 && c <= 57 || c >= 65 && c <= 90 || c >= 97 && c <= 122 || c === 36 || c === 45 || c === 46 || c === 95 || c === 58;
|
|
2530
2535
|
const isNameBoundary = (c) => c === 47 || c === 62 || c === 9 || c === 10 || c === 12 || c === 13 || c === 32;
|
|
@@ -2539,6 +2544,11 @@ const splitIncompleteMdx = (data) => {
|
|
|
2539
2544
|
continue;
|
|
2540
2545
|
}
|
|
2541
2546
|
const tagStart = i;
|
|
2547
|
+
const autolink = HTTP_AUTOLINK_REGEX.exec(data.slice(i));
|
|
2548
|
+
if (autolink) {
|
|
2549
|
+
i += autolink[0].length;
|
|
2550
|
+
continue;
|
|
2551
|
+
}
|
|
2542
2552
|
i++;
|
|
2543
2553
|
if (i >= len) {
|
|
2544
2554
|
cutPos = tagStart;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lofcz/platejs-markdown",
|
|
3
|
-
"version": "53.4.
|
|
3
|
+
"version": "53.4.10",
|
|
4
4
|
"description": "Markdown serializer plugin for Plate",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"remark-gfm": "4.0.1",
|
|
53
53
|
"remark-math": "6.0.0",
|
|
54
54
|
"@plate/scripts": "1.0.0",
|
|
55
|
-
"@platejs/table": "npm:@lofcz/platejs-table@53.1.8",
|
|
56
55
|
"@platejs/footnote": "npm:@lofcz/platejs-footnote@53.0.0",
|
|
57
|
-
"platejs": "npm:@lofcz/platejs@53.
|
|
56
|
+
"@platejs/table": "npm:@lofcz/platejs-table@53.1.8",
|
|
57
|
+
"platejs": "npm:@lofcz/platejs@53.4.9"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"platejs": ">=53.3.3",
|