Skip to content

[V2] Potential code block improvements #2271

Description

@markerikson

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty: intermediateIssues that are medium difficulty level, e.g. moderate refactoring with a clear test plan.featureThis is not a bug or issue with Docusausus, per se. It is a feature request for the future.good first issueIf you are just getting started with Docusaurus, this issue should be a good place to begin.help wantedAsking for outside help and/or contributions to this particular issue or PR.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions