-
Notifications
You must be signed in to change notification settings - Fork 828
[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?
Changes from all commits
30b8e7a
36f4176
1307029
9427692
9de5c17
be3d984
92f4dbc
269094a
f1d6737
b46e5f6
89de7ed
8a8e527
ecf80b1
731bd50
63cdbaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||
| /* | ||||||
| Copyright 2025 Google LLC | ||||||
|
|
||||||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
| you may not use this file except in compliance with the License. | ||||||
| You may obtain a copy of the License at | ||||||
|
|
||||||
| https://www.apache.org/licenses/LICENSE-2.0 | ||||||
|
|
||||||
| Unless required by applicable law or agreed to in writing, software | ||||||
| distributed under the License is distributed on an "AS IS" BASIS, | ||||||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
| See the License for the specific language governing permissions and | ||||||
| limitations under the License. | ||||||
| */ | ||||||
|
|
||||||
| import {markdownContext} from "./markdown.js"; | ||||||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
? I need to setup some form of "format on save" or something I guess? |
||||||
| import {themeContext} from "./theme.js"; | ||||||
|
|
||||||
| export { | ||||||
| markdownContext as markdown, | ||||||
| themeContext as theme, | ||||||
| themeContext, // Preserved for backwards compatibility. Prefer using `theme`. | ||||||
| }; | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| Copyright 2025 Google LLC | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| https://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
| import { | ||
| DirectiveResult, | ||
| } from "lit/directive.js"; | ||
| import { createContext } from "@lit/context"; | ||
|
|
||
| /** | ||
| * A Lit Context to override the default (noop) markdown renderer. | ||
| */ | ||
| export const markdownContext = createContext<DirectiveResult>( | ||
| Symbol("a2ui-lit-markdown-renderer") | ||
| ); |
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is now probably redundant. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| Copyright 2025 Google LLC | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| https://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| import { html, TemplateResult } from "lit"; | ||
| import { | ||
| directive, | ||
| Directive, | ||
| } from "lit/directive.js"; | ||
|
|
||
| /** | ||
| * "Handles" Markdown rendering by doing nothing. | ||
| * | ||
| * Configure @a2ui/lit-markdown, or your custom Markdown renderer | ||
| * to actually parse and render Markdown in your app. | ||
| */ | ||
| class NoopMarkdownRendererDirective extends Directive { | ||
| render(markdown: string, _tagClassMap?: Record<string, string[]>) : TemplateResult { | ||
| return html`<pre>${markdown}</pre>`; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably |
||
| } | ||
| } | ||
|
|
||
| export const noopMarkdown = directive(NoopMarkdownRendererDirective); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,9 @@ | |
|
|
||
| import { html, css, nothing } from "lit"; | ||
| import { customElement, property } from "lit/decorators.js"; | ||
| import { markdown } from "./directives/directives.js"; | ||
| import { consume } from '@lit/context'; | ||
| import { noopMarkdown } from "./directives/noop_markdown.js"; | ||
| import * as Context from "./context/context.js"; | ||
| import { Root } from "./root.js"; | ||
| import { A2uiMessageProcessor } from "@a2ui/web_core/data/model-processor"; | ||
| import * as Primitives from "@a2ui/web_core/types/primitives"; | ||
|
|
@@ -44,6 +46,9 @@ export class Text extends Root { | |
| @property({ reflect: true, attribute: "usage-hint" }) | ||
| accessor usageHint: Types.ResolvedText["usageHint"] | null = null; | ||
|
|
||
| @consume({context: Context.markdown}) | ||
| accessor markdownRenderer = noopMarkdown; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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! |
||
|
|
||
| static styles = [ | ||
| structuralStyles, | ||
| css` | ||
|
|
@@ -116,8 +121,8 @@ export class Text extends Root { | |
| break; // Body. | ||
| } | ||
|
|
||
| return html`${markdown( | ||
| markdownText, | ||
| return html`${this.markdownRenderer( | ||
| markdownText, | ||
| Styles.appendToAll(this.theme.markdown, ["ol", "ul", "li"], {}) | ||
| )}`; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| This directory contains the default markdown implementations for A2UI. | ||
|
|
||
| * `markdown-it-shared` is a shared markdown renderer that uses markdown-it and | ||
| DOMPurify to render markdown content in general. | ||
| * `markdown-it-lit` is the Lit facade of the markdown renderer for Lit. | ||
| * `markdown-it-angular` is the Angular facade of the markdown renderer | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Haha, aspirational :P |
||
| for Angular. | ||
|
|
||
| Users should use the facade packages in their apps. There's nothing of interest | ||
| in the shared renderer package. | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Is this needed?) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| @a2ui:registry=https://us-npm.pkg.dev/oss-exit-gate-prod/a2ui--npm/ | ||
| //us-npm.pkg.dev/oss-exit-gate-prod/a2ui--npm/:always-auth=true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| A2UI markdown renderer for 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??