Skip to content

Conversation

@ditman
Copy link
Collaborator

@ditman ditman commented Feb 4, 2026

Description

This PR separates the markdown-it dependency from the lit renderer, by allowing users to @provide a markdown renderer of their own.

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 couple of new packages are introduced:

  • @a2ui/markdown-it-shared: the pre-configured markdown-it instance for all web renderers. This allows us to have a single configured markdown renderer with markdown-it and dompurify (TBD) that can be reused across all packages. This is pretty much a markdown string -> html string converter, but if we want to add plugins to markdown-it later, all packages get the new output at once.
  • @a2ui/markdown-it-lit: the bridge package between the lit renderer and markdown-it-shared. This is what people will use when using the lit renderer to @provide the markdown renderer. They can also use this package as a jumping off point to create their own markdown renderer, if they prefer anything else other than markdown-it.

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

The idea for this PR is to create an @a2ui/markdown-it-angular package to bridge the gap in the angular renderer. I haven't checked how to inject the renderer in angular, but I expect angular to have some DI mechanism that we're already leveraging.

Fixes

Tests

The new packages need some tests, that may already exist (and break) in the current lit renderer package. I just didn't have time to set those up yet, but will do before landing this, if we like this approach.

Pre-launch Checklist

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

Copy link
Collaborator Author

@ditman ditman left a comment

Choose a reason for hiding this comment

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

I posted some comments to guide through the PR, and maybe start some discussions. PTAL!

*/
class NoopMarkdownRendererDirective extends Directive {
render(markdown: string, _tagClassMap?: Record<string, string[]>) : TemplateResult {
return html`<pre>${markdown}</pre>`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should probably console.warn once to let users know that they need to use @a2ui/markdown-it-lit, and maybe link to some documentation site.


import { googleAI } from "@genkit-ai/google-genai";
import { configure } from "genkit";
import {markdownContext} from "./markdown.js";
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
import {markdownContext} from "./markdown.js";
import { markdownContext } from "./markdown.js";

? I need to setup some form of "format on save" or something I guess?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This file is now probably redundant.

accessor usageHint: Types.ResolvedText["usageHint"] | null = null;

@consume({context: Context.markdown})
accessor markdownRenderer = noopMarkdown;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not to toot my own horn, but this ended up looking quite nice. I like Lit!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can we stop comitting the lockfiles to the repo? They add a lot of noise and can cause unnecessary merge trouble! Any advantage of checking this in??

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't understand why am I getting these .JSON updates, is my branch too old? Is this being updated off of master, instead of the contents of my branch?

Updating off of master sounds dangerous.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changes to this file are 100% cosmetic, just because I thought I had broken the contact example with my markdown changes (turns out I hadn't, but it rubbed me the wrong way)... I can remove this from this PR since it's not too related!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the gist of the "integration" for Lit users, I think it turned out fairly simple, but still it's a breaking change with the previous version of the package, unfortunately.

export class A2UILayoutEditor extends SignalWatcher(LitElement) {
@provide({ context: UI.Context.themeContext })
accessor theme: v0_8.Types.Theme = uiTheme;
@provide({ context: UI.Context.theme })
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renaming UI.Context.themeContext to UI.Context.theme is also a breaking change, but IMO it improves legibility a little bit (especially now that there's more than one inhabitant in the UI.Context namespace.

@ditman
Copy link
Collaborator Author

ditman commented Feb 4, 2026

(Rebasing to resolve merge conflicts)

@ditman ditman force-pushed the inject-markdown-rendering branch from 6ac6fd5 to ecf80b1 Compare February 4, 2026 19:01
@ditman ditman mentioned this pull request Feb 4, 2026
@ditman
Copy link
Collaborator Author

ditman commented Feb 4, 2026

I had to tweak the build script task a little bit to ensure the new packages I added as path dependencies for the lit renderer are being built.

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

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

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

1 participant