Mdx: Question: how to add syntax highlighting?

Created on 4 May 2018  路  3Comments  路  Source: mdx-js/mdx

There is https://github.com/mdx-js/mdx/issues/122 which is marked as a bug. Is there any other way to add syntax highlighting to code blocks with language tags like javascript?

All 3 comments

Yesterday I fixed that issue while flying back home, still need to send a pull request 馃憤馃徎

After that is fixed it鈥檚 as easy as adding that plugin 馃憤馃徎

This worked for me for Go syntax highlighting with Prism:

// theme.js
import theme from 'mdx-deck/themes'
import {
    future
} from 'mdx-deck/themes'
import okaidia from 'react-syntax-highlighter/styles/prism/okaidia'
import prismGo from 'react-syntax-highlighter/languages/prism/go'

export default {
  // extends the default theme
  ...theme,
  ...future,
  // add a custom font
  font: 'Laila, Roboto, sans-serif',
  // custom colors
  colors: {
    text: '#fff',
    background: 'black',
    link: '#da0',
  },
  prism: {
    style: okaidia,
    languages: {
        go: prismGo,}
  },
}

Export theme at the top of my deck.mdx:

export { default as theme } from './theme'

Hope this helps!

Was this page helpful?
0 / 5 - 0 ratings