question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[V2] Potential code block improvements

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
yangshuncommented, Apr 1, 2020

Thank you @KohheePeace and @elviswolcott!

2reactions
elviswolcottcommented, Mar 24, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code blocks | Docusaurus
Code blocks are text blocks wrapped around by strings of 3 backticks. You may check out this reference for the specifications of MDX....
Read more >
Version 20.03 - Code::Blocks
Make it possible to evaluate expression in wxSmith code blocks; Improvements for Fortran (ticket #717); Put the recent entered command in the position...
Read more >
Standards conformance improvements to /Gw in Visual Studio ...
The /Gw switch enables the linker to optimize global data to reduce binary size. As part of the 17.5 Preview 2 release a...
Read more >
Marked Help - Marked 2
IMPROVED. Fenced code block handling if custom processor returns NOCUSTOM; If a CriticMarkup element has a comment following it, show it in the...
Read more >
Improving JavaScript Bundle Performance With Code-Splitting
This automatization often leads developers to treat a framework and build tools as a black box. It's a common misconception that the code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found