-
Notifications
You must be signed in to change notification settings - Fork 825
[RFC] Split markdown rendering to a separate package. #595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
ditman
left a comment
There was a problem hiding this 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>`; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import {markdownContext} from "./markdown.js"; | |
| import { markdownContext } from "./markdown.js"; |
? I need to setup some form of "format on save" or something I guess?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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??
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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 }) |
There was a problem hiding this comment.
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.
|
(Rebasing to resolve merge conflicts) |
…o the noop version.
6ac6fd5 to
ecf80b1
Compare
|
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. |
Description
This PR separates the
markdown-itdependency from thelitrenderer, by allowing users to@providea markdown renderer of their own.BREAKING CHANGE: By default, now incoming markdown is rendered as a
preelement, 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-configuredmarkdown-itinstance for all web renderers. This allows us to have a single configured markdown renderer withmarkdown-itanddompurify(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 tomarkdown-itlater, all packages get the new output at once.@a2ui/markdown-it-lit: the bridge package between thelitrenderer andmarkdown-it-shared. This is what people will use when using thelitrenderer to@providethemarkdownrenderer. They can also use this package as a jumping off point to create their own markdown renderer, if they prefer anything else other thanmarkdown-it.The
litsamples are updated to inject the new markdown renderer.The idea for this PR is to create an
@a2ui/markdown-it-angularpackage 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.