Created
April 15, 2019 18:41
-
-
Save hpneo/2999d841f2bc96477c72b7eac74afe70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Renderer } from 'marked'; | |
| import Markdown from '~components/markdown'; | |
| import CodeMirror from 'codemirror'; | |
| import 'codemirror/addon/runmode/runmode'; | |
| import 'codemirror/mode/ruby/ruby'; | |
| import 'codemirror/mode/xml/xml'; | |
| import 'codemirror/mode/javascript/javascript'; | |
| import 'codemirror/mode/css/css'; | |
| import 'codemirror/mode/htmlmixed/htmlmixed'; | |
| import '~utils/gfm+table'; | |
| const renderCode = (code, lang) => { | |
| const output = document.createElement('pre'); | |
| CodeMirror.runMode(code, lang, output); | |
| return `<pre class="highlight">${output.innerHTML}</pre>`; | |
| }; | |
| const renderTable = (header, body) => { | |
| if (body) { | |
| body = `<tbody>${body}</tbody>`; | |
| } | |
| return `<table class="table is-bordered is-striped"><thead>${header}</thead>${body}</table>`; | |
| }; | |
| const renderer = new Renderer(); | |
| renderer.code = renderCode; | |
| renderer.table = renderTable; | |
| const DefaultElement = ({ content, wrap = true, trim = false }) => | |
| <Markdown markdown={content} markupOpts={{ trim, wrap }} markdownOpts={{ renderer }} />; | |
| export default DefaultElement; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment