Skip to content

feat(embed): render markdown in the app - #4334

Draft
josemontespg wants to merge 1 commit into
embed/4-buildfrom
embed/5-markdown
Draft

josemontespg wants to merge 1 commit into
embed/4-buildfrom
embed/5-markdown

Conversation

@josemontespg

@josemontespg josemontespg commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The basic catalog renders every body Text as markdown, but the app built by a2ui-embed build had no markdown renderer. Every view logged a [MarkdownDirective] warning and showed markdown as raw characters, which hurts tool UIs that show content like GitHub issue bodies.

The built app now renders markdown with @a2ui/markdown-it by default. startEmbedApp takes an optional markdown renderer and passes it to the basic catalog through its Lit context. The build config gets markdown: boolean (default true), and the generated entry passes renderMarkdown only when it is on. The choice lives at build time because only the build can leave the renderer out of the bundle: a runtime default would always import it. Without a renderer the app escapes the text, so markdown: false shows the text as typed without the warning.

Tool results are untrusted. renderMarkdown keeps raw HTML as text, drops javascript: links and sanitizes with DOMPurify, and images still follow the host CSP. The app now intercepts link clicks and opens http:, https: and mailto: links through ui/open-link, so a link never navigates the sandboxed frame.

Changes

  • startEmbedApp: new markdown option, provided through Context.markdown on the app root, with an escaping renderer when it is omitted. Clicks on links call app.openLink, or show a notice when the host lacks openLinks.
  • Build: markdown config option, validated as a boolean. The entry imports @a2ui/markdown-it resolved from @a2ui/embed, which now depends on it and on @lit/context.
  • Size of the basic-catalog app HTML: 807,915 bytes before, 967,515 bytes with markdown (+159,600), 810,263 bytes with markdown: false (+2,348).
  • Tests: karma tests for headings, lists, code and links without the warning, escaped raw HTML and dropped script links, link clicks sent to ui/open-link without navigation, the notice without openLinks, and plain text without a renderer. The build tests cover the option and its validation, the CSP test checks the renderer is passed, and the e2e test checks rendered markdown under the default MCP Apps CSP.
  • README and CHANGELOG.

Verification

  • yarn workspace @a2ui/embed test (clean wireit cache): node 165/165, karma 30/30.
  • yarn workspace @a2ui/embed lint, prettier on changed files, and ./scripts/fix_licenses.py --check pass.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces markdown rendering support to the A2UI embed app using @a2ui/markdown-it and @lit/context, along with a configurable option to disable it for smaller bundle sizes. It also intercepts link clicks to open them via the host's ui/open-link request instead of navigating the iframe. The review feedback highlights two key improvements: first, only calling event.preventDefault() when a link is actually openable by the host to prevent breaking default browser behaviors like anchor scrolling; second, replacing URL.canParse with a try/catch block around new URL() to maintain compatibility with older browsers.

Comment thread typescript/embed/src/mcp/links.ts Resolved
@josemontespg
josemontespg force-pushed the embed/5-markdown branch 2 times, most recently from 4349673 to 64e0d93 Compare November 26, 2026 01:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant