Skip to content

Commit 48d7319

Browse files
committed
Add LLM generation logic and tests
1 parent ca78f2b commit 48d7319

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/Elastic.Markdown/Myst/Renderers/LlmMarkdown/LlmBlockRenderers.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Elastic.Markdown.Myst.CodeBlocks;
77
using Elastic.Markdown.Myst.Directives;
88
using Elastic.Markdown.Myst.Directives.Admonition;
9+
using Elastic.Markdown.Myst.Directives.Diagram;
910
using Elastic.Markdown.Myst.Directives.Image;
1011
using Elastic.Markdown.Myst.Directives.Include;
1112
using Markdig.Extensions.DefinitionLists;
@@ -372,6 +373,9 @@ protected override void Write(LlmMarkdownRenderer renderer, DirectiveBlock obj)
372373
case IncludeBlock includeBlock:
373374
WriteIncludeBlock(renderer, includeBlock);
374375
return;
376+
case DiagramBlock diagramBlock:
377+
WriteDiagramBlock(renderer, diagramBlock);
378+
return;
375379
}
376380

377381
// Ensure single empty line before directive
@@ -417,6 +421,27 @@ private static void WriteImageBlock(LlmMarkdownRenderer renderer, ImageBlock ima
417421
renderer.EnsureLine();
418422
}
419423

424+
private static void WriteDiagramBlock(LlmMarkdownRenderer renderer, DiagramBlock diagramBlock)
425+
{
426+
renderer.EnsureBlockSpacing();
427+
428+
// Render diagram as structured comment with type information
429+
renderer.WriteLine($"<diagram type=\"{diagramBlock.DiagramType}\">");
430+
431+
// Render the diagram content with indentation
432+
if (!string.IsNullOrWhiteSpace(diagramBlock.Content))
433+
{
434+
var lines = diagramBlock.Content.Split(['\n', '\r'], StringSplitOptions.RemoveEmptyEntries);
435+
foreach (var line in lines)
436+
{
437+
renderer.WriteLine(line);
438+
}
439+
}
440+
441+
renderer.WriteLine("</diagram>");
442+
renderer.EnsureLine();
443+
}
444+
420445
private void WriteIncludeBlock(LlmMarkdownRenderer renderer, IncludeBlock block)
421446
{
422447
if (!block.Found || block.IncludePath is null)

tests/authoring/LlmMarkdown/LlmMarkdownOutput.fs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,3 +488,38 @@ Hello, this is a substitution: {{hello-world}}
488488
Hello, this is a substitution: Hello World!
489489
```
490490
"""
491+
492+
type ``diagram directive`` () =
493+
static let markdown = Setup.Document """
494+
::::{diagram} mermaid
495+
flowchart LR
496+
A[Start] --> B{Decision}
497+
B -->|Yes| C[Action 1]
498+
B -->|No| D[Action 2]
499+
C --> E[End]
500+
D --> E
501+
::::
502+
503+
::::{diagram} d2
504+
x -> y: hello world
505+
y -> z: nice to meet you
506+
::::
507+
"""
508+
509+
[<Fact>]
510+
let ``renders diagram with type information`` () =
511+
markdown |> convertsToNewLLM """
512+
<diagram type="mermaid">
513+
flowchart LR
514+
A[Start] --> B{Decision}
515+
B -->|Yes| C[Action 1]
516+
B -->|No| D[Action 2]
517+
C --> E[End]
518+
D --> E
519+
</diagram>
520+
521+
<diagram type="d2">
522+
x -> y: hello world
523+
y -> z: nice to meet you
524+
</diagram>
525+
"""

0 commit comments

Comments
 (0)