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

Code block with language tabs #982

Closed
hsluoyz opened this issue Sep 25, 2018 · 10 comments
Closed

Code block with language tabs #982

hsluoyz opened this issue Sep 25, 2018 · 10 comments
Labels
difficulty: intermediate Issues that are medium difficulty level, e.g. moderate refactoring with a clear test plan. feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin.

Comments

@hsluoyz
Copy link
Contributor

hsluoyz commented Sep 25, 2018

🚀 Feature

Code block with language tabs

Have you read the Contributing Guidelines on issues?

Yes

Motivation

My project is a library. It supports four languages: Golang, Java, PHP and Node.js. So I need to show code in multiple languages in my documentation.

Pitch

I already noticed the discussion here: #103. But it seems to be a little hacky. I still want to know if there's any official decision on this feature or other third-party recommendations? Thanks.

@endiliey
Copy link
Contributor

There is the problem of syntax though. How do we divine code block with language tabs ? :o

@hsluoyz
Copy link
Contributor Author

hsluoyz commented Sep 26, 2018

A way to do it is to extend the markdown grammar to support it. Like said here, the text of the code block should be self-contained in the markdown instead of using external files. Then maybe we need to patch the markdown parser to support this new grammar. Javascript is then used to render it.

However, modifying markdown grammer is not always good. Another way is to put a placeholder like a reserved label <docusaurus-code-block-1> in markdown. Then define the code block #1 and its text in external files. The markdown parser won't need to be changed. Javascript can replace the label with actual code block controls in the HTML layer.

@hsluoyz
Copy link
Contributor Author

hsluoyz commented Oct 16, 2018

Hi, any update on this issue? @endiliey @yangshun

GitBook and readthedocs already support this feature:

  1. GitBook: https://github.com/GitbookIO/plugin-codetabs

image

  1. readthedocs: https://sphinxcontrib-contentui.readthedocs.io/en/latest/tabs.html

image

@JoelMarcey
Copy link
Contributor

@hsluoyz - we have a pull request in review that can add tabbing to a docs page. I imagine we could repurpose the final version of that to do something similar to what is being asked for here.

@JoelMarcey
Copy link
Contributor

@hsluoyz Also see #103 - as part of that, we are looking to adding code tabs too.

@hsluoyz
Copy link
Contributor Author

hsluoyz commented Oct 18, 2018

@JoelMarcey Thanks!

Never thought the PR will be so fast! We are really looking forward to this feature! I will test it first when the feature is ready :)

@endiliey
Copy link
Contributor

endiliey commented Nov 23, 2018

#1063 might be a better option (but we are still settling a nicer syntax, but overall the PR looks good)
cc @fiennyangeln

https://deploy-preview-1063--docusaurus-preview.netlify.com/docs/en/next/doc-markdown#code-tabs
image

@endiliey endiliey added feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin. difficulty: intermediate Issues that are medium difficulty level, e.g. moderate refactoring with a clear test plan. labels Nov 23, 2018
@hsluoyz
Copy link
Contributor Author

hsluoyz commented Nov 27, 2018

Thanks for the status update! This PR is really amazing! Cannot wait to try it :) @fiennyangeln @endiliey

@amimas
Copy link

amimas commented Feb 15, 2019

I believe tabbed code block is now supported on latest version

@hsluoyz
Copy link
Contributor Author

hsluoyz commented Feb 15, 2019

I will try it ASAP, close it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: intermediate Issues that are medium difficulty level, e.g. moderate refactoring with a clear test plan. feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin.
Projects
None yet
Development

No branches or pull requests

4 participants