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

Better documentation and support for code syntax hightlighting #191

Closed
ericelliott opened this issue Jun 28, 2018 · 7 comments
Closed

Better documentation and support for code syntax hightlighting #191

ericelliott opened this issue Jun 28, 2018 · 7 comments
Labels
📚 area/docs This affects documentation 💪 phase/solved Post is done 🦋 type/enhancement This is great to have

Comments

@ericelliott
Copy link

I think these code hightlighting issues keep popping up because it's not at all obvious how we're supposed to turn code highlighting on without digging into the code examples.

Take a look at how react-syntax-hightlighter deals with this issue:

import SyntaxHighlighter from 'react-syntax-highlighter';
import { tomorrowNightBright } from 'react-syntax-highlighter/styles/hljs';

<SyntaxHighlighter language="javascript" style={tomorrowNightBright}>`const foo = 'bar';`</SyntaxHighlighter>

In my opinion, something like this would be really cool:

import Markdown from 'react-markdown';
import { style } from './styles/hljs';

<Markdown style={ style }>`
# Hurray!

\`\`\`
const foo = 'bar';
\`\`\`
`</Markdown>

If we can already do something like this, it would be really cool to make it easy to find in the documentation.

@ibrahima
Copy link

ibrahima commented Jul 5, 2018

It's actually pretty easy to enable code highlighting, you just need to pass a custom renderer for code blocks to ReactMarkdown. I found the easiest way to figure out how to do that was to look at the source for how the existing renderers were written: https://github.com/rexxars/react-markdown/blob/master/src/renderers.js . I am not sure if those examples in the other issues are fully up to date (since they predate version 3.0), but I'll throw mine into the pile because I'm actually using react-syntax-highlighter.

https://gist.github.com/ibrahima/d21950a95aee3212e991a8404e238093

(I've extracted this snippet from a bigger codebase with more customization so apologies if it doesn't work right away.)

@lawrenceching
Copy link

Build-In support is not that necessary. The solution @ibrahima provided is awesome.
As users, I think what we need is to document it somewhere.
The gap between the default result and the demo page is huge. That really confused me.

@colinhacks
Copy link

@ibrahima I'm confused - does your code work with triple-backtick syntax? How do you tell react-markdown what language's syntax to use?

Does anyone know of a solution that uses GitHub's custom syntax for specifying languages? e.g.:

const x: string = "asdf";

@ibrahima
Copy link

ibrahima commented Apr 6, 2020

Yes it does. The markdown parser already handles that. My snippet just gives a way to render code blocks with syntax highlighting.

@ericelliott
Copy link
Author

Did that example ever get added to the docs?

@wooorm
Copy link
Member

wooorm commented Oct 8, 2020

This should be significantly easier when #428 lands, by adding either https://github.com/mapbox/rehype-prism, https://github.com/rsclarke/rehype-shiki, or https://github.com/rehypejs/rehype-highlight. I’ll rename this issue to ensure we add an example somewhere in the readme

edit: title is perfect 😅

@ChristianMurphy ChristianMurphy added 📚 area/docs This affects documentation 🦋 type/enhancement This is great to have and removed feature request labels Oct 8, 2020
wooorm added a commit that referenced this issue Oct 16, 2020
* Lowercase filenames to scream less
* Add `remark-cli`, `remark-preset-wooorm` to format prose
* Use imports and fancy new JS features
* Add link to a markdown cheatsheet, as many questions are about that
* Add details tags showing equivalent JSX for examples, to clarify how markdown
  works
* Refactor options list, clean signatures
* Add examples on plugins, plugins w/ options, renderers (syntax highlighting),
  and combining plugins w/ renderers (math)
* Add sections on why to use this, security, contributing, related projects
* Add test for `react-katex` integration

Closes GH-70.
Closes GH-191.
Related to GH-474.
Closes GH-479.
Closes GH-480.
Related to GH-483.
wooorm added a commit that referenced this issue Oct 17, 2020
* Lowercase filenames to scream less
* Add `remark-cli`, `remark-preset-wooorm` to format prose
* Use imports and fancy new JS features
* Add link to a markdown cheatsheet, as many questions are about that
* Add details tags showing equivalent JSX for examples, to clarify how markdown
  works
* Refactor options list, clean signatures
* Add examples on plugins, plugins w/ options, renderers (syntax highlighting),
  and combining plugins w/ renderers (math)
* Add sections on why to use this, security, contributing, related projects
* Add test for `react-katex` integration

Closes GH-70.
Closes GH-191.
Related to GH-474.
Closes GH-479.
Closes GH-480.
Related to GH-483.
@wooorm wooorm closed this as completed in b3aa6e0 Oct 17, 2020
@wooorm
Copy link
Member

wooorm commented Oct 19, 2020

This is now documented in the readme

@wooorm wooorm added the 💪 phase/solved Post is done label Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 area/docs This affects documentation 💪 phase/solved Post is done 🦋 type/enhancement This is great to have
Development

No branches or pull requests

7 participants