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

[V2] Potential code block improvements #2271

Closed
markerikson opened this issue Feb 6, 2020 · 8 comments
Closed

[V2] Potential code block improvements #2271

markerikson opened this issue Feb 6, 2020 · 8 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. help wanted Asking for outside help and/or contributions to this particular issue or PR.

Comments

@markerikson
Copy link

markerikson commented Feb 6, 2020

🚀 Feature

v2 code blocks currently have the ability to highlight specific line numbers, like this:

```jsx {1,4-6,11}

However, highlighting lines based on line numbers is somewhat difficult to use.

The gatsby-remark-prismjs plugin has the ability to highlight individual lines by putting a // highlight-next-line comment in front, or highlight ranges of lines using // highlight-start and // highlight-end pairs. It looks like the logic is implemented in this directives.js file.

This would be a great addition to the Docusaurus Prism plugin.

In addition, I've seen that many docs websites have code snippets that include a filename in front of the block, such as Gatsby (example) and Ember (example).

Gatsby's Markdown for this looks like:

```javascript:title=src/pages/about-css-modules.js
import React from "react"
// highlight-next-line
import styles from "./about-css-modules.module.css"
import Container from "../components/container"

// highlight-next-line
console.log(styles)

Have you read the Contributing Guidelines on issues?

Yes

Motivation

Easier line highlights and filenames would be very useful, especially as part of tutorials that are telling users what to edit.

@markerikson markerikson added feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. status: needs triage This issue has not been triaged by maintainers labels Feb 6, 2020
@yangshun yangshun added difficulty: intermediate Issues that are medium difficulty level, e.g. moderate refactoring with a clear test plan. help wanted Asking for outside help and/or contributions to this particular issue or PR. and removed status: needs triage This issue has not been triaged by maintainers labels Feb 18, 2020
@yangshun
Copy link
Contributor

Sounds very useful indeed!

@JoelMarcey JoelMarcey added the good first issue If you are just getting started with Docusaurus, this issue should be a good place to begin. label Feb 18, 2020
@elviswolcott
Copy link
Contributor

I've built these features out for an internal site on docusaurus v1 before. I'll take a stab at implementing it with this syntax sometime next week if no one takes it before then.

@elviswolcott
Copy link
Contributor

It looks life @kohheepeace has the code titles figured out. I can take a stab at the code highlight comments.

@markerikson
Copy link
Author

Looks like the filename title PR is almost done. @elviswolcott , are you still looking at doing the code highlighting comments feature?

@elviswolcott
Copy link
Contributor

Yeah, lost track of this with everything going on the last few weeks. I'll get a PR together in the next few days.

@elviswolcott
Copy link
Contributor

My PR implements highlight-next-line, highlight-start, and highlight-end.

The linked Gatsby plugin also includes a highlight-range comment which I did not implement, as it doesn't seem particularly useful. It is somewhat more useful than the current method (e.g. highlighting relative to a function declaration) but it seems that highlight-next-line, highlight-start, and highlight-end will always be more readable and maintainable.

If anyone thinks it should be added, I can throw it in.

@markerikson
Copy link
Author

Looks like both the requested features are in https://github.com/facebook/docusaurus/releases/tag/v2.0.0-alpha.49 , so I'll close this. Thanks!

@yangshun
Copy link
Contributor

yangshun commented Apr 1, 2020

Thank you @kohheepeace and @elviswolcott!

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. help wanted Asking for outside help and/or contributions to this particular issue or PR.
Projects
None yet
Development

No branches or pull requests

4 participants