Yuki Takei 1 год назад
Родитель
Сommit
2226879388

+ 38 - 0
apps/app/src/features/callout/services/callout.spec.ts

@@ -40,6 +40,7 @@ This is an info callout.
     assert('children' in calloutNode.children[0]);
     assert('value' in calloutNode.children[0].children[0]);
 
+    expect(calloutNode.children.length).toBe(1);
     expect(calloutNode.children[0].children[0].value).toBe('This is an info callout.');
   });
 
@@ -75,6 +76,43 @@ This is an info callout.
     assert('children' in calloutNode.children[0]);
     assert('value' in calloutNode.children[0].children[0]);
 
+    expect(calloutNode.children.length).toBe(1);
+    expect(calloutNode.children[0].children[0].value).toBe('This is an info callout.');
+  });
+
+  it('should transform containerDirective to callout with empty label', () => {
+    const processor = unified()
+      .use(remarkParse)
+      .use(remarkDirective)
+      .use(callout.remarkPlugin);
+
+    const markdown = `
+:::info[]
+This is an info callout.
+:::
+    `;
+
+    const tree = processor.parse(markdown);
+    processor.runSync(tree);
+
+    let calloutNode: ContainerDirective | undefined;
+    visit(tree, 'containerDirective', (node) => {
+      calloutNode = node;
+    });
+
+    expect(calloutNode).toBeDefined();
+
+    assert(calloutNode?.data?.hName != null);
+    assert(calloutNode?.data?.hProperties != null);
+
+    expect(calloutNode.data.hName).toBe('callout');
+    expect(calloutNode.data.hProperties.type).toBe('info');
+    expect(calloutNode.data.hProperties.label).toBe('info');
+
+    assert('children' in calloutNode.children[0]);
+    assert('value' in calloutNode.children[0].children[0]);
+
+    expect(calloutNode.children.length).toBe(1);
     expect(calloutNode.children[0].children[0].value).toBe('This is an info callout.');
   });
 });

+ 1 - 1
apps/app/src/features/callout/services/callout.ts

@@ -15,7 +15,7 @@ export const remarkPlugin: Plugin = () => {
         // extract directive label
         const paragraphs = (node.children ?? []).filter((child): child is Paragraph => child.type === 'paragraph');
         const paragraphForDirectiveLabel = paragraphs.find(p => p.data?.directiveLabel);
-        const label = paragraphForDirectiveLabel != null
+        const label = paragraphForDirectiveLabel != null && paragraphForDirectiveLabel.children.length > 0
           ? (paragraphForDirectiveLabel.children[0] as Text).value
           : undefined;
         // remove directive label from children