@doist/typist 10.0.2 → 10.0.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [10.0.3](https://github.com/Doist/typist/compare/v10.0.2...v10.0.3) (2026-05-23)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **serializers:** follow-up fixes to suggestion HTML output ([#1342](https://github.com/Doist/typist/issues/1342)) ([86ebb2a](https://github.com/Doist/typist/commit/86ebb2af196630dab99c7508f08317cb664c3dbe))
6
+
1
7
  ## [10.0.2](https://github.com/Doist/typist/compare/v10.0.1...v10.0.2) (2026-05-22)
2
8
 
3
9
  ### Bug Fixes
@@ -1,6 +1,28 @@
1
1
  import { kebabCase } from "lodash-es";
2
2
  //#region src/helpers/serializer.ts
3
3
  /**
4
+ * Extracts the URL scheme used by a suggestion node (e.g. `mention`, `channel`) from its node
5
+ * name (e.g. `mentionSuggestion`, `channelSuggestion`).
6
+ *
7
+ * @param node The suggestion node type.
8
+ *
9
+ * @returns The URL scheme as a kebab-case string.
10
+ */
11
+ function getSuggestionUrlScheme(node) {
12
+ return kebabCase(node.name.replace(/Suggestion$/, ""));
13
+ }
14
+ /**
15
+ * Returns all suggestion nodes available in the given editor schema (e.g. `mentionSuggestion`,
16
+ * `channelSuggestion`).
17
+ *
18
+ * @param schema The editor schema to be used for suggestion nodes detection.
19
+ *
20
+ * @returns An array of `NodeType` objects for the available suggestion nodes.
21
+ */
22
+ function getSuggestionNodes(schema) {
23
+ return Object.values(schema.nodes).filter((node) => node.name.endsWith("Suggestion"));
24
+ }
25
+ /**
4
26
  * Builds the information derived from all the suggestion nodes available in the given editor
5
27
  * schema, in a single iteration. Returns `null` if there are no suggestion nodes in the schema.
6
28
  *
@@ -9,15 +31,29 @@ import { kebabCase } from "lodash-es";
9
31
  * @returns A `SuggestionSchemaInfo` object, or `null` if there are no suggestion nodes.
10
32
  */
11
33
  function buildSuggestionSchemaInfo(schema) {
12
- const suggestionNodes = Object.values(schema.nodes).filter((node) => node.name.endsWith("Suggestion"));
34
+ const suggestionNodes = getSuggestionNodes(schema);
13
35
  if (suggestionNodes.length === 0) return null;
14
- const triggerCharByScheme = new Map(suggestionNodes.map((node) => [kebabCase(node.name.replace(/Suggestion$/, "")), String(node.spec.triggerChar ?? "@")]));
36
+ const triggerCharByScheme = new Map(suggestionNodes.map((node) => [getSuggestionUrlScheme(node), String(node.spec.triggerChar ?? "@")]));
15
37
  return {
16
38
  urlSchemeRegex: `(?:${[...triggerCharByScheme.keys()].join("|")})://`,
17
39
  triggerCharByScheme
18
40
  };
19
41
  }
20
42
  /**
43
+ * Computes a string ID that identifies the configured trigger characters of all the suggestion
44
+ * nodes in the given editor schema. Used to discriminate cache keys for serializers whose output
45
+ * depends on the trigger character (e.g. the HTML serializer).
46
+ *
47
+ * @param schema The current editor document schema.
48
+ *
49
+ * @returns A string ID matching the suggestion trigger characters in the schema.
50
+ */
51
+ function computeSuggestionTriggerCharsId(schema) {
52
+ const suggestionSchemaInfo = buildSuggestionSchemaInfo(schema);
53
+ if (!suggestionSchemaInfo) return "";
54
+ return [...suggestionSchemaInfo.triggerCharByScheme].map(([scheme, triggerChar]) => `${scheme}=${triggerChar}`).join();
55
+ }
56
+ /**
21
57
  * Extract all tags from the given parse rules argument, and returns an array of said tags.
22
58
  *
23
59
  * @param parseRules The parse rules for a DOM node or inline style.
@@ -29,6 +65,6 @@ function extractTagsFromParseRules(parseRules) {
29
65
  return parseRules.filter((rule) => rule.tag).map((rule) => rule.tag);
30
66
  }
31
67
  //#endregion
32
- export { buildSuggestionSchemaInfo, extractTagsFromParseRules };
68
+ export { buildSuggestionSchemaInfo, computeSuggestionTriggerCharsId, extractTagsFromParseRules, getSuggestionNodes, getSuggestionUrlScheme };
33
69
 
34
70
  //# sourceMappingURL=serializer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"serializer.js","names":[],"sources":["../../src/helpers/serializer.ts"],"sourcesContent":["import { kebabCase } from 'lodash-es'\n\nimport { DEFAULT_SUGGESTION_TRIGGER_CHAR } from '../constants/suggestions'\n\nimport type { ParseRule, Schema } from '@tiptap/pm/model'\n\n/**\n * Information derived from the suggestion nodes available in the editor schema, used by the\n * HTML serializer to identify and transform suggestion links into spans.\n */\ntype SuggestionSchemaInfo = {\n /**\n * A partial regular expression that matches the URL schemes used by all the available\n * suggestion nodes (e.g. `(?:mention|channel)://`).\n */\n urlSchemeRegex: string\n\n /**\n * A map from each URL scheme (e.g. `mention`, `channel`) to its configured trigger character\n * (e.g. `@`, `#`).\n */\n triggerCharByScheme: Map<string, string>\n}\n\n/**\n * Builds the information derived from all the suggestion nodes available in the given editor\n * schema, in a single iteration. Returns `null` if there are no suggestion nodes in the schema.\n *\n * @param schema The editor schema to be used for suggestion nodes detection.\n *\n * @returns A `SuggestionSchemaInfo` object, or `null` if there are no suggestion nodes.\n */\nfunction buildSuggestionSchemaInfo(schema: Schema): SuggestionSchemaInfo | null {\n const suggestionNodes = Object.values(schema.nodes).filter((node) =>\n node.name.endsWith('Suggestion'),\n )\n\n if (suggestionNodes.length === 0) {\n return null\n }\n\n const triggerCharByScheme = new Map(\n suggestionNodes.map((node) => [\n kebabCase(node.name.replace(/Suggestion$/, '')),\n String(\n (node.spec as { triggerChar?: string }).triggerChar ??\n DEFAULT_SUGGESTION_TRIGGER_CHAR,\n ),\n ]),\n )\n\n const urlSchemes = [...triggerCharByScheme.keys()]\n\n return {\n urlSchemeRegex: `(?:${urlSchemes.join('|')})://`,\n triggerCharByScheme,\n }\n}\n\n/**\n * Extract all tags from the given parse rules argument, and returns an array of said tags.\n *\n * @param parseRules The parse rules for a DOM node or inline style.\n *\n * @returns An array of tags extracted from the parse rules.\n */\nfunction extractTagsFromParseRules(\n parseRules?: readonly ParseRule[],\n): (keyof HTMLElementTagNameMap)[] {\n if (!parseRules || parseRules.length === 0) {\n return []\n }\n\n return parseRules\n .filter((rule) => rule.tag)\n .map((rule) => rule.tag as keyof HTMLElementTagNameMap)\n}\n\nexport { buildSuggestionSchemaInfo, extractTagsFromParseRules }\n"],"mappings":";;;;;;;;;;AAgCA,SAAS,0BAA0B,QAA6C;CAC5E,MAAM,kBAAkB,OAAO,OAAO,OAAO,MAAM,CAAC,QAAQ,SACxD,KAAK,KAAK,SAAS,aAAa,CACnC;CAED,IAAI,gBAAgB,WAAW,GAC3B,OAAO;CAGX,MAAM,sBAAsB,IAAI,IAC5B,gBAAgB,KAAK,SAAS,CAC1B,UAAU,KAAK,KAAK,QAAQ,eAAe,GAAG,CAAC,EAC/C,OACK,KAAK,KAAkC,eAAA,IAE3C,CACJ,CAAC,CACL;CAID,OAAO;EACH,gBAAgB,MAAM,CAHN,GAAG,oBAAoB,MAAM,CAGb,CAAC,KAAK,IAAI,CAAC;EAC3C;EACH;;;;;;;;;AAUL,SAAS,0BACL,YAC+B;CAC/B,IAAI,CAAC,cAAc,WAAW,WAAW,GACrC,OAAO,EAAE;CAGb,OAAO,WACF,QAAQ,SAAS,KAAK,IAAI,CAC1B,KAAK,SAAS,KAAK,IAAmC"}
1
+ {"version":3,"file":"serializer.js","names":[],"sources":["../../src/helpers/serializer.ts"],"sourcesContent":["import { kebabCase } from 'lodash-es'\n\nimport { DEFAULT_SUGGESTION_TRIGGER_CHAR } from '../constants/suggestions'\n\nimport type { NodeType, ParseRule, Schema } from '@tiptap/pm/model'\n\n/**\n * Extracts the URL scheme used by a suggestion node (e.g. `mention`, `channel`) from its node\n * name (e.g. `mentionSuggestion`, `channelSuggestion`).\n *\n * @param node The suggestion node type.\n *\n * @returns The URL scheme as a kebab-case string.\n */\nfunction getSuggestionUrlScheme(node: NodeType): string {\n return kebabCase(node.name.replace(/Suggestion$/, ''))\n}\n\n/**\n * Information derived from the suggestion nodes available in the editor schema, used by the\n * HTML serializer to identify and transform suggestion links into spans.\n */\ntype SuggestionSchemaInfo = {\n /**\n * A partial regular expression that matches the URL schemes used by all the available\n * suggestion nodes (e.g. `(?:mention|channel)://`).\n */\n urlSchemeRegex: string\n\n /**\n * A map from each URL scheme (e.g. `mention`, `channel`) to its configured trigger character\n * (e.g. `@`, `#`).\n */\n triggerCharByScheme: Map<string, string>\n}\n\n/**\n * Returns all suggestion nodes available in the given editor schema (e.g. `mentionSuggestion`,\n * `channelSuggestion`).\n *\n * @param schema The editor schema to be used for suggestion nodes detection.\n *\n * @returns An array of `NodeType` objects for the available suggestion nodes.\n */\nfunction getSuggestionNodes(schema: Schema): NodeType[] {\n return Object.values(schema.nodes).filter((node) => node.name.endsWith('Suggestion'))\n}\n\n/**\n * Builds the information derived from all the suggestion nodes available in the given editor\n * schema, in a single iteration. Returns `null` if there are no suggestion nodes in the schema.\n *\n * @param schema The editor schema to be used for suggestion nodes detection.\n *\n * @returns A `SuggestionSchemaInfo` object, or `null` if there are no suggestion nodes.\n */\nfunction buildSuggestionSchemaInfo(schema: Schema): SuggestionSchemaInfo | null {\n const suggestionNodes = getSuggestionNodes(schema)\n\n if (suggestionNodes.length === 0) {\n return null\n }\n\n const triggerCharByScheme = new Map(\n suggestionNodes.map((node) => [\n getSuggestionUrlScheme(node),\n String(\n (node.spec as { triggerChar?: string }).triggerChar ??\n DEFAULT_SUGGESTION_TRIGGER_CHAR,\n ),\n ]),\n )\n\n const urlSchemes = [...triggerCharByScheme.keys()]\n\n return {\n urlSchemeRegex: `(?:${urlSchemes.join('|')})://`,\n triggerCharByScheme,\n }\n}\n\n/**\n * Computes a string ID that identifies the configured trigger characters of all the suggestion\n * nodes in the given editor schema. Used to discriminate cache keys for serializers whose output\n * depends on the trigger character (e.g. the HTML serializer).\n *\n * @param schema The current editor document schema.\n *\n * @returns A string ID matching the suggestion trigger characters in the schema.\n */\nfunction computeSuggestionTriggerCharsId(schema: Schema): string {\n const suggestionSchemaInfo = buildSuggestionSchemaInfo(schema)\n\n if (!suggestionSchemaInfo) {\n return ''\n }\n\n return [...suggestionSchemaInfo.triggerCharByScheme]\n .map(([scheme, triggerChar]) => `${scheme}=${triggerChar}`)\n .join()\n}\n\n/**\n * Extract all tags from the given parse rules argument, and returns an array of said tags.\n *\n * @param parseRules The parse rules for a DOM node or inline style.\n *\n * @returns An array of tags extracted from the parse rules.\n */\nfunction extractTagsFromParseRules(\n parseRules?: readonly ParseRule[],\n): (keyof HTMLElementTagNameMap)[] {\n if (!parseRules || parseRules.length === 0) {\n return []\n }\n\n return parseRules\n .filter((rule) => rule.tag)\n .map((rule) => rule.tag as keyof HTMLElementTagNameMap)\n}\n\nexport {\n buildSuggestionSchemaInfo,\n computeSuggestionTriggerCharsId,\n extractTagsFromParseRules,\n getSuggestionNodes,\n getSuggestionUrlScheme,\n}\n"],"mappings":";;;;;;;;;;AAcA,SAAS,uBAAuB,MAAwB;CACpD,OAAO,UAAU,KAAK,KAAK,QAAQ,eAAe,GAAG,CAAC;;;;;;;;;;AA6B1D,SAAS,mBAAmB,QAA4B;CACpD,OAAO,OAAO,OAAO,OAAO,MAAM,CAAC,QAAQ,SAAS,KAAK,KAAK,SAAS,aAAa,CAAC;;;;;;;;;;AAWzF,SAAS,0BAA0B,QAA6C;CAC5E,MAAM,kBAAkB,mBAAmB,OAAO;CAElD,IAAI,gBAAgB,WAAW,GAC3B,OAAO;CAGX,MAAM,sBAAsB,IAAI,IAC5B,gBAAgB,KAAK,SAAS,CAC1B,uBAAuB,KAAK,EAC5B,OACK,KAAK,KAAkC,eAAA,IAE3C,CACJ,CAAC,CACL;CAID,OAAO;EACH,gBAAgB,MAAM,CAHN,GAAG,oBAAoB,MAAM,CAGb,CAAC,KAAK,IAAI,CAAC;EAC3C;EACH;;;;;;;;;;;AAYL,SAAS,gCAAgC,QAAwB;CAC7D,MAAM,uBAAuB,0BAA0B,OAAO;CAE9D,IAAI,CAAC,sBACD,OAAO;CAGX,OAAO,CAAC,GAAG,qBAAqB,oBAAoB,CAC/C,KAAK,CAAC,QAAQ,iBAAiB,GAAG,OAAO,GAAG,cAAc,CAC1D,MAAM;;;;;;;;;AAUf,SAAS,0BACL,YAC+B;CAC/B,IAAI,CAAC,cAAc,WAAW,WAAW,GACrC,OAAO,EAAE;CAGb,OAAO,WACF,QAAQ,SAAS,KAAK,IAAI,CAC1B,KAAK,SAAS,KAAK,IAAmC"}
@@ -1 +1 @@
1
- {"version":3,"file":"html.d.ts","names":[],"sources":["../../../src/serializers/html/html.ts"],"mappings":";;;;;AAkB8C;KAKzC,wBAAA;;;;AAQ2B;;;;EAA5B,SAAA,GAAY,QAAA;AAAA;;;;AAoDuD;;;;;;iBAA9D,oBAAA,CAAqB,MAAA,EAAQ,MAAA,GAAS,wBAAA;;;;;;;;iBA+FtC,yBAAA,CAA0B,MAAA,EAAQ,MAAA,GAAM,wBAAA"}
1
+ {"version":3,"file":"html.d.ts","names":[],"sources":["../../../src/serializers/html/html.ts"],"mappings":";;;;;AAsB8C;KAKzC,wBAAA;;;;AAQ2B;;;;EAA5B,SAAA,GAAY,QAAA;AAAA;;;;AAqDuD;;;;;;iBAA9D,oBAAA,CAAqB,MAAA,EAAQ,MAAA,GAAS,wBAAA;;;;;;;;iBA+FtC,yBAAA,CAA0B,MAAA,EAAQ,MAAA,GAAM,wBAAA"}
@@ -1,4 +1,5 @@
1
1
  import { computeSchemaId, isPlainTextDocument } from "../../helpers/schema.js";
2
+ import { buildSuggestionSchemaInfo, computeSuggestionTriggerCharsId } from "../../helpers/serializer.js";
2
3
  import { rehypeCodeBlock } from "./plugins/rehype-code-block.js";
3
4
  import { rehypeImage } from "./plugins/rehype-image.js";
4
5
  import { rehypeSuggestions } from "./plugins/rehype-suggestions.js";
@@ -6,7 +7,7 @@ import { rehypeTaskList } from "./plugins/rehype-task-list.js";
6
7
  import { remarkAutolinkLiteral } from "./plugins/remark-autolink-literal.js";
7
8
  import { remarkDisableConstructs } from "./plugins/remark-disable-constructs.js";
8
9
  import { remarkStrikethrough } from "./plugins/remark-strikethrough.js";
9
- import { escape, kebabCase } from "lodash-es";
10
+ import { escape } from "lodash-es";
10
11
  import rehypeMinifyWhitespace from "rehype-minify-whitespace";
11
12
  import rehypeStringify from "rehype-stringify";
12
13
  import remarkBreaks from "remark-breaks";
@@ -24,10 +25,8 @@ import { unified } from "unified";
24
25
  function createHTMLSerializerForPlainTextEditor(schema) {
25
26
  return { serialize(markdown) {
26
27
  let htmlResult = escape(markdown);
27
- Object.values(schema.nodes).filter((node) => node.name.endsWith("Suggestion")).forEach((suggestionNode) => {
28
- const linkSchema = kebabCase(suggestionNode.name.replace(/Suggestion$/, ""));
29
- htmlResult = htmlResult.replace(new RegExp(`\\[([^\\[]+)\\]\\((?:${linkSchema}):\\/\\/([^\\s)]+)\\)`, "gm"), `<span data-${linkSchema} data-id="$2" data-label="$1"></span>`);
30
- });
28
+ const suggestionSchemaInfo = buildSuggestionSchemaInfo(schema);
29
+ if (suggestionSchemaInfo) for (const [linkSchema, triggerChar] of suggestionSchemaInfo.triggerCharByScheme) htmlResult = htmlResult.replace(new RegExp(`\\[([^\\[]+)\\]\\((?:${linkSchema}):\\/\\/([^\\s)]+)\\)`, "gm"), (_, label, id) => `<span data-${linkSchema} data-id="${id}" data-label="${label}">${triggerChar}${label}</span>`);
31
30
  return htmlResult.replace(/^([^\n]+)\n?|\n+/gm, `<p>$1</p>`);
32
31
  } };
33
32
  }
@@ -69,7 +68,7 @@ const htmlSerializerInstanceById = {};
69
68
  * @returns The HTML serializer instance for the given editor schema.
70
69
  */
71
70
  function getHTMLSerializerInstance(schema) {
72
- const id = computeSchemaId(schema);
71
+ const id = [computeSchemaId(schema), computeSuggestionTriggerCharsId(schema)].join("|");
73
72
  if (!htmlSerializerInstanceById[id]) htmlSerializerInstanceById[id] = createHTMLSerializer(schema);
74
73
  return htmlSerializerInstanceById[id];
75
74
  }
@@ -1 +1 @@
1
- {"version":3,"file":"html.js","names":[],"sources":["../../../src/serializers/html/html.ts"],"sourcesContent":["import { escape, kebabCase } from 'lodash-es'\nimport rehypeMinifyWhitespace from 'rehype-minify-whitespace'\nimport rehypeStringify from 'rehype-stringify'\nimport remarkBreaks from 'remark-breaks'\nimport remarkParse from 'remark-parse'\nimport remarkRehype from 'remark-rehype'\nimport { unified } from 'unified'\n\nimport { computeSchemaId, isPlainTextDocument } from '../../helpers/schema'\n\nimport { rehypeCodeBlock } from './plugins/rehype-code-block'\nimport { rehypeImage } from './plugins/rehype-image'\nimport { rehypeSuggestions } from './plugins/rehype-suggestions'\nimport { rehypeTaskList } from './plugins/rehype-task-list'\nimport { remarkAutolinkLiteral } from './plugins/remark-autolink-literal'\nimport { remarkDisableConstructs } from './plugins/remark-disable-constructs'\nimport { remarkStrikethrough } from './plugins/remark-strikethrough'\n\nimport type { Schema } from '@tiptap/pm/model'\n\n/**\n * The return type for the `createHTMLSerializer` function.\n */\ntype HTMLSerializerReturnType = {\n /**\n * Serializes an input Markdown string to an output HTML string.\n *\n * @param markdown The Markdown string to serialize.\n *\n * @returns The serialized HTML.\n */\n serialize: (markdown: string) => string\n}\n\n/**\n * The type for the object that holds multiple HTML serializer instances.\n */\ntype HTMLSerializerInstanceById = {\n [id: string]: HTMLSerializerReturnType\n}\n\n/**\n * Create a custom Markdown to HTML serializer for plain-text editors only.\n *\n * @param schema The editor schema to be used for nodes and marks detection.\n *\n * @returns A normalized object for the HTML serializer.\n */\nfunction createHTMLSerializerForPlainTextEditor(schema: Schema) {\n return {\n serialize(markdown: string) {\n // Converts special characters (i.e. `&`, `<`, `>`, `\"`, and `'`) to their corresponding\n // HTML entities because we need to output the full content as valid HTML (i.e. the\n // editor should not drop invalid HTML).\n let htmlResult = escape(markdown)\n\n // Serialize all suggestion links if any suggestion node exists in the schema\n Object.values(schema.nodes)\n .filter((node) => node.name.endsWith('Suggestion'))\n .forEach((suggestionNode) => {\n const linkSchema = kebabCase(suggestionNode.name.replace(/Suggestion$/, ''))\n\n htmlResult = htmlResult.replace(\n new RegExp(`\\\\[([^\\\\[]+)\\\\]\\\\((?:${linkSchema}):\\\\/\\\\/([^\\\\s)]+)\\\\)`, 'gm'),\n `<span data-${linkSchema} data-id=\"$2\" data-label=\"$1\"></span>`,\n )\n })\n\n // Return the serialized HTML with every line wrapped in a paragraph element\n return htmlResult.replace(/^([^\\n]+)\\n?|\\n+/gm, `<p>$1</p>`)\n },\n }\n}\n\n/**\n * Create a Markdown to HTML serializer with the unified ecosystem for a rich-text editor, or use a\n * custom serializer for a plain-text editor. The editor schema is used to detect which nodes and\n * marks are available in the editor, and only parses the input with the minimal required plugins.\n *\n * @param schema The editor schema to be used for nodes and marks detection.\n *\n * @returns A normalized object for the HTML serializer.\n */\nfunction createHTMLSerializer(schema: Schema): HTMLSerializerReturnType {\n // Returns a custom HTML serializer for plain-text editors\n if (isPlainTextDocument(schema)) {\n return createHTMLSerializerForPlainTextEditor(schema)\n }\n\n // Initialize a unified processor with a remark plugin for parsing Markdown\n const unifiedProcessor = unified().use(remarkParse)\n\n // Configure the unified processor to use a custom plugin to disable constructs based on the\n // supported extensions that are enabled in the editor schema\n unifiedProcessor.use(remarkDisableConstructs, schema)\n\n // Configure the unified processor to use a third-party plugin to turn soft line endings into\n // hard breaks (i.e. `<br>`), which will display user content closer to how it was authored\n // (although not CommonMark compliant, this resembles the behaviour we always supported)\n if (schema.nodes.hardBreak) {\n unifiedProcessor.use(remarkBreaks)\n }\n\n // Configure the unified processor to use a custom plugin to add support for the strikethrough\n // extension from the GitHub Flavored Markdown (GFM) specification\n if (schema.marks.strike) {\n unifiedProcessor.use(remarkStrikethrough, { singleTilde: false })\n }\n\n // Configure the unified processor to use a custom plugin to add support for the autolink\n // literals extension from the GitHub Flavored Markdown (GFM) specification\n if (schema.marks.link) {\n unifiedProcessor.use(remarkAutolinkLiteral)\n }\n\n // Configure the unified processor with an official plugin to convert Markdown into HTML to\n // support rehype (a tool that transforms HTML with plugins), followed by another official\n // plugin to minify whitespace between tags (prevents line feeds from appearing as blank)\n unifiedProcessor\n .use(remarkRehype, {\n // Persist raw HTML (disables support for custom elements/tags)\n // ref: https://github.com/Doist/Issues/issues/5689\n allowDangerousHtml: true,\n })\n // This must come before all rehype plugins that transform the HTML output\n .use(rehypeMinifyWhitespace, {\n // Preserve line breaks when collapsing whitespace (e.g., line feeds)\n newlines: true,\n })\n\n // Configure the unified processor with a custom plugin to remove the trailing newline from code\n // blocks (i.e. the newline between the last code line and `</code></pre>`)\n if (schema.nodes.codeBlock) {\n unifiedProcessor.use(rehypeCodeBlock)\n }\n\n // Configure the unified processor with a custom plugin to remove the wrapping paragraph from\n // images and to remove all inline images based on inline images support in the editor schema\n if (schema.nodes.paragraph && schema.nodes.image) {\n unifiedProcessor.use(rehypeImage, schema)\n }\n\n // Configure the unified processor with a custom plugin to add support Tiptap task lists\n if (schema.nodes.taskList && schema.nodes.taskItem) {\n unifiedProcessor.use(rehypeTaskList)\n }\n\n // Configure the unified processor with a custom plugin to add support for suggestions nodes\n unifiedProcessor.use(rehypeSuggestions, schema)\n\n // Configure the unified processor with an official plugin that defines how to take a syntax\n // tree as input and turn it into serialized HTML\n unifiedProcessor.use(rehypeStringify, {\n characterReferences: {\n // Compatibility with the previous implementation in Marked\n useNamedReferences: true,\n },\n })\n\n return {\n serialize(markdown: string) {\n return unifiedProcessor.processSync(markdown).toString()\n },\n }\n}\n\n/**\n * Object that holds multiple HTML serializer instances based on a given ID.\n */\nconst htmlSerializerInstanceById: HTMLSerializerInstanceById = {}\n\n/**\n * Returns a singleton instance of a HTML serializer based on the provided editor schema.\n *\n * @param schema The editor schema connected to the HTML serializer instance.\n *\n * @returns The HTML serializer instance for the given editor schema.\n */\nfunction getHTMLSerializerInstance(schema: Schema) {\n const id = computeSchemaId(schema)\n\n if (!htmlSerializerInstanceById[id]) {\n htmlSerializerInstanceById[id] = createHTMLSerializer(schema)\n }\n\n return htmlSerializerInstanceById[id]\n}\n\nexport { createHTMLSerializer, getHTMLSerializerInstance }\n\nexport type { HTMLSerializerReturnType }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAS,uCAAuC,QAAgB;CAC5D,OAAO,EACH,UAAU,UAAkB;EAIxB,IAAI,aAAa,OAAO,SAAS;EAGjC,OAAO,OAAO,OAAO,MAAM,CACtB,QAAQ,SAAS,KAAK,KAAK,SAAS,aAAa,CAAC,CAClD,SAAS,mBAAmB;GACzB,MAAM,aAAa,UAAU,eAAe,KAAK,QAAQ,eAAe,GAAG,CAAC;GAE5E,aAAa,WAAW,QACpB,IAAI,OAAO,wBAAwB,WAAW,wBAAwB,KAAK,EAC3E,cAAc,WAAW,uCAC5B;IACH;EAGN,OAAO,WAAW,QAAQ,sBAAsB,YAAY;IAEnE;;;;;;;;;;;AAYL,SAAS,qBAAqB,QAA0C;CAEpE,IAAI,oBAAoB,OAAO,EAC3B,OAAO,uCAAuC,OAAO;CAIzD,MAAM,mBAAmB,SAAS,CAAC,IAAI,YAAY;CAInD,iBAAiB,IAAI,yBAAyB,OAAO;CAKrD,IAAI,OAAO,MAAM,WACb,iBAAiB,IAAI,aAAa;CAKtC,IAAI,OAAO,MAAM,QACb,iBAAiB,IAAI,qBAAqB,EAAE,aAAa,OAAO,CAAC;CAKrE,IAAI,OAAO,MAAM,MACb,iBAAiB,IAAI,sBAAsB;CAM/C,iBACK,IAAI,cAAc,EAGf,oBAAoB,MACvB,CAAC,CAED,IAAI,wBAAwB,EAEzB,UAAU,MACb,CAAC;CAIN,IAAI,OAAO,MAAM,WACb,iBAAiB,IAAI,gBAAgB;CAKzC,IAAI,OAAO,MAAM,aAAa,OAAO,MAAM,OACvC,iBAAiB,IAAI,aAAa,OAAO;CAI7C,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UACtC,iBAAiB,IAAI,eAAe;CAIxC,iBAAiB,IAAI,mBAAmB,OAAO;CAI/C,iBAAiB,IAAI,iBAAiB,EAClC,qBAAqB,EAEjB,oBAAoB,MACvB,EACJ,CAAC;CAEF,OAAO,EACH,UAAU,UAAkB;EACxB,OAAO,iBAAiB,YAAY,SAAS,CAAC,UAAU;IAE/D;;;;;AAML,MAAM,6BAAyD,EAAE;;;;;;;;AASjE,SAAS,0BAA0B,QAAgB;CAC/C,MAAM,KAAK,gBAAgB,OAAO;CAElC,IAAI,CAAC,2BAA2B,KAC5B,2BAA2B,MAAM,qBAAqB,OAAO;CAGjE,OAAO,2BAA2B"}
1
+ {"version":3,"file":"html.js","names":[],"sources":["../../../src/serializers/html/html.ts"],"sourcesContent":["import { escape } from 'lodash-es'\nimport rehypeMinifyWhitespace from 'rehype-minify-whitespace'\nimport rehypeStringify from 'rehype-stringify'\nimport remarkBreaks from 'remark-breaks'\nimport remarkParse from 'remark-parse'\nimport remarkRehype from 'remark-rehype'\nimport { unified } from 'unified'\n\nimport { computeSchemaId, isPlainTextDocument } from '../../helpers/schema'\nimport {\n buildSuggestionSchemaInfo,\n computeSuggestionTriggerCharsId,\n} from '../../helpers/serializer'\n\nimport { rehypeCodeBlock } from './plugins/rehype-code-block'\nimport { rehypeImage } from './plugins/rehype-image'\nimport { rehypeSuggestions } from './plugins/rehype-suggestions'\nimport { rehypeTaskList } from './plugins/rehype-task-list'\nimport { remarkAutolinkLiteral } from './plugins/remark-autolink-literal'\nimport { remarkDisableConstructs } from './plugins/remark-disable-constructs'\nimport { remarkStrikethrough } from './plugins/remark-strikethrough'\n\nimport type { Schema } from '@tiptap/pm/model'\n\n/**\n * The return type for the `createHTMLSerializer` function.\n */\ntype HTMLSerializerReturnType = {\n /**\n * Serializes an input Markdown string to an output HTML string.\n *\n * @param markdown The Markdown string to serialize.\n *\n * @returns The serialized HTML.\n */\n serialize: (markdown: string) => string\n}\n\n/**\n * The type for the object that holds multiple HTML serializer instances.\n */\ntype HTMLSerializerInstanceById = {\n [id: string]: HTMLSerializerReturnType\n}\n\n/**\n * Create a custom Markdown to HTML serializer for plain-text editors only.\n *\n * @param schema The editor schema to be used for nodes and marks detection.\n *\n * @returns A normalized object for the HTML serializer.\n */\nfunction createHTMLSerializerForPlainTextEditor(schema: Schema) {\n return {\n serialize(markdown: string) {\n // Converts special characters (i.e. `&`, `<`, `>`, `\"`, and `'`) to their corresponding\n // HTML entities because we need to output the full content as valid HTML (i.e. the\n // editor should not drop invalid HTML).\n let htmlResult = escape(markdown)\n\n // Serialize all suggestion links if any suggestion node exists in the schema\n const suggestionSchemaInfo = buildSuggestionSchemaInfo(schema)\n\n if (suggestionSchemaInfo) {\n for (const [linkSchema, triggerChar] of suggestionSchemaInfo.triggerCharByScheme) {\n htmlResult = htmlResult.replace(\n new RegExp(`\\\\[([^\\\\[]+)\\\\]\\\\((?:${linkSchema}):\\\\/\\\\/([^\\\\s)]+)\\\\)`, 'gm'),\n (_, label, id) =>\n `<span data-${linkSchema} data-id=\"${id}\" data-label=\"${label}\">${triggerChar}${label}</span>`,\n )\n }\n }\n\n // Return the serialized HTML with every line wrapped in a paragraph element\n return htmlResult.replace(/^([^\\n]+)\\n?|\\n+/gm, `<p>$1</p>`)\n },\n }\n}\n\n/**\n * Create a Markdown to HTML serializer with the unified ecosystem for a rich-text editor, or use a\n * custom serializer for a plain-text editor. The editor schema is used to detect which nodes and\n * marks are available in the editor, and only parses the input with the minimal required plugins.\n *\n * @param schema The editor schema to be used for nodes and marks detection.\n *\n * @returns A normalized object for the HTML serializer.\n */\nfunction createHTMLSerializer(schema: Schema): HTMLSerializerReturnType {\n // Returns a custom HTML serializer for plain-text editors\n if (isPlainTextDocument(schema)) {\n return createHTMLSerializerForPlainTextEditor(schema)\n }\n\n // Initialize a unified processor with a remark plugin for parsing Markdown\n const unifiedProcessor = unified().use(remarkParse)\n\n // Configure the unified processor to use a custom plugin to disable constructs based on the\n // supported extensions that are enabled in the editor schema\n unifiedProcessor.use(remarkDisableConstructs, schema)\n\n // Configure the unified processor to use a third-party plugin to turn soft line endings into\n // hard breaks (i.e. `<br>`), which will display user content closer to how it was authored\n // (although not CommonMark compliant, this resembles the behaviour we always supported)\n if (schema.nodes.hardBreak) {\n unifiedProcessor.use(remarkBreaks)\n }\n\n // Configure the unified processor to use a custom plugin to add support for the strikethrough\n // extension from the GitHub Flavored Markdown (GFM) specification\n if (schema.marks.strike) {\n unifiedProcessor.use(remarkStrikethrough, { singleTilde: false })\n }\n\n // Configure the unified processor to use a custom plugin to add support for the autolink\n // literals extension from the GitHub Flavored Markdown (GFM) specification\n if (schema.marks.link) {\n unifiedProcessor.use(remarkAutolinkLiteral)\n }\n\n // Configure the unified processor with an official plugin to convert Markdown into HTML to\n // support rehype (a tool that transforms HTML with plugins), followed by another official\n // plugin to minify whitespace between tags (prevents line feeds from appearing as blank)\n unifiedProcessor\n .use(remarkRehype, {\n // Persist raw HTML (disables support for custom elements/tags)\n // ref: https://github.com/Doist/Issues/issues/5689\n allowDangerousHtml: true,\n })\n // This must come before all rehype plugins that transform the HTML output\n .use(rehypeMinifyWhitespace, {\n // Preserve line breaks when collapsing whitespace (e.g., line feeds)\n newlines: true,\n })\n\n // Configure the unified processor with a custom plugin to remove the trailing newline from code\n // blocks (i.e. the newline between the last code line and `</code></pre>`)\n if (schema.nodes.codeBlock) {\n unifiedProcessor.use(rehypeCodeBlock)\n }\n\n // Configure the unified processor with a custom plugin to remove the wrapping paragraph from\n // images and to remove all inline images based on inline images support in the editor schema\n if (schema.nodes.paragraph && schema.nodes.image) {\n unifiedProcessor.use(rehypeImage, schema)\n }\n\n // Configure the unified processor with a custom plugin to add support Tiptap task lists\n if (schema.nodes.taskList && schema.nodes.taskItem) {\n unifiedProcessor.use(rehypeTaskList)\n }\n\n // Configure the unified processor with a custom plugin to add support for suggestions nodes\n unifiedProcessor.use(rehypeSuggestions, schema)\n\n // Configure the unified processor with an official plugin that defines how to take a syntax\n // tree as input and turn it into serialized HTML\n unifiedProcessor.use(rehypeStringify, {\n characterReferences: {\n // Compatibility with the previous implementation in Marked\n useNamedReferences: true,\n },\n })\n\n return {\n serialize(markdown: string) {\n return unifiedProcessor.processSync(markdown).toString()\n },\n }\n}\n\n/**\n * Object that holds multiple HTML serializer instances based on a given ID.\n */\nconst htmlSerializerInstanceById: HTMLSerializerInstanceById = {}\n\n/**\n * Returns a singleton instance of a HTML serializer based on the provided editor schema.\n *\n * @param schema The editor schema connected to the HTML serializer instance.\n *\n * @returns The HTML serializer instance for the given editor schema.\n */\nfunction getHTMLSerializerInstance(schema: Schema) {\n const schemaId = computeSchemaId(schema)\n const triggerCharsId = computeSuggestionTriggerCharsId(schema)\n\n const id = [schemaId, triggerCharsId].join('|')\n\n if (!htmlSerializerInstanceById[id]) {\n htmlSerializerInstanceById[id] = createHTMLSerializer(schema)\n }\n\n return htmlSerializerInstanceById[id]\n}\n\nexport { createHTMLSerializer, getHTMLSerializerInstance }\n\nexport type { HTMLSerializerReturnType }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAoDA,SAAS,uCAAuC,QAAgB;CAC5D,OAAO,EACH,UAAU,UAAkB;EAIxB,IAAI,aAAa,OAAO,SAAS;EAGjC,MAAM,uBAAuB,0BAA0B,OAAO;EAE9D,IAAI,sBACA,KAAK,MAAM,CAAC,YAAY,gBAAgB,qBAAqB,qBACzD,aAAa,WAAW,QACpB,IAAI,OAAO,wBAAwB,WAAW,wBAAwB,KAAK,GAC1E,GAAG,OAAO,OACP,cAAc,WAAW,YAAY,GAAG,gBAAgB,MAAM,IAAI,cAAc,MAAM,SAC7F;EAKT,OAAO,WAAW,QAAQ,sBAAsB,YAAY;IAEnE;;;;;;;;;;;AAYL,SAAS,qBAAqB,QAA0C;CAEpE,IAAI,oBAAoB,OAAO,EAC3B,OAAO,uCAAuC,OAAO;CAIzD,MAAM,mBAAmB,SAAS,CAAC,IAAI,YAAY;CAInD,iBAAiB,IAAI,yBAAyB,OAAO;CAKrD,IAAI,OAAO,MAAM,WACb,iBAAiB,IAAI,aAAa;CAKtC,IAAI,OAAO,MAAM,QACb,iBAAiB,IAAI,qBAAqB,EAAE,aAAa,OAAO,CAAC;CAKrE,IAAI,OAAO,MAAM,MACb,iBAAiB,IAAI,sBAAsB;CAM/C,iBACK,IAAI,cAAc,EAGf,oBAAoB,MACvB,CAAC,CAED,IAAI,wBAAwB,EAEzB,UAAU,MACb,CAAC;CAIN,IAAI,OAAO,MAAM,WACb,iBAAiB,IAAI,gBAAgB;CAKzC,IAAI,OAAO,MAAM,aAAa,OAAO,MAAM,OACvC,iBAAiB,IAAI,aAAa,OAAO;CAI7C,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UACtC,iBAAiB,IAAI,eAAe;CAIxC,iBAAiB,IAAI,mBAAmB,OAAO;CAI/C,iBAAiB,IAAI,iBAAiB,EAClC,qBAAqB,EAEjB,oBAAoB,MACvB,EACJ,CAAC;CAEF,OAAO,EACH,UAAU,UAAkB;EACxB,OAAO,iBAAiB,YAAY,SAAS,CAAC,UAAU;IAE/D;;;;;AAML,MAAM,6BAAyD,EAAE;;;;;;;;AASjE,SAAS,0BAA0B,QAAgB;CAI/C,MAAM,KAAK,CAHM,gBAAgB,OAGb,EAFG,gCAAgC,OAEnB,CAAC,CAAC,KAAK,IAAI;CAE/C,IAAI,CAAC,2BAA2B,KAC5B,2BAA2B,MAAM,qBAAqB,OAAO;CAGjE,OAAO,2BAA2B"}
@@ -1,5 +1,5 @@
1
- import { isHastElementNode, isHastTextNode } from "../../../helpers/unified.js";
2
1
  import { buildSuggestionSchemaInfo } from "../../../helpers/serializer.js";
2
+ import { isHastElementNode, isHastTextNode } from "../../../helpers/unified.js";
3
3
  import { visit } from "unist-util-visit";
4
4
  //#region src/serializers/html/plugins/rehype-suggestions.ts
5
5
  /**
@@ -10,8 +10,8 @@ import { visit } from "unist-util-visit";
10
10
  function rehypeSuggestions(schema) {
11
11
  const suggestionSchemaInfo = buildSuggestionSchemaInfo(schema);
12
12
  if (!suggestionSchemaInfo) return (tree) => tree;
13
+ const suggestionSchemaRegex = new RegExp(`^${suggestionSchemaInfo.urlSchemeRegex}`);
13
14
  return (...[tree]) => {
14
- const suggestionSchemaRegex = new RegExp(`^${suggestionSchemaInfo.urlSchemeRegex}`);
15
15
  visit(tree, "element", (node) => {
16
16
  if (isHastElementNode(node, "a") && suggestionSchemaRegex.test(String(node.properties?.href))) {
17
17
  const [, urlScheme, id] = /^([a-z-]+):\/\/(\S+)$/i.exec(String(node.properties?.href)) || [];
@@ -1 +1 @@
1
- {"version":3,"file":"rehype-suggestions.js","names":[],"sources":["../../../../src/serializers/html/plugins/rehype-suggestions.ts"],"sourcesContent":["import { visit } from 'unist-util-visit'\n\nimport { buildSuggestionSchemaInfo } from '../../../helpers/serializer'\nimport { isHastElementNode, isHastTextNode } from '../../../helpers/unified'\n\nimport type { Schema } from '@tiptap/pm/model'\nimport type { Node as HastNode } from 'hast'\nimport type { Transformer } from 'unified'\n\n/**\n * A rehype plugin to add support for suggestions nodes (e.g., `@username` or `#channel).\n *\n * @param schema The editor schema to be used for suggestion nodes detection.\n */\nfunction rehypeSuggestions(schema: Schema): Transformer {\n const suggestionSchemaInfo = buildSuggestionSchemaInfo(schema)\n\n // Return the tree as-is if the editor does not support suggestions\n if (!suggestionSchemaInfo) {\n return (tree: HastNode) => tree\n }\n\n return (...[tree]: Parameters<Transformer>): ReturnType<Transformer> => {\n const suggestionSchemaRegex = new RegExp(`^${suggestionSchemaInfo.urlSchemeRegex}`)\n\n visit(tree, 'element', (node: HastNode) => {\n if (\n isHastElementNode(node, 'a') &&\n suggestionSchemaRegex.test(String(node.properties?.href))\n ) {\n const [, urlScheme, id] =\n /^([a-z-]+):\\/\\/(\\S+)$/i.exec(String(node.properties?.href)) || []\n\n // Replace the link element with a span containing the suggestion attributes,\n // keeping the visible label (prefixed with the trigger character) as text content\n // so the span renders correctly when used outside of an editor.\n if (urlScheme && id && isHastTextNode(node.children[0])) {\n const label = node.children[0].value\n\n // The URL scheme was matched against the regex built from the same map of\n // suggestion nodes, so the trigger character is guaranteed to exist\n const triggerChar = suggestionSchemaInfo.triggerCharByScheme.get(\n urlScheme,\n ) as string\n\n node.tagName = 'span'\n node.properties = {\n [`data-${urlScheme}`]: '',\n 'data-id': id,\n 'data-label': label,\n }\n node.children[0].value = `${triggerChar}${label}`\n }\n }\n })\n\n return tree\n }\n}\n\nexport { rehypeSuggestions }\n"],"mappings":";;;;;;;;;AAcA,SAAS,kBAAkB,QAA6B;CACpD,MAAM,uBAAuB,0BAA0B,OAAO;CAG9D,IAAI,CAAC,sBACD,QAAQ,SAAmB;CAG/B,QAAQ,GAAG,CAAC,UAA4D;EACpE,MAAM,wBAAwB,IAAI,OAAO,IAAI,qBAAqB,iBAAiB;EAEnF,MAAM,MAAM,YAAY,SAAmB;GACvC,IACI,kBAAkB,MAAM,IAAI,IAC5B,sBAAsB,KAAK,OAAO,KAAK,YAAY,KAAK,CAAC,EAC3D;IACE,MAAM,GAAG,WAAW,MAChB,yBAAyB,KAAK,OAAO,KAAK,YAAY,KAAK,CAAC,IAAI,EAAE;IAKtE,IAAI,aAAa,MAAM,eAAe,KAAK,SAAS,GAAG,EAAE;KACrD,MAAM,QAAQ,KAAK,SAAS,GAAG;KAI/B,MAAM,cAAc,qBAAqB,oBAAoB,IACzD,UACH;KAED,KAAK,UAAU;KACf,KAAK,aAAa;OACb,QAAQ,cAAc;MACvB,WAAW;MACX,cAAc;MACjB;KACD,KAAK,SAAS,GAAG,QAAQ,GAAG,cAAc;;;IAGpD;EAEF,OAAO"}
1
+ {"version":3,"file":"rehype-suggestions.js","names":[],"sources":["../../../../src/serializers/html/plugins/rehype-suggestions.ts"],"sourcesContent":["import { visit } from 'unist-util-visit'\n\nimport { buildSuggestionSchemaInfo } from '../../../helpers/serializer'\nimport { isHastElementNode, isHastTextNode } from '../../../helpers/unified'\n\nimport type { Schema } from '@tiptap/pm/model'\nimport type { Node as HastNode } from 'hast'\nimport type { Transformer } from 'unified'\n\n/**\n * A rehype plugin to add support for suggestions nodes (e.g., `@username` or `#channel).\n *\n * @param schema The editor schema to be used for suggestion nodes detection.\n */\nfunction rehypeSuggestions(schema: Schema): Transformer {\n const suggestionSchemaInfo = buildSuggestionSchemaInfo(schema)\n\n // Return the tree as-is if the editor does not support suggestions\n if (!suggestionSchemaInfo) {\n return (tree: HastNode) => tree\n }\n\n const suggestionSchemaRegex = new RegExp(`^${suggestionSchemaInfo.urlSchemeRegex}`)\n\n return (...[tree]: Parameters<Transformer>): ReturnType<Transformer> => {\n visit(tree, 'element', (node: HastNode) => {\n if (\n isHastElementNode(node, 'a') &&\n suggestionSchemaRegex.test(String(node.properties?.href))\n ) {\n const [, urlScheme, id] =\n /^([a-z-]+):\\/\\/(\\S+)$/i.exec(String(node.properties?.href)) || []\n\n // Replace the link element with a span containing the suggestion attributes,\n // keeping the visible label (prefixed with the trigger character) as text content\n // so the span renders correctly when used outside of an editor.\n if (urlScheme && id && isHastTextNode(node.children[0])) {\n const label = node.children[0].value\n\n // The URL scheme was matched against the regex built from the same map of\n // suggestion nodes, so the trigger character is guaranteed to exist\n const triggerChar = suggestionSchemaInfo.triggerCharByScheme.get(\n urlScheme,\n ) as string\n\n node.tagName = 'span'\n node.properties = {\n [`data-${urlScheme}`]: '',\n 'data-id': id,\n 'data-label': label,\n }\n node.children[0].value = `${triggerChar}${label}`\n }\n }\n })\n\n return tree\n }\n}\n\nexport { rehypeSuggestions }\n"],"mappings":";;;;;;;;;AAcA,SAAS,kBAAkB,QAA6B;CACpD,MAAM,uBAAuB,0BAA0B,OAAO;CAG9D,IAAI,CAAC,sBACD,QAAQ,SAAmB;CAG/B,MAAM,wBAAwB,IAAI,OAAO,IAAI,qBAAqB,iBAAiB;CAEnF,QAAQ,GAAG,CAAC,UAA4D;EACpE,MAAM,MAAM,YAAY,SAAmB;GACvC,IACI,kBAAkB,MAAM,IAAI,IAC5B,sBAAsB,KAAK,OAAO,KAAK,YAAY,KAAK,CAAC,EAC3D;IACE,MAAM,GAAG,WAAW,MAChB,yBAAyB,KAAK,OAAO,KAAK,YAAY,KAAK,CAAC,IAAI,EAAE;IAKtE,IAAI,aAAa,MAAM,eAAe,KAAK,SAAS,GAAG,EAAE;KACrD,MAAM,QAAQ,KAAK,SAAS,GAAG;KAI/B,MAAM,cAAc,qBAAqB,oBAAoB,IACzD,UACH;KAED,KAAK,UAAU;KACf,KAAK,aAAa;OACb,QAAQ,cAAc;MACvB,WAAW;MACX,cAAc;MACjB;KACD,KAAK,SAAS,GAAG,QAAQ,GAAG,cAAc;;;IAGpD;EAEF,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.d.ts","names":[],"sources":["../../../src/serializers/markdown/markdown.ts"],"mappings":";;;;;AAY8C;KAKzC,4BAAA;;;;AAqBmB;;;;EAbpB,SAAA,GAAY,IAAA;AAAA;;;;;;;;;;;;;;;;;iBAuEP,wBAAA,CAAyB,MAAA,EAAQ,MAAA,GAAS,4BAAA;;;;;;;;iBA+G1C,6BAAA,CAA8B,MAAA,EAAQ,MAAA,GAAM,4BAAA"}
1
+ {"version":3,"file":"markdown.d.ts","names":[],"sources":["../../../src/serializers/markdown/markdown.ts"],"mappings":";;;;;AAa8C;KAKzC,4BAAA;;;;AAqBmB;;;;EAbpB,SAAA,GAAY,IAAA;AAAA;;;;;;;;;;;;;;;;;iBAuEP,wBAAA,CAAyB,MAAA,EAAQ,MAAA,GAAS,4BAAA;;;;;;;;iBA6G1C,6BAAA,CAA8B,MAAA,EAAQ,MAAA,GAAM,4BAAA"}
@@ -1,4 +1,5 @@
1
1
  import { computeSchemaId, isPlainTextDocument } from "../../helpers/schema.js";
2
+ import { getSuggestionNodes } from "../../helpers/serializer.js";
2
3
  import { REGEX_PUNCTUATION } from "../../constants/regular-expressions.js";
3
4
  import { image } from "./plugins/image.js";
4
5
  import { listItem } from "./plugins/list-item.js";
@@ -61,7 +62,7 @@ function createMarkdownSerializer(schema) {
61
62
  if ((schema.nodes.bulletList || schema.nodes.orderedList) && schema.nodes.listItem) turndown.use(listItem(schema.nodes.listItem));
62
63
  if (schema.marks.strike) turndown.use(strikethrough(schema.marks.strike));
63
64
  if (schema.nodes.taskList && schema.nodes.taskItem) turndown.use(taskItem(schema.nodes.taskItem));
64
- Object.values(schema.nodes).filter((node) => node.name.endsWith("Suggestion")).forEach((suggestionNode) => {
65
+ getSuggestionNodes(schema).forEach((suggestionNode) => {
65
66
  turndown.use(suggestion(suggestionNode));
66
67
  });
67
68
  return { serialize(html) {
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.js","names":[],"sources":["../../../src/serializers/markdown/markdown.ts"],"sourcesContent":["import Turndown from 'turndown'\n\nimport { REGEX_PUNCTUATION } from '../../constants/regular-expressions'\nimport { computeSchemaId, isPlainTextDocument } from '../../helpers/schema'\n\nimport { image } from './plugins/image'\nimport { listItem } from './plugins/list-item'\nimport { paragraph } from './plugins/paragraph'\nimport { strikethrough } from './plugins/strikethrough'\nimport { suggestion } from './plugins/suggestion'\nimport { taskItem } from './plugins/task-item'\n\nimport type { Schema } from '@tiptap/pm/model'\n\n/**\n * The return type for the `createMarkdownSerializer` function.\n */\ntype MarkdownSerializerReturnType = {\n /**\n * Serializes an input HTML string to an output Markdown string.\n *\n * @param html The HTML string to serialize.\n *\n * @returns The serialized Markdown.\n */\n serialize: (html: string) => string\n}\n\n/**\n * The type for the object that holds multiple Markdown serializer instances.\n */\ntype MarkdownSerializerInstanceById = {\n [id: string]: MarkdownSerializerReturnType\n}\n\n/**\n * The bullet list marker for both standard and task list items.\n */\nconst BULLET_LIST_MARKER = '-'\n\n/**\n * Sensible default options to initialize the Turndown with.\n *\n * @see https://github.com/mixmark-io/turndown#options\n */\nconst INITIAL_TURNDOWN_OPTIONS: Turndown.Options = {\n headingStyle: 'atx',\n hr: '---',\n bulletListMarker: BULLET_LIST_MARKER,\n codeBlockStyle: 'fenced',\n fence: '```',\n emDelimiter: '*',\n strongDelimiter: '**',\n linkStyle: 'inlined',\n /**\n * Special rule to handle blank elements (overrides EVERY rule).\n *\n * @see https://github.com/mixmark-io/turndown#special-rules\n */\n blankReplacement(_, node) {\n const parentNode = node.parentNode as HTMLElement\n\n // Return the list marker for empty bullet list items\n if (node.nodeName === 'UL' || (parentNode?.nodeName === 'UL' && node.nodeName === 'LI')) {\n return `${BULLET_LIST_MARKER} \\n`\n }\n\n // Return the list marker for empty ordered list items\n if (node.nodeName === 'OL' || (parentNode?.nodeName === 'OL' && node.nodeName === 'LI')) {\n const start =\n node.nodeName === 'LI'\n ? parentNode.getAttribute('start')\n : node.getAttribute('start')\n const index = Array.prototype.indexOf.call(parentNode.children, node)\n\n return `${start ? Number(start) + index : index + 1}. \\n`\n }\n\n // @ts-ignore: The `Turndown.Node` type does not include `isBlock`\n return node.isBlock ? '\\n\\n' : ''\n },\n}\n\n/**\n * Create an HTML to Markdown serializer with the Turndown library for both a rich-text editor, and\n * a plain-text editor. The editor schema is used to detect which nodes and marks are available in\n * the editor, and only parses the input with the minimal required rules.\n *\n * **Note:** Unlike the HTML serializer, built-in rules that are not supported by the schema are not\n * disabled because if the schema does not support certain nodes/marks, the parsing rules don't have\n * valid HTML elements to match in the editor HTML output.\n *\n * @param schema The editor schema to be used for nodes and marks detection.\n *\n * @returns A normalized object for the Markdown serializer.\n */\nfunction createMarkdownSerializer(schema: Schema): MarkdownSerializerReturnType {\n // Initialize Turndown with custom options\n const turndown = new Turndown(INITIAL_TURNDOWN_OPTIONS)\n\n // Turndown ensures Markdown characters are escaped (i.e. `\\`) by default, so they are not\n // interpreted as Markdown when the output is compiled back to HTML. However, for plain-text\n // editors, we need to override the `escape` function to return the input as-is (effectively\n // disabling the escaping behaviour), so that all characters are interpreted as Markdown.\n if (isPlainTextDocument(schema)) {\n turndown.escape = (str) => str\n }\n\n // As for rich-text editors, we need to override the built-in escaping behaviour with a custom\n // implementation to suit our requirements. Please note that the `escape` function takes the\n // text content of each HTML element, with the exception of code elements, so we can be sure\n // that the escaping behaviour will only touch relevant Markdown characters.\n else {\n turndown.escape = (str) => {\n return (\n str\n // Escape all backslash characters that precede any punctuation marks, to\n // prevent the backslash itself from being interpreted as an escape sequence\n // for the subsequent character. It's important to apply this rule first to\n // avoid double escaping.\n .replace(new RegExp(`(\\\\\\\\${REGEX_PUNCTUATION.source})`, 'g'), '\\\\$1')\n\n // Although the CommonMark specification allows for bulleted or ordered lists\n // inside other bulleted or ordered lists (i.e. `- 1. - 1. Item`), the markup\n // generated by Markdown compilers is not supported by Tiptap, and we need to\n // make sure that text context that matches the ordered list syntax is\n // correctly escaped in order to be interpreted as text.\n .replace(/^(\\d+)\\.(\\s.+|$)/, '$1\\\\.$2')\n )\n }\n }\n\n // Overwrite some built-in rules for handling of special behaviours\n // (see documentation for each extension for more details)\n turndown.use(paragraph(schema.nodes.paragraph, isPlainTextDocument(schema)))\n\n // Overwrite the built-in `image` rule if the corresponding node exists in the schema\n if (schema.nodes.image) {\n turndown.use(image(schema.nodes.image))\n }\n\n // Overwrite the built-in `listItem` rule if the corresponding node exists in the schema\n if ((schema.nodes.bulletList || schema.nodes.orderedList) && schema.nodes.listItem) {\n turndown.use(listItem(schema.nodes.listItem))\n }\n\n // Add a rule for `strikethrough` if the corresponding node exists in the schema\n if (schema.marks.strike) {\n turndown.use(strikethrough(schema.marks.strike))\n }\n\n // Add a rule for `taskItem` if the corresponding nodes exists in the schema\n if (schema.nodes.taskList && schema.nodes.taskItem) {\n turndown.use(taskItem(schema.nodes.taskItem))\n }\n\n // Add a custom rule for all suggestion nodes available in the schema\n Object.values(schema.nodes)\n .filter((node) => node.name.endsWith('Suggestion'))\n .forEach((suggestionNode) => {\n turndown.use(suggestion(suggestionNode))\n })\n\n // Return a normalized `serialize` function\n return {\n serialize(html: string) {\n let markdownResult = html\n\n // Turndown was built to convert HTML into Markdown, expecting the input to be\n // standard-compliant HTML. As such, it collapses all whitespace by default, and there's\n // currently no way to opt-out of this behavior. However, for plain-text editors, we\n // need to preserve Markdown whitespace (otherwise we lose syntax like nested lists) by\n // replacing all instances of the space character (but only if it's preceded by another\n // space character) by the non-breaking space character, and after processing the input\n // with Turndown, we restore the original space character.\n if (isPlainTextDocument(schema)) {\n markdownResult = markdownResult.replace(/ {2,}/g, (m) => m.replace(/ /g, '\\u00a0'))\n }\n\n // Get the serialized Markdown parsed with Turndown\n markdownResult = turndown.turndown(markdownResult)\n\n // Restore the original space character for plain-text editors (as mentioned above),\n // after Markdown serialization has been performed\n if (isPlainTextDocument(schema)) {\n markdownResult = markdownResult.replace(/\\u00a0/g, ' ')\n }\n\n // Return the serialized Markdown parsed with Turndown, and with trailing space\n // characters removed\n return markdownResult.replace(/ +$/gm, '')\n },\n }\n}\n\n/**\n * Object that holds multiple Markdown serializer instances based on a given ID.\n */\nconst markdownSerializerInstanceById: MarkdownSerializerInstanceById = {}\n\n/**\n * Returns a singleton instance of a Markdown serializer based on the provided editor schema.\n *\n * @param schema The editor schema connected to the Markdown serializer instance.\n *\n * @returns The Markdown serializer instance for the given editor schema.\n */\nfunction getMarkdownSerializerInstance(schema: Schema) {\n const id = computeSchemaId(schema)\n\n if (!markdownSerializerInstanceById[id]) {\n markdownSerializerInstanceById[id] = createMarkdownSerializer(schema)\n }\n\n return markdownSerializerInstanceById[id]\n}\n\nexport { BULLET_LIST_MARKER, createMarkdownSerializer, getMarkdownSerializerInstance }\n\nexport type { MarkdownSerializerReturnType }\n"],"mappings":";;;;;;;;;;;;;;AA6CA,MAAM,2BAA6C;CAC/C,cAAc;CACd,IAAI;CACJ,kBAAA;CACA,gBAAgB;CAChB,OAAO;CACP,aAAa;CACb,iBAAiB;CACjB,WAAW;;;;;;CAMX,iBAAiB,GAAG,MAAM;EACtB,MAAM,aAAa,KAAK;EAGxB,IAAI,KAAK,aAAa,QAAS,YAAY,aAAa,QAAQ,KAAK,aAAa,MAC9E,OAAO;EAIX,IAAI,KAAK,aAAa,QAAS,YAAY,aAAa,QAAQ,KAAK,aAAa,MAAO;GACrF,MAAM,QACF,KAAK,aAAa,OACZ,WAAW,aAAa,QAAQ,GAChC,KAAK,aAAa,QAAQ;GACpC,MAAM,QAAQ,MAAM,UAAU,QAAQ,KAAK,WAAW,UAAU,KAAK;GAErE,OAAO,GAAG,QAAQ,OAAO,MAAM,GAAG,QAAQ,QAAQ,EAAE;;EAIxD,OAAO,KAAK,UAAU,SAAS;;CAEtC;;;;;;;;;;;;;;AAeD,SAAS,yBAAyB,QAA8C;CAE5E,MAAM,WAAW,IAAI,SAAS,yBAAyB;CAMvD,IAAI,oBAAoB,OAAO,EAC3B,SAAS,UAAU,QAAQ;MAQ3B,SAAS,UAAU,QAAQ;EACvB,OACI,IAKK,QAAQ,IAAI,OAAO,QAAQ,kBAAkB,OAAO,IAAI,IAAI,EAAE,OAAO,CAOrE,QAAQ,oBAAoB,UAAU;;CAOvD,SAAS,IAAI,UAAU,OAAO,MAAM,WAAW,oBAAoB,OAAO,CAAC,CAAC;CAG5E,IAAI,OAAO,MAAM,OACb,SAAS,IAAI,MAAM,OAAO,MAAM,MAAM,CAAC;CAI3C,KAAK,OAAO,MAAM,cAAc,OAAO,MAAM,gBAAgB,OAAO,MAAM,UACtE,SAAS,IAAI,SAAS,OAAO,MAAM,SAAS,CAAC;CAIjD,IAAI,OAAO,MAAM,QACb,SAAS,IAAI,cAAc,OAAO,MAAM,OAAO,CAAC;CAIpD,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UACtC,SAAS,IAAI,SAAS,OAAO,MAAM,SAAS,CAAC;CAIjD,OAAO,OAAO,OAAO,MAAM,CACtB,QAAQ,SAAS,KAAK,KAAK,SAAS,aAAa,CAAC,CAClD,SAAS,mBAAmB;EACzB,SAAS,IAAI,WAAW,eAAe,CAAC;GAC1C;CAGN,OAAO,EACH,UAAU,MAAc;EACpB,IAAI,iBAAiB;EASrB,IAAI,oBAAoB,OAAO,EAC3B,iBAAiB,eAAe,QAAQ,WAAW,MAAM,EAAE,QAAQ,MAAM,OAAS,CAAC;EAIvF,iBAAiB,SAAS,SAAS,eAAe;EAIlD,IAAI,oBAAoB,OAAO,EAC3B,iBAAiB,eAAe,QAAQ,WAAW,IAAI;EAK3D,OAAO,eAAe,QAAQ,SAAS,GAAG;IAEjD;;;;;AAML,MAAM,iCAAiE,EAAE;;;;;;;;AASzE,SAAS,8BAA8B,QAAgB;CACnD,MAAM,KAAK,gBAAgB,OAAO;CAElC,IAAI,CAAC,+BAA+B,KAChC,+BAA+B,MAAM,yBAAyB,OAAO;CAGzE,OAAO,+BAA+B"}
1
+ {"version":3,"file":"markdown.js","names":[],"sources":["../../../src/serializers/markdown/markdown.ts"],"sourcesContent":["import Turndown from 'turndown'\n\nimport { REGEX_PUNCTUATION } from '../../constants/regular-expressions'\nimport { computeSchemaId, isPlainTextDocument } from '../../helpers/schema'\nimport { getSuggestionNodes } from '../../helpers/serializer'\n\nimport { image } from './plugins/image'\nimport { listItem } from './plugins/list-item'\nimport { paragraph } from './plugins/paragraph'\nimport { strikethrough } from './plugins/strikethrough'\nimport { suggestion } from './plugins/suggestion'\nimport { taskItem } from './plugins/task-item'\n\nimport type { Schema } from '@tiptap/pm/model'\n\n/**\n * The return type for the `createMarkdownSerializer` function.\n */\ntype MarkdownSerializerReturnType = {\n /**\n * Serializes an input HTML string to an output Markdown string.\n *\n * @param html The HTML string to serialize.\n *\n * @returns The serialized Markdown.\n */\n serialize: (html: string) => string\n}\n\n/**\n * The type for the object that holds multiple Markdown serializer instances.\n */\ntype MarkdownSerializerInstanceById = {\n [id: string]: MarkdownSerializerReturnType\n}\n\n/**\n * The bullet list marker for both standard and task list items.\n */\nconst BULLET_LIST_MARKER = '-'\n\n/**\n * Sensible default options to initialize the Turndown with.\n *\n * @see https://github.com/mixmark-io/turndown#options\n */\nconst INITIAL_TURNDOWN_OPTIONS: Turndown.Options = {\n headingStyle: 'atx',\n hr: '---',\n bulletListMarker: BULLET_LIST_MARKER,\n codeBlockStyle: 'fenced',\n fence: '```',\n emDelimiter: '*',\n strongDelimiter: '**',\n linkStyle: 'inlined',\n /**\n * Special rule to handle blank elements (overrides EVERY rule).\n *\n * @see https://github.com/mixmark-io/turndown#special-rules\n */\n blankReplacement(_, node) {\n const parentNode = node.parentNode as HTMLElement\n\n // Return the list marker for empty bullet list items\n if (node.nodeName === 'UL' || (parentNode?.nodeName === 'UL' && node.nodeName === 'LI')) {\n return `${BULLET_LIST_MARKER} \\n`\n }\n\n // Return the list marker for empty ordered list items\n if (node.nodeName === 'OL' || (parentNode?.nodeName === 'OL' && node.nodeName === 'LI')) {\n const start =\n node.nodeName === 'LI'\n ? parentNode.getAttribute('start')\n : node.getAttribute('start')\n const index = Array.prototype.indexOf.call(parentNode.children, node)\n\n return `${start ? Number(start) + index : index + 1}. \\n`\n }\n\n // @ts-ignore: The `Turndown.Node` type does not include `isBlock`\n return node.isBlock ? '\\n\\n' : ''\n },\n}\n\n/**\n * Create an HTML to Markdown serializer with the Turndown library for both a rich-text editor, and\n * a plain-text editor. The editor schema is used to detect which nodes and marks are available in\n * the editor, and only parses the input with the minimal required rules.\n *\n * **Note:** Unlike the HTML serializer, built-in rules that are not supported by the schema are not\n * disabled because if the schema does not support certain nodes/marks, the parsing rules don't have\n * valid HTML elements to match in the editor HTML output.\n *\n * @param schema The editor schema to be used for nodes and marks detection.\n *\n * @returns A normalized object for the Markdown serializer.\n */\nfunction createMarkdownSerializer(schema: Schema): MarkdownSerializerReturnType {\n // Initialize Turndown with custom options\n const turndown = new Turndown(INITIAL_TURNDOWN_OPTIONS)\n\n // Turndown ensures Markdown characters are escaped (i.e. `\\`) by default, so they are not\n // interpreted as Markdown when the output is compiled back to HTML. However, for plain-text\n // editors, we need to override the `escape` function to return the input as-is (effectively\n // disabling the escaping behaviour), so that all characters are interpreted as Markdown.\n if (isPlainTextDocument(schema)) {\n turndown.escape = (str) => str\n }\n\n // As for rich-text editors, we need to override the built-in escaping behaviour with a custom\n // implementation to suit our requirements. Please note that the `escape` function takes the\n // text content of each HTML element, with the exception of code elements, so we can be sure\n // that the escaping behaviour will only touch relevant Markdown characters.\n else {\n turndown.escape = (str) => {\n return (\n str\n // Escape all backslash characters that precede any punctuation marks, to\n // prevent the backslash itself from being interpreted as an escape sequence\n // for the subsequent character. It's important to apply this rule first to\n // avoid double escaping.\n .replace(new RegExp(`(\\\\\\\\${REGEX_PUNCTUATION.source})`, 'g'), '\\\\$1')\n\n // Although the CommonMark specification allows for bulleted or ordered lists\n // inside other bulleted or ordered lists (i.e. `- 1. - 1. Item`), the markup\n // generated by Markdown compilers is not supported by Tiptap, and we need to\n // make sure that text context that matches the ordered list syntax is\n // correctly escaped in order to be interpreted as text.\n .replace(/^(\\d+)\\.(\\s.+|$)/, '$1\\\\.$2')\n )\n }\n }\n\n // Overwrite some built-in rules for handling of special behaviours\n // (see documentation for each extension for more details)\n turndown.use(paragraph(schema.nodes.paragraph, isPlainTextDocument(schema)))\n\n // Overwrite the built-in `image` rule if the corresponding node exists in the schema\n if (schema.nodes.image) {\n turndown.use(image(schema.nodes.image))\n }\n\n // Overwrite the built-in `listItem` rule if the corresponding node exists in the schema\n if ((schema.nodes.bulletList || schema.nodes.orderedList) && schema.nodes.listItem) {\n turndown.use(listItem(schema.nodes.listItem))\n }\n\n // Add a rule for `strikethrough` if the corresponding node exists in the schema\n if (schema.marks.strike) {\n turndown.use(strikethrough(schema.marks.strike))\n }\n\n // Add a rule for `taskItem` if the corresponding nodes exists in the schema\n if (schema.nodes.taskList && schema.nodes.taskItem) {\n turndown.use(taskItem(schema.nodes.taskItem))\n }\n\n // Add a custom rule for all suggestion nodes available in the schema\n getSuggestionNodes(schema).forEach((suggestionNode) => {\n turndown.use(suggestion(suggestionNode))\n })\n\n // Return a normalized `serialize` function\n return {\n serialize(html: string) {\n let markdownResult = html\n\n // Turndown was built to convert HTML into Markdown, expecting the input to be\n // standard-compliant HTML. As such, it collapses all whitespace by default, and there's\n // currently no way to opt-out of this behavior. However, for plain-text editors, we\n // need to preserve Markdown whitespace (otherwise we lose syntax like nested lists) by\n // replacing all instances of the space character (but only if it's preceded by another\n // space character) by the non-breaking space character, and after processing the input\n // with Turndown, we restore the original space character.\n if (isPlainTextDocument(schema)) {\n markdownResult = markdownResult.replace(/ {2,}/g, (m) => m.replace(/ /g, '\\u00a0'))\n }\n\n // Get the serialized Markdown parsed with Turndown\n markdownResult = turndown.turndown(markdownResult)\n\n // Restore the original space character for plain-text editors (as mentioned above),\n // after Markdown serialization has been performed\n if (isPlainTextDocument(schema)) {\n markdownResult = markdownResult.replace(/\\u00a0/g, ' ')\n }\n\n // Return the serialized Markdown parsed with Turndown, and with trailing space\n // characters removed\n return markdownResult.replace(/ +$/gm, '')\n },\n }\n}\n\n/**\n * Object that holds multiple Markdown serializer instances based on a given ID.\n */\nconst markdownSerializerInstanceById: MarkdownSerializerInstanceById = {}\n\n/**\n * Returns a singleton instance of a Markdown serializer based on the provided editor schema.\n *\n * @param schema The editor schema connected to the Markdown serializer instance.\n *\n * @returns The Markdown serializer instance for the given editor schema.\n */\nfunction getMarkdownSerializerInstance(schema: Schema) {\n const id = computeSchemaId(schema)\n\n if (!markdownSerializerInstanceById[id]) {\n markdownSerializerInstanceById[id] = createMarkdownSerializer(schema)\n }\n\n return markdownSerializerInstanceById[id]\n}\n\nexport { BULLET_LIST_MARKER, createMarkdownSerializer, getMarkdownSerializerInstance }\n\nexport type { MarkdownSerializerReturnType }\n"],"mappings":";;;;;;;;;;;;;;;AA8CA,MAAM,2BAA6C;CAC/C,cAAc;CACd,IAAI;CACJ,kBAAA;CACA,gBAAgB;CAChB,OAAO;CACP,aAAa;CACb,iBAAiB;CACjB,WAAW;;;;;;CAMX,iBAAiB,GAAG,MAAM;EACtB,MAAM,aAAa,KAAK;EAGxB,IAAI,KAAK,aAAa,QAAS,YAAY,aAAa,QAAQ,KAAK,aAAa,MAC9E,OAAO;EAIX,IAAI,KAAK,aAAa,QAAS,YAAY,aAAa,QAAQ,KAAK,aAAa,MAAO;GACrF,MAAM,QACF,KAAK,aAAa,OACZ,WAAW,aAAa,QAAQ,GAChC,KAAK,aAAa,QAAQ;GACpC,MAAM,QAAQ,MAAM,UAAU,QAAQ,KAAK,WAAW,UAAU,KAAK;GAErE,OAAO,GAAG,QAAQ,OAAO,MAAM,GAAG,QAAQ,QAAQ,EAAE;;EAIxD,OAAO,KAAK,UAAU,SAAS;;CAEtC;;;;;;;;;;;;;;AAeD,SAAS,yBAAyB,QAA8C;CAE5E,MAAM,WAAW,IAAI,SAAS,yBAAyB;CAMvD,IAAI,oBAAoB,OAAO,EAC3B,SAAS,UAAU,QAAQ;MAQ3B,SAAS,UAAU,QAAQ;EACvB,OACI,IAKK,QAAQ,IAAI,OAAO,QAAQ,kBAAkB,OAAO,IAAI,IAAI,EAAE,OAAO,CAOrE,QAAQ,oBAAoB,UAAU;;CAOvD,SAAS,IAAI,UAAU,OAAO,MAAM,WAAW,oBAAoB,OAAO,CAAC,CAAC;CAG5E,IAAI,OAAO,MAAM,OACb,SAAS,IAAI,MAAM,OAAO,MAAM,MAAM,CAAC;CAI3C,KAAK,OAAO,MAAM,cAAc,OAAO,MAAM,gBAAgB,OAAO,MAAM,UACtE,SAAS,IAAI,SAAS,OAAO,MAAM,SAAS,CAAC;CAIjD,IAAI,OAAO,MAAM,QACb,SAAS,IAAI,cAAc,OAAO,MAAM,OAAO,CAAC;CAIpD,IAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UACtC,SAAS,IAAI,SAAS,OAAO,MAAM,SAAS,CAAC;CAIjD,mBAAmB,OAAO,CAAC,SAAS,mBAAmB;EACnD,SAAS,IAAI,WAAW,eAAe,CAAC;GAC1C;CAGF,OAAO,EACH,UAAU,MAAc;EACpB,IAAI,iBAAiB;EASrB,IAAI,oBAAoB,OAAO,EAC3B,iBAAiB,eAAe,QAAQ,WAAW,MAAM,EAAE,QAAQ,MAAM,OAAS,CAAC;EAIvF,iBAAiB,SAAS,SAAS,eAAe;EAIlD,IAAI,oBAAoB,OAAO,EAC3B,iBAAiB,eAAe,QAAQ,WAAW,IAAI;EAK3D,OAAO,eAAe,QAAQ,SAAS,GAAG;IAEjD;;;;;AAML,MAAM,iCAAiE,EAAE;;;;;;;;AASzE,SAAS,8BAA8B,QAAgB;CACnD,MAAM,KAAK,gBAAgB,OAAO;CAElC,IAAI,CAAC,+BAA+B,KAChC,+BAA+B,MAAM,yBAAyB,OAAO;CAGzE,OAAO,+BAA+B"}
@@ -1,4 +1,4 @@
1
- import { kebabCase } from "lodash-es";
1
+ import { getSuggestionUrlScheme } from "../../../helpers/serializer.js";
2
2
  //#region src/serializers/markdown/plugins/suggestion.ts
3
3
  /**
4
4
  * A Turndown plugin which adds a custom rule for suggestion nodes created by the suggestion
@@ -7,7 +7,7 @@ import { kebabCase } from "lodash-es";
7
7
  * @param nodeType The node object that matches this rule.
8
8
  */
9
9
  function suggestion(nodeType) {
10
- const attributeType = kebabCase(nodeType.name.replace(/Suggestion$/, ""));
10
+ const attributeType = getSuggestionUrlScheme(nodeType);
11
11
  return (turndown) => {
12
12
  turndown.addRule(nodeType.name, {
13
13
  filter(node) {
@@ -1 +1 @@
1
- {"version":3,"file":"suggestion.js","names":[],"sources":["../../../../src/serializers/markdown/plugins/suggestion.ts"],"sourcesContent":["import { kebabCase } from 'lodash-es'\n\nimport type { NodeType } from '@tiptap/pm/model'\nimport type Turndown from 'turndown'\n\n/**\n * A Turndown plugin which adds a custom rule for suggestion nodes created by the suggestion\n * extension factory function.\n *\n * @param nodeType The node object that matches this rule.\n */\nfunction suggestion(nodeType: NodeType): Turndown.Plugin {\n const attributeType = kebabCase(nodeType.name.replace(/Suggestion$/, ''))\n\n return (turndown: Turndown) => {\n turndown.addRule(nodeType.name, {\n filter(node: Element) {\n return node.hasAttribute(`data-${attributeType}`)\n },\n replacement(_, node) {\n const label = String((node as Element).getAttribute('data-label'))\n const id = String((node as Element).getAttribute('data-id'))\n\n return `[${label}](${attributeType}://${id})`\n },\n })\n }\n}\n\nexport { suggestion }\n"],"mappings":";;;;;;;;AAWA,SAAS,WAAW,UAAqC;CACrD,MAAM,gBAAgB,UAAU,SAAS,KAAK,QAAQ,eAAe,GAAG,CAAC;CAEzE,QAAQ,aAAuB;EAC3B,SAAS,QAAQ,SAAS,MAAM;GAC5B,OAAO,MAAe;IAClB,OAAO,KAAK,aAAa,QAAQ,gBAAgB;;GAErD,YAAY,GAAG,MAAM;IAIjB,OAAO,IAHO,OAAQ,KAAiB,aAAa,aAAa,CAGjD,CAAC,IAAI,cAAc,KAFxB,OAAQ,KAAiB,aAAa,UAAU,CAEjB,CAAC;;GAElD,CAAC"}
1
+ {"version":3,"file":"suggestion.js","names":[],"sources":["../../../../src/serializers/markdown/plugins/suggestion.ts"],"sourcesContent":["import { getSuggestionUrlScheme } from '../../../helpers/serializer'\n\nimport type { NodeType } from '@tiptap/pm/model'\nimport type Turndown from 'turndown'\n\n/**\n * A Turndown plugin which adds a custom rule for suggestion nodes created by the suggestion\n * extension factory function.\n *\n * @param nodeType The node object that matches this rule.\n */\nfunction suggestion(nodeType: NodeType): Turndown.Plugin {\n const attributeType = getSuggestionUrlScheme(nodeType)\n\n return (turndown: Turndown) => {\n turndown.addRule(nodeType.name, {\n filter(node: Element) {\n return node.hasAttribute(`data-${attributeType}`)\n },\n replacement(_, node) {\n const label = String((node as Element).getAttribute('data-label'))\n const id = String((node as Element).getAttribute('data-id'))\n\n return `[${label}](${attributeType}://${id})`\n },\n })\n }\n}\n\nexport { suggestion }\n"],"mappings":";;;;;;;;AAWA,SAAS,WAAW,UAAqC;CACrD,MAAM,gBAAgB,uBAAuB,SAAS;CAEtD,QAAQ,aAAuB;EAC3B,SAAS,QAAQ,SAAS,MAAM;GAC5B,OAAO,MAAe;IAClB,OAAO,KAAK,aAAa,QAAQ,gBAAgB;;GAErD,YAAY,GAAG,MAAM;IAIjB,OAAO,IAHO,OAAQ,KAAiB,aAAa,aAAa,CAGjD,CAAC,IAAI,cAAc,KAFxB,OAAQ,KAAiB,aAAa,UAAU,CAEjB,CAAC;;GAElD,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@doist/typist",
3
3
  "description": "The mighty Tiptap-based rich-text editor React component that powers Doist products.",
4
- "version": "10.0.2",
4
+ "version": "10.0.3",
5
5
  "license": "MIT",
6
6
  "homepage": "https://typist.doist.dev/",
7
7
  "repository": {