-
Notifications
You must be signed in to change notification settings - Fork 44
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
Translate markdown with angle brackets to HTML (fixes #476) #497
Conversation
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.
Hi @jcads, thank you for working on this issue. This solution looks like a great start, I have some input below.
I believe the cause of this bug is since <
and >
are reserved characters in HTML, the browser mistook <provider-name>
as an HTML tag. To fix this, we could use character entities to display these special characters instead.
For example, if we replace the special characters with their equivalent HTML entities, such as:
htmlText = text.replace("<", "<");
and then pass it to parse(htmlText)
, the browser would then be able to read "<".
Wondering what @wlach thinks about this approach. If this seems reasonable, should we also take care of the other edge cases, such as &
?
src/components/Markdown.svelte
Outdated
{#if text.includes('<')} | ||
{#if inline} | ||
{text} | ||
{:else} | ||
{#each lines as text} | ||
<p style="margin: 0">{text}</p> | ||
{/each} | ||
{/if} |
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.
We should always use parse/parseInline to render text
in this component as the goal is to display markdown content.
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.
Got it @Iinh. Thank you.
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.
Hi @jcads -- thanks for the PR I think this solution is not quite right. As @Iinh, we want to continue using parse/parseInline to render the text.
What's going on here is the markdown renderer is creating <provider-name>
as an HTML element. We can confirm this by looking at the developer console:
I think a shorter/cleaner solution would be to enhance the renderer object to escape these objects.
https://marked.js.org/using_pro#renderer
I think you might need to add a render for tag
types, but am not 100% sure. Give it a try and see!
Thanks @Iinh! This is actually a better approach than what I suggested. I think the markdown parser will automatically handle characters like |
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.
Looks great, thanks for persisting on this @jcads. Let me know if / when you're interested in working on something else.
This fixes pagination when navigating through long lists of metrics (the descriptions weren't being updated after #497)
This fixes pagination when navigating through long lists of metrics (the descriptions weren't being updated after #497)
PR #497 fixed some cases, but not all. Angle brackets in code blocks have their own escaping behaviour, which doesn't work well with the adhoc work we're doing. Strictly a string like this: <provider> is considered HTML in markdown. However this *probably* isn't how we want to interpret it in the Glean Dictionary. We'll address this by modifying the renderer when it encounters an HTML tag, rather than doing a naive regex replace against the whole markdown string.
This is pedantic, but strictly something called <provider-name> is considered an HTML tag unless it's in a code block (backticks). See mozilla/glean-dictionary#549 and mozilla/glean-dictionary#497. I'm going to fix this upstream but figured I might as well file a PR here to fix the underlying issue.
PR #497 fixed some cases, but not all. Angle brackets in code blocks have their own escaping behaviour, which doesn't work well with the adhoc work we're doing. Strictly a string like this: <provider> is considered HTML in markdown. However this *probably* isn't how we want to interpret it in the Glean Dictionary. We'll address this by modifying the renderer when it encounters an HTML tag, rather than doing a naive regex replace against the whole markdown string.
This is pedantic, but strictly something called <provider-name> is considered an HTML tag unless it's in a code block (backticks). See mozilla/glean-dictionary#549 and mozilla/glean-dictionary#497. I'm going to fix this upstream but figured I might as well file a PR here to fix the underlying issue.
…9243) This is pedantic, but strictly something called <provider-name> is considered an HTML tag unless it's in a code block (backticks). See mozilla/glean-dictionary#549 and mozilla/glean-dictionary#497. I'm going to fix this upstream but figured I might as well file a PR here to fix the underlying issue.
https://deploy-preview-497--glean-dictionary-dev.netlify.app/apps/fenix/metrics/browser_search_with_ads
![image](https://user-images.githubusercontent.com/50954098/113473000-5b716f80-9499-11eb-9c40-a184f65341df.png)
Fixes #476.
Pull Request checklist
fixes, if applicable)