Skip to content

Enhance LLM readable markdown rendering - #1569

Merged
reakaleek merged 26 commits into
mainfrom
feature/llm-markdown-renderer
Jul 18, 2025
Merged

reakaleek merged 26 commits into
mainfrom
feature/llm-markdown-renderer

Conversation

@reakaleek

@reakaleek reakaleek commented Jul 16, 2025 •

Copy link
Copy Markdown
Member

Closes #1504
Closes https://github.com/elastic/docs-eng-team/issues/161

Changes

This adds a new LlmMarkdownRenderer that extends Markdig's TextRendererBase.
Hence, we can take an existing MarkdownDocument and render it with our new custom renderer.

Notes

The markdown is accessible in local serve, on previews as well as assembler builds.
You just need to append .md to the current URL.

Preview

https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/1569/syntax/quick-ref.md

@reakaleek reakaleek changed the title Add new LLM markdown renderer WIP: Add new LLM markdown renderer Jul 17, 2025
@reakaleek
reakaleek force-pushed the feature/llm-markdown-renderer branch from 4ae0f36 to 89e9732 Compare July 17, 2025 09:45
@reakaleek reakaleek self-assigned this Jul 17, 2025
@reakaleek
reakaleek marked this pull request as ready for review July 17, 2025 11:38
@reakaleek
reakaleek requested a review from a team as a code owner July 17, 2025 11:38
@reakaleek reakaleek changed the title WIP: Add new LLM markdown renderer Enhance LLM readable markdown rendering Jul 17, 2025

@Mpdreamz Mpdreamz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! One nit around object pooling.

Did not go into output too much, we can update that as we continue to work closer with other teams.

{
await DocumentationSet.Tree.Resolve(ctx);
var document = await markdown.ParseFullAsync(ctx);
await using var writer = new StringWriter();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an object pool for stringwriters and stringbuilders and htmlrenderes which can drastically help reduce allocation e.g:

See:

var stringBuilder = StringBuilderPool.Get();
using var stringWriter = StringWriterPool.Get();
stringWriter.SetStringBuilder(stringBuilder);

For a usage example see:

var subscription = DocumentationObjectPoolProvider.HtmlRendererPool.Get();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to create a LlmMarkdownRenderer object pool based on the existing HtmlRenderSubscription.

Unfortunately, I don't think it will work because I have the BuildContext as property on the LlmMarkdownRenderer.

But I guess I can still use it for StringWriter or StringBuilder.

WIP.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I just noticed, what I did is not enough. I need to return the object.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I think I got it right now.

f975abd

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK OK. Now I think it's nice. 9e5d96d

@reakaleek
reakaleek requested a review from Mpdreamz July 17, 2025 22:45
@reakaleek
reakaleek force-pushed the feature/llm-markdown-renderer branch from 7b51b3e to b6d8419 Compare July 17, 2025 22:54

@Mpdreamz Mpdreamz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On ultra nitpick but LGTM!

@reakaleek
reakaleek enabled auto-merge (squash) July 18, 2025 11:37
@reakaleek
reakaleek merged commit d1b66f5 into main Jul 18, 2025
@reakaleek
reakaleek deleted the feature/llm-markdown-renderer branch July 18, 2025 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown doesn't match HTML

2 participants