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

fix(v2): treat inline code in raw HTML as native element #2857

Merged
merged 2 commits into from
Jun 3, 2020

Conversation

lex111
Copy link
Contributor

@lex111 lex111 commented Jun 1, 2020

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

<table>
  <tr>
    <th>Argument</th>
  </tr>
  <tr>
    <td><code>name</code></td>
  </tr>
</table>
Before After
Screenshot from 2020-06-01 13-35-52 image

In other words, after that inline code in tables defined in different ways (Markdown and HTML) are rendered identically.

| Argument |
| -------- |
| `name`   |

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.)

@lex111 lex111 added the pr: bug fix This PR fixes a bug in a past release. label Jun 1, 2020
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jun 1, 2020
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Jun 1, 2020

Deploy preview for docusaurus-2 ready!

Built with commit e327d1b

https://deploy-preview-2857--docusaurus-2.netlify.app

@lex111 lex111 requested a review from yangshun June 2, 2020 17:11
@@ -16,6 +16,9 @@ export default {
code: (props) => {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope 🤷‍♂️

Copy link
Collaborator

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) {
Copy link
Contributor

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')) {
  ...
}

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✔️

@yangshun
Copy link
Contributor

yangshun commented Jun 2, 2020

@slorber mayb we can merge this PR, release a new version and then the typescript cheatsheet website won't have this issue.

@slorber
Copy link
Collaborator

slorber commented Jun 2, 2020

Was working on the same thing at the same time ^^

I can confirm this solves the TS Cheatsheet use case. Also checked that single line code blocks get the editor and it seems to work too.

image

Not a fan of checking for newline but if it works then it's fine ;)

@slorber slorber self-requested a review June 2, 2020 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants