Skip to content

Split markdown rendering to a separate package.#647

Merged
ditman merged 31 commits intogoogle:mainfrom
ditman:inject-markdown-renderer-only
Mar 3, 2026
Merged

Split markdown rendering to a separate package.#647
ditman merged 31 commits intogoogle:mainfrom
ditman:inject-markdown-renderer-only

Conversation

@ditman
Copy link
Collaborator

@ditman ditman commented Feb 20, 2026

Description

This PR separates the markdown-it dependency from the lit and angular rendererers, by allowing users to inject their own markdown renderer.

Warning

BREAKING CHANGE: By default, now incoming markdown is rendered as a pre element, and users must inject a markdown renderer of their choosing for markdown to be rendered (see below).

In order to keep the "batteries" somewhat included in the sdk, a new package is introduced:

  • @a2ui/markdown-it: a pre-configured markdown-it instance for all web renderers. This allows us to have a single configured markdown renderer with markdown-it and dompurify that can be reused across all web packages. This is just a markdown string -> html string converter. (I liked/followed this naming convention)

The lit and angular restaurant samples are updated to inject the new markdown renderer.

Fixes

Tests

  • Added some unit tests to all new packages.

Pre-launch Checklist

If you need help, consider asking for advice on the discussion board.

Copy link
Collaborator

@jacobsimionato jacobsimionato left a comment

Choose a reason for hiding this comment

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

Hey thanks for iterating - this seems a lot lighter! It looks like angular support is gone, but ideally it will be possible to use this same shared interface/package for Angular?

@ditman ditman changed the title [RFC] [RFC] Split markdown rendering to a separate package. #595 [RFC] Split markdown rendering to a separate package. Feb 20, 2026
@ditman
Copy link
Collaborator Author

ditman commented Feb 21, 2026

/gemini review

Copy link
Contributor

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

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 effectively refactors the markdown rendering logic into a new shared package, @a2ui/markdown-it-shared. This is a positive step towards better code organization and reusability. The dependency injection approach for providing the markdown renderer in both Angular and Lit frameworks is well-executed.

However, I have identified a critical security vulnerability due to an incomplete sanitizer implementation in the new shared package. Additionally, there are a couple of bugs in the new package: one in the HTML highlighting logic and another in a build script, which could break the publishing process. My review includes specific comments and suggestions to address these issues.

@ditman ditman force-pushed the inject-markdown-renderer-only branch from 8df05c1 to b70a5eb Compare February 24, 2026 21:05
@ditman
Copy link
Collaborator Author

ditman commented Feb 24, 2026

/gemini review

@ditman ditman marked this pull request as ready for review February 24, 2026 21:10
Copy link
Contributor

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

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 is a great step towards improving the maintainability and consistency of markdown rendering by centralizing the logic into a new @a2ui/markdown-it-shared package. The use of dependency injection for the renderer in both Angular and Lit frameworks is well-executed. I've identified a couple of critical issues in the new shared markdown renderer that could lead to incorrect rendering and potential security vulnerabilities. Additionally, there are a few medium-severity suggestions to improve code clarity and adhere to best practices for library development. Overall, this is a valuable refactoring, and addressing these points will make it even more robust.

@google google deleted a comment from gemini-code-assist bot Feb 24, 2026
@ditman ditman force-pushed the inject-markdown-renderer-only branch from dfa0b28 to ec4ece9 Compare February 27, 2026 03:12
@ditman
Copy link
Collaborator Author

ditman commented Feb 27, 2026

/gemini review

Copy link
Contributor

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

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 refactors the markdown rendering logic by decoupling the markdown-it dependency from the lit and angular renderers and moving it into a new shared package, @a2ui/markdown-it-shared. This is a great architectural improvement that makes the renderers more modular and allows users to inject their own markdown implementation. The changes are well-implemented, including updates to the sample applications to use the new provider/context patterns. My review includes a few minor suggestions to improve code clarity and maintainability.

@jacobsimionato
Copy link
Collaborator

LGTM. I wonder if the package should be called a2ui-markdown-it or something? Not sure if 'shared' is needed in there?

@ditman
Copy link
Collaborator Author

ditman commented Mar 2, 2026

LGTM. I wonder if the package should be called a2ui-markdown-it or something? Not sure if 'shared' is needed in there?

I really like that name, I'll rename the package ASAP. shared is a leftover from when I had shared but also angular and lit versions. Great call!

ditman added 24 commits March 2, 2026 11:22
@ditman ditman force-pushed the inject-markdown-renderer-only branch from f66f276 to ffec1e3 Compare March 2, 2026 19:32
@ditman ditman changed the title [RFC] Split markdown rendering to a separate package. Split markdown rendering to a separate package. Mar 2, 2026
@ditman
Copy link
Collaborator Author

ditman commented Mar 2, 2026

OK, I'm landing this once @jacobsimionato comes online :P

@ditman ditman merged commit 72d9894 into google:main Mar 3, 2026
8 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in A2UI Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Figure out how to resolve Markdown dependency in OSS and google repository

2 participants