Skip to content

Comments

[RFC] Split markdown rendering to a separate package.#647

Draft
ditman wants to merge 14 commits intogoogle:mainfrom
ditman:inject-markdown-renderer-only
Draft

[RFC] Split markdown rendering to a separate package.#647
ditman wants to merge 14 commits intogoogle:mainfrom
ditman:inject-markdown-renderer-only

Conversation

@ditman
Copy link
Collaborator

@ditman ditman commented Feb 20, 2026

Description

This PR addresses some feedback on #595 by dropping some of the "implementation" packages for the markdown renderer, and directly using an injected renderMarkdown function if present. It adds some core types for the generic markdown renderer to be configured and injected.

It also updates the lit shell sample app to inject the pre-built renderer, to display how end-users will interact with this.

Pre-launch Checklist

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

@gemini-code-assist
Copy link
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

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.

Comment on lines +22 to +24
export const sanitizer = {
sanitize: (html: string) => html,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

security-critical critical

The sanitizer is currently a no-op, which poses a significant security risk as it allows un-sanitized HTML to be rendered. The TODO comment indicates this is an incomplete implementation. Raw HTML from the markdown source will be rendered without sanitization, which can lead to Cross-Site Scripting (XSS) vulnerabilities.

You should implement a proper HTML sanitizer, like DOMPurify as suggested by the TODO, to prevent XSS attacks. You will also need to add dompurify and its types (@types/dompurify) as dependencies to the package.json.

Suggested change
export const sanitizer = {
sanitize: (html: string) => html,
};
import DOMPurify from 'dompurify';
/**
* A sanitizer that sanitizes HTML.
*/
export const sanitizer = {
sanitize: (html: string) => DOMPurify.sanitize(html),
};

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good bot

Comment on lines +30 to +36
case 'html': {
const iframe = document.createElement('iframe');
iframe.classList.add('html-view');
iframe.srcdoc = str;
iframe.sandbox.add('');
return iframe.innerHTML;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The highlight function for HTML code blocks is using iframe.innerHTML, which will return an empty string. This is likely not the intended behavior. If the goal is to display a sandboxed preview of the HTML, you should probably be returning the iframe.outerHTML.

Additionally, using document.createElement will cause this code to fail in non-browser environments (e.g., during server-side rendering or in tests running in Node.js). Consider adding a check for the environment.

Suggested change
case 'html': {
const iframe = document.createElement('iframe');
iframe.classList.add('html-view');
iframe.srcdoc = str;
iframe.sandbox.add('');
return iframe.innerHTML;
}
case 'html': {
if (typeof document === 'undefined') {
return str; // Or escape it
}
const iframe = document.createElement('iframe');
iframe.classList.add('html-view');
iframe.srcdoc = str;
iframe.sandbox.add('');
return iframe.outerHTML;
}

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 in fact logic that probably should disappear. I don't think that an html tagged highlight is a good signal to attempt to render an iframe :/

// 3. Adjusting paths in package.json (main, types, exports) to be relative to dist/

const dirname = import.meta.dirname;
const corePkgPath = join(dirname, '../core/package.json');
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The path to corePkgPath is incorrect. It points to ../core/package.json, which would resolve to renderers/markdown/core/package.json. Based on the project structure, it should probably point to the web_core package at ../../web_core/package.json. This will cause the publish script to fail.

Suggested change
const corePkgPath = join(dirname, '../core/package.json');
const corePkgPath = join(dirname, '../../web_core/package.json');

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good bot

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.

2 participants