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

[Enhancement] Improved code blocks #103

Closed
3 tasks
hramos opened this issue Sep 30, 2017 · 8 comments
Closed
3 tasks

[Enhancement] Improved code blocks #103

hramos opened this issue Sep 30, 2017 · 8 comments
Labels
difficulty: advanced Issues that are complex, e.g. large scoping for long-term maintainability. feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. status: claimed Issue has been claimed by a contributor who plans to work on it.

Comments

@hramos
Copy link
Contributor

hramos commented Sep 30, 2017

In this issue I want to collect some ideas for improving our fenced code block widget. 1.0 will launch without this.

(There may be other ideas for features to implement in this issue facebook/react#10991)

@hramos hramos changed the title Code blocks with language selectors Improved code blocks Oct 3, 2017
@hramos hramos mentioned this issue Oct 3, 2017
3 tasks
@hramos hramos changed the title Improved code blocks [Enhancement] Improved code blocks Oct 19, 2017
@JoelMarcey JoelMarcey added the feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. label Oct 24, 2017
@JoelMarcey JoelMarcey reopened this Oct 30, 2017
@Glavin001
Copy link
Contributor

What would be a good syntax for code blocks with language toggling?

image

I am very interesting in trying to make a Pull Request for this. Before I get started, I'd appreciate some collaboration on the design :).

@ForbesLindesay
Copy link
Contributor

I like the idea of just having multiple code blocks, one after another, with no text between them:

screen shot 2018-03-02 at 18 10 12

@stevenzeck
Copy link
Contributor

A toggle would be very helpful. The one in the parse docs is great if you have a small list of languages, but if you have more than 5 it's hard to make it work. Perhaps use that if the number of languages is 3 or fewer and a select list otherwise?

@jonathaningram
Copy link
Contributor

jonathaningram commented Jun 19, 2018

I actually hacked together a plugin called "file tabs" to do this. I just wanted to use docusaurus to quickly prototype something, so the plugin was meant to be quick and dirty. Source is here: https://github.com/govau/platforms-alpha/blob/master/lib/shared/fileTabs.js

Install into your site like this: https://github.com/govau/platforms-alpha/blob/master/tell/website/siteConfig.js#L52

And here's how you use it in your .md file:

```filetabs
file=website/blog/2018-06-13-docusaurus-file-tabs-plugin/example.cs lang=csharp label=C#
file=website/blog/2018-06-13-docusaurus-file-tabs-plugin/example.go lang=go label=Go
file=website/blog/2018-06-13-docusaurus-file-tabs-plugin/example.inline parser=md label=Java
file=website/blog/2018-06-13-docusaurus-file-tabs-plugin/example.js lang=js label=Node.js
file=website/blog/2018-06-13-docusaurus-file-tabs-plugin/example.php lang=php label=PHP
file=website/blog/2018-06-13-docusaurus-file-tabs-plugin/example.py lang=python label=Python
file=website/blog/2018-06-13-docusaurus-file-tabs-plugin/example.rb lang=ruby label=Ruby
```

And how it ends up looking:

image

image

Edit:

One problem as it stands is that this doesn't account for versioning:

  1. docs/** are not copied when versioning. Hoping that Enable sub-directories in docs/  #705 resolves this
  2. the versioned_docs/**/*.md files are going to have filetabs fences that refer to the latest/master set of files. Need to figure out how this would be handled. Ideally filetabs would work by having files be relative to the current file, but from memory when I tried doing that originally it didn't work and I needed to make the file relative to the project root.

@yangshun
Copy link
Contributor

@jonathaningram This looks amazing! I also like that the code is stored outside of the Markdown file. We'll look into including it! 😄

@yangshun yangshun added the difficulty: advanced Issues that are complex, e.g. large scoping for long-term maintainability. label Jun 19, 2018
@jonathaningram
Copy link
Contributor

@yangshun thanks! Yeah we'd probably publish as an npm package and then it could just be imported like any other old package, but for my case I didn't want to bother publishing a new package so I just needed to hack together a way to import it from multiple docusaurus instances.

And of course the tabs HTML and CSS would need to be cleaned up, verify accessibility, and so on.

Finally, I think the fence syntax is pretty neat, but would be good to validate that it's scalable too.

Oh, it actually lets you embed another MD file like this:

image

@fiennyangeln
Copy link
Contributor

Hi I'm interested in this issue. Is it an appropriate bug to work on?

@JoelMarcey
Copy link
Contributor

@fiennyangeln - I think this is quite appropriate. Language Toggling would be great and a feature that people really have asked for. And anything else you feel could improve the code blocks too.

I will mark this issue as claimed by you 😄

@JoelMarcey JoelMarcey added the status: claimed Issue has been claimed by a contributor who plans to work on it. label Oct 17, 2018
@endiliey endiliey closed this as completed May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: advanced Issues that are complex, e.g. large scoping for long-term maintainability. feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. status: claimed Issue has been claimed by a contributor who plans to work on it.
Projects
None yet
Development

No branches or pull requests

9 participants