-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
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
fix(v2): treat inline code in raw HTML as native element #2857
Conversation
Deploy preview for docusaurus-2 ready! Built with commit e327d1b |
@@ -16,6 +16,9 @@ export default { | |||
code: (props) => { |
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.
I wonder why we even map code to CodeBlock in the first place. Endi did this in the first commit of this file. Any idea?
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.
Nope 🤷♂️
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.
This is what permits to transform ``` to the prism editor
@@ -16,6 +16,9 @@ export default { | |||
code: (props) => { | |||
const {children} = props; | |||
if (typeof children === 'string') { | |||
if (children.indexOf('\n') === -1) { |
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.
This makes sense. Suggestion:
if (!children.includes('\n')) {
...
}
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.
I did this because indexOf
is the fastest of them.
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.
@yangshun so should I replace indexOf
with includes
? Or can I leave first one?
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.
Yeah feel free. I think the perf difference here is negligible. I'd optimize for readability. But up to 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.
✔️
@slorber mayb we can merge this PR, release a new version and then the typescript cheatsheet website won't have this issue. |
Motivation
One of our users complained that inline code in raw HTML was not rendered correctly. I advised him to use Markdown syntax to define tables, to which he replied that in this case lists cannot be used. That's fair, raw HTML gives you more opportunities and flexibility, so we should take this into account.
I mean, inline code in raw HTML should be rendered using regular HTML element, rather
CodeBlock
component (see screenshots below).Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
In other words, after that inline code in tables defined in different ways (Markdown and HTML) are rendered identically.
Related PRs
(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)