Skip to content

Instantly share code, notes, and snippets.

@elviswolcott
Last active March 25, 2020 02:50
Show Gist options
  • Save elviswolcott/c4f15c6b0ec579e43a775cfdf9b25cc4 to your computer and use it in GitHub Desktop.
Save elviswolcott/c4f15c6b0ec579e43a775cfdf9b25cc4 to your computer and use it in GitHub Desktop.
Example of highlight comments working in comment styles
id title sidebar_label
highlight-test
Advanced Highlighting
Highlighting

:::note Assumes you are using @docusaurus-preset-classic. :::

// You can highlight js using comments
const myFunction = () => {
  // highlight-next-line
  return 100;
};

// highlight-start
const myOtherFunction = () => {
  return 101;
};
// highlight-end

export { myFunction, myOtherFunction };
// or jsx
const myComponent = () => {
  return <div>
    { /* highlight-next-line */ }
    <p>Highlighted</p>
    <p>Not Highlighted</p>
    { /* highlight-start */ }
    <div>
      <p>All highlighted!</p>
    </div>
    { /* highlight-end */ }
  </div>
}
Why *not* highlight **Markdown**?
// highlight-next-line
*highlighted*
not highlighted
// highlight-start
> ALL OF
> THIS IS
> HIGHLIGHTED
// highlight-end
You can highlight plaintext too
// highlight-next-line
single line
not highlighted
// highlight-start
line range

all
highlighted
// highlight-end
but not this
# python (and hopefully any other language) works too!
# highlight-next-line
print('Hello!')
print('World.')
# highlight-start
def hello_world():
  print('Hello world!')
# highlight-end
hello_world()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment