Skip to content

Commit 475addc

Browse files
authored
Fix duplicate content in table cells (#2339)
1 parent 0bb30ec commit 475addc

File tree

2 files changed

+116
-5
lines changed

2 files changed

+116
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,12 +382,13 @@ private static int[] CalculateColumnWidths(LlmMarkdownRenderer renderer, Table t
382382
private static string RenderTableCellContent(LlmMarkdownRenderer renderer, TableCell cell) =>
383383
DocumentationObjectPoolProvider.UseLlmMarkdownRenderer(
384384
renderer.BuildContext,
385-
cell.Descendants().OfType<Inline>(),
386-
static (tmpRenderer, obj) =>
385+
cell,
386+
static (tmpRenderer, c) =>
387387
{
388-
foreach (var inline in obj)
389-
tmpRenderer.Write(inline);
390-
});
388+
// Render the cell's child blocks (e.g., ParagraphBlock) which properly
389+
// handles the inline hierarchy without duplicating nested inline content
390+
tmpRenderer.WriteChildren(c);
391+
}).Trim();
391392
}
392393

393394
public class LlmDirectiveRenderer : MarkdownObjectRenderer<LlmMarkdownRenderer, DirectiveBlock>

tests/authoring/LlmMarkdown/LlmMarkdownOutput.fs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,3 +641,113 @@ Another setting description.
641641

642642
An advanced option.
643643
"""
644+
645+
type ``links in paragraphs`` () =
646+
static let markdown = Setup.Document """
647+
This is a paragraph with a [link to docs](https://www.elastic.co/docs/deploy-manage/security) in it.
648+
"""
649+
650+
[<Fact>]
651+
let ``renders links without duplication`` () =
652+
markdown |> convertsToNewLLM """This is a paragraph with a [link to docs](https://www.elastic.co/docs/deploy-manage/security) in it.
653+
"""
654+
655+
type ``links in tables`` () =
656+
static let markdown = Setup.Document """
657+
| Feature | Availability |
658+
|---------|--------------|
659+
| [Security configurations](https://www.elastic.co/docs/deploy-manage/security) | Full control |
660+
| [Authentication realms](https://www.elastic.co/docs/deploy-manage/users-roles) | Available |
661+
"""
662+
663+
[<Fact>]
664+
let ``renders links in table cells without duplication`` () =
665+
markdown |> convertsToNewLLM """
666+
| Feature | Availability |
667+
|--------------------------------------------------------------------------------|--------------|
668+
| [Security configurations](https://www.elastic.co/docs/deploy-manage/security) | Full control |
669+
| [Authentication realms](https://www.elastic.co/docs/deploy-manage/users-roles) | Available |
670+
"""
671+
672+
type ``multiple links in table cells`` () =
673+
static let markdown = Setup.Document """
674+
| Feature | Links |
675+
|---------|-------|
676+
| Security | [Config](https://example.com/config) and [Auth](https://example.com/auth) |
677+
"""
678+
679+
[<Fact>]
680+
let ``renders multiple links in same cell without duplication`` () =
681+
markdown |> convertsToNewLLM """
682+
| Feature | Links |
683+
|----------|---------------------------------------------------------------------------|
684+
| Security | [Config](https://example.com/config) and [Auth](https://example.com/auth) |
685+
"""
686+
687+
type ``links with formatting in tables`` () =
688+
static let markdown = Setup.Document """
689+
| Feature | Description |
690+
|---------|-------------|
691+
| [**Bold link**](https://example.com) | Description |
692+
| [*Italic link*](https://example.com/italic) | Another |
693+
"""
694+
695+
[<Fact>]
696+
let ``renders formatted links in table cells correctly`` () =
697+
markdown |> convertsToNewLLM """
698+
| Feature | Description |
699+
|---------------------------------------------|-------------|
700+
| [**Bold link**](https://example.com) | Description |
701+
| [*Italic link*](https://example.com/italic) | Another |
702+
"""
703+
704+
type ``bold and italic in tables`` () =
705+
static let markdown = Setup.Document """
706+
| Format | Example |
707+
|--------|---------|
708+
| Bold | This is **bold text** here |
709+
| Italic | This is *italic text* here |
710+
| Both | This is **bold** and *italic* |
711+
"""
712+
713+
[<Fact>]
714+
let ``renders bold and italic in table cells without duplication`` () =
715+
markdown |> convertsToNewLLM """
716+
| Format | Example |
717+
|--------|-------------------------------|
718+
| Bold | This is **bold text** here |
719+
| Italic | This is *italic text* here |
720+
| Both | This is **bold** and *italic* |
721+
"""
722+
723+
type ``code inline in tables`` () =
724+
static let markdown = Setup.Document """
725+
| Command | Description |
726+
|---------|-------------|
727+
| `git status` | Shows status |
728+
| `git commit` | Commits changes |
729+
"""
730+
731+
[<Fact>]
732+
let ``renders code inline in table cells correctly`` () =
733+
markdown |> convertsToNewLLM """
734+
| Command | Description |
735+
|--------------|-----------------|
736+
| `git status` | Shows status |
737+
| `git commit` | Commits changes |
738+
"""
739+
740+
type ``images in tables`` () =
741+
static let markdown = Setup.Document """
742+
| Icon | Name |
743+
|------|------|
744+
| ![logo](https://example.com/logo.png) | Logo |
745+
"""
746+
747+
[<Fact>]
748+
let ``renders images in table cells without duplication`` () =
749+
markdown |> convertsToNewLLM """
750+
| Icon | Name |
751+
|---------------------------------------|------|
752+
| ![logo](https://example.com/logo.png) | Logo |
753+
"""

0 commit comments

Comments
 (0)