Skip to content

Add MarkdownString.supportsHtml api proposal - #132182

Merged
Matt Bierner (mjbvz) merged 1 commit into
mainfrom
dev/mjbvz/support-html
Sep 3, 2021
Merged

Matt Bierner (mjbvz) merged 1 commit into
mainfrom
dev/mjbvz/support-html

Conversation

@mjbvz

@mjbvz Matt Bierner (mjbvz) commented Sep 3, 2021 •

Copy link
Copy Markdown
Contributor

For #40607

This change introduces a new supportsHtml property on MarkdownString that can be used to enable rendering of a safe subset of tags and attributes inside of markdown strings

For backwards compatability, supportsHtml will default to false and must be explicitly enabled by extensions

This PR will need to go in after we adopt dompurify (#131950) which should provide better control over how we actually go about sanitizing rendered html

// If we want to allow markdown permitted tags, then we can delete sanitizer and sanitize.
// We always pass the output through insane after this so that we don't rely on
// marked for sanitization.
markedOptions.sanitizer = (html: string): string => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alex Ross (@alexr00) Are you aware of any extensions besides GitHub PR that use spans in markdown? Would Github PR be able to adopt supportHtml so that we can remove our customize sanitizer here?

this.value += escapeMarkdownSyntaxTokens(this.supportThemeIcons ? escapeIcons(value) : value)
.replace(/([ \t]+)/g, (_match, g1) => ' '.repeat(g1.length))
.replace(/^>/gm, '\\>')
.replace(/\>/gm, '\\>')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Johannes Rieken (@jrieken) or Eric Amodio (@eamodio) I changed this regex to escape closing > because that looked like what the code intended to do. Please let me know if the original regex was written this way for a reason

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@jrieken Johannes Rieken (jrieken) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👯

this.value += escapeMarkdownSyntaxTokens(this.supportThemeIcons ? escapeIcons(value) : value)
.replace(/([ \t]+)/g, (_match, g1) => ' '.repeat(g1.length))
.replace(/^>/gm, '\\>')
.replace(/\>/gm, '\\>')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

Fixes #40607

This change introduces a new `supportsHtml` property on `MarkdownString` that can be used to enable rendering of a safe subset of tags and attributes inside of markdown strings

For backwards compatibility, `supportsHtml` will default to false and must be explicitly enabled by extensions

This PR will need to go in after we adopt dompurify (#131950) which should provide better control over how we actually go about sanitizing rendered html
@usernamehw

Copy link
Copy Markdown
Contributor

Would this change (or dompurify PR) make it easier to support more styling properties on <span>?

Properties like border, border-radius, padding.

@mjbvz

Copy link
Copy Markdown
Contributor Author

Not really. If we want to support a subset of css styles, we'd need a good css sanitizer as well. Right now we only support one or two a very specific style strings

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants