@mdxeditor/editor 3.27.0 → 3.28.0

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 CHANGED
@@ -1047,6 +1047,11 @@ export declare const directivesPlugin: (params?: {
1047
1047
  * Use this to register your custom directive editors. You can also use the built-in {@link GenericDirectiveEditor}.
1048
1048
  */
1049
1049
  directiveDescriptors: DirectiveDescriptor<any>[];
1050
+ /**
1051
+ * Set this option to display unknown text-directives as normal text nodes.
1052
+ * This is handy when colons are used to separate words, e.g. in german "Schüler:in"
1053
+ */
1054
+ escapeUnknownTextDirectives?: boolean | undefined;
1050
1055
  } | undefined) => RealmPlugin;
1051
1056
 
1052
1057
  /**
@@ -1,20 +1,29 @@
1
+ import { $createTextNode } from "lexical";
1
2
  import { $createDirectiveNode } from "./DirectiveNode.js";
2
3
  const DIRECTIVE_TYPES = ["leafDirective", "containerDirective", "textDirective"];
3
4
  function isMdastDirectivesNode(node) {
4
5
  return DIRECTIVE_TYPES.includes(node.type);
5
6
  }
6
- const MdastDirectiveVisitor = {
7
+ const MdastDirectiveVisitor = (escapeUnknownTextDirectives) => ({
7
8
  testNode: (node, { directiveDescriptors }) => {
8
9
  if (isMdastDirectivesNode(node)) {
9
10
  const descriptor = directiveDescriptors.find((descriptor2) => descriptor2.testNode(node));
11
+ if (escapeUnknownTextDirectives && !descriptor && node.type === "textDirective") {
12
+ return true;
13
+ }
10
14
  return descriptor !== void 0;
11
15
  }
12
16
  return false;
13
17
  },
14
- visitNode({ lexicalParent, mdastNode }) {
15
- lexicalParent.append($createDirectiveNode(mdastNode));
18
+ visitNode({ lexicalParent, mdastNode, descriptors }) {
19
+ const isKnown = !escapeUnknownTextDirectives || descriptors.directiveDescriptors.some((d) => d.testNode(mdastNode));
20
+ if (isKnown) {
21
+ lexicalParent.append($createDirectiveNode(mdastNode));
22
+ } else {
23
+ lexicalParent.append($createTextNode(`:${mdastNode.name}`));
24
+ }
16
25
  }
17
- };
26
+ });
18
27
  export {
19
28
  MdastDirectiveVisitor,
20
29
  isMdastDirectivesNode
@@ -28,7 +28,7 @@ const directivesPlugin = realmPlugin({
28
28
  // import
29
29
  [addMdastExtension$]: directiveFromMarkdown(),
30
30
  [addSyntaxExtension$]: directive(),
31
- [addImportVisitor$]: MdastDirectiveVisitor,
31
+ [addImportVisitor$]: MdastDirectiveVisitor(params == null ? void 0 : params.escapeUnknownTextDirectives),
32
32
  // export
33
33
  [addLexicalNode$]: DirectiveNode,
34
34
  [addExportVisitor$]: DirectiveVisitor,
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "*.css"
12
12
  ],
13
13
  "type": "module",
14
- "version": "3.27.0",
14
+ "version": "3.28.0",
15
15
  "description": "React component for rich text markdown editing",
16
16
  "scripts": {
17
17
  "build": "vite build",