mirror of
https://github.com/jxnblk/mdx-deck.git
synced 2024-11-29 13:58:02 +03:00
26 lines
540 B
JavaScript
26 lines
540 B
JavaScript
import React from 'react'
|
|
import SyntaxHighlighter from 'react-syntax-highlighter'
|
|
|
|
export const getLanguage = className => {
|
|
const match = /language-(\w*)/.exec(className || 'language-javascript')
|
|
let lang = 'javascript'
|
|
if (match.length > 1) {
|
|
lang = match[1]
|
|
}
|
|
return lang
|
|
}
|
|
|
|
export const pre = props => props.children
|
|
|
|
export const code = props => {
|
|
const language = getLanguage(props.className)
|
|
return <SyntaxHighlighter language={language} {...props} />
|
|
}
|
|
|
|
export default {
|
|
components: {
|
|
pre,
|
|
code,
|
|
},
|
|
}
|