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

CodeBlock in React pages #6185

Closed
2 tasks done
Grafikart opened this issue Dec 24, 2021 · 2 comments · Fixed by #6216
Closed
2 tasks done

CodeBlock in React pages #6185

Grafikart opened this issue Dec 24, 2021 · 2 comments · Fixed by #6216
Labels
documentation The issue is related to the documentation of Docusaurus good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin. status: accepting pr This issue has been accepted, and we are looking for community contributors to implement this

Comments

@Grafikart
Copy link

Have you read the Contributing Guidelines on issues?

Description

It's possible to use block of code in markdown document but the documentation does not explain how to use the same feature in JSX page. Does docusaurus exposes a component for this kind of usage ?

It's possible to use the <Highlight> component from "prism-react-renderer" but we loose the styling and every configuration :(. If there is a component for this I'm willing to add this to the documentation myself

Self-service

  • I'd be willing to address this documentation request myself.
@Grafikart Grafikart added documentation The issue is related to the documentation of Docusaurus status: needs triage This issue has not been triaged by maintainers labels Dec 24, 2021
@Josh-Cena Josh-Cena removed the status: needs triage This issue has not been triaged by maintainers label Dec 24, 2021
@Josh-Cena
Copy link
Collaborator

Josh-Cena commented Dec 24, 2021

There was a brief mention here: https://docusaurus.io/docs/markdown-features/react#importing-code-snippets

But yes, we can make it more explicitly documented. If you want to document it on the "Code blocks" page, feel free to send a PR!

@Josh-Cena Josh-Cena changed the title CodeBlock in pages CodeBlock in React pages Dec 24, 2021
@Josh-Cena Josh-Cena added good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin. status: accepting pr This issue has been accepted, and we are looking for community contributors to implement this labels Dec 25, 2021
@slorber
Copy link
Collaborator

slorber commented Dec 28, 2021

Yes, this should work:

import CodeBlock from '@theme/CodeBlock';

export default function MyHomePage() {
  return (
    <CodeBlock className="language-bash">
      {"yarn install\nyarn start"}
    </CodeBlock>
  );
}

We still have some improvements left to do, as the original component was initially created for usage inside markdown.

For example we probably want a better language API:

-    <CodeBlock className="language-bash">
+    <CodeBlock language="bash">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation The issue is related to the documentation of Docusaurus good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin. status: accepting pr This issue has been accepted, and we are looking for community contributors to implement this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants