Skip to content
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

Add MarkdownString.supportsHtml api proposal #132182

Merged
merged 1 commit into from
Sep 3, 2021
Merged

Conversation

mjbvz
Copy link
Collaborator

@mjbvz mjbvz commented Sep 3, 2021

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

@mjbvz mjbvz added this to the September 2021 milestone Sep 3, 2021
@mjbvz mjbvz self-assigned this Sep 3, 2021
// 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
Collaborator Author

Choose a reason for hiding this comment

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

@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?

}
}

appendText(value: string, newlineStyle: MarkdownStringTextNewlineStyle = MarkdownStringTextNewlineStyle.Paragraph): MarkdownString {
this.value += escapeMarkdownSyntaxTokens(this.supportThemeIcons ? escapeIcons(value) : value)
.replace(/([ \t]+)/g, (_match, g1) => ' '.repeat(g1.length))
.replace(/^>/gm, '\\>')
.replace(/\>/gm, '\\>')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jrieken or @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
Member

Choose a reason for hiding this comment

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

lgtm

Copy link
Member

@jrieken jrieken left a comment

Choose a reason for hiding this comment

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

👯

}
}

appendText(value: string, newlineStyle: MarkdownStringTextNewlineStyle = MarkdownStringTextNewlineStyle.Paragraph): MarkdownString {
this.value += escapeMarkdownSyntaxTokens(this.supportThemeIcons ? escapeIcons(value) : value)
.replace(/([ \t]+)/g, (_match, g1) => ' '.repeat(g1.length))
.replace(/^>/gm, '\\>')
.replace(/\>/gm, '\\>')
Copy link
Member

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
@mjbvz mjbvz merged commit 8b7264a into main Sep 3, 2021
@mjbvz mjbvz deleted the dev/mjbvz/support-html branch September 3, 2021 19:33
@usernamehw
Copy link
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
Collaborator Author

mjbvz commented Sep 9, 2021

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