-
Notifications
You must be signed in to change notification settings - Fork 990
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example of how to override the Markdown loader
- Loading branch information
1 parent
29d2d9d
commit d49ac2d
Showing
5 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.warning { | ||
color: #9F6000; | ||
background-color: #FEEFB3; | ||
padding: 18px; | ||
} | ||
.warning:before { | ||
content:'\26A0'; | ||
margin-right: 9px; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import frontMatter from 'front-matter' | ||
import markdownIt from 'markdown-it' | ||
import hljs from 'highlight.js' | ||
import objectAssign from 'object-assign' | ||
|
||
const highlight = (str, lang) => { | ||
if ((lang !== null) && hljs.getLanguage(lang)) { | ||
try { | ||
return hljs.highlight(lang, str).value | ||
} catch (_error) { | ||
console.error(_error) | ||
} | ||
} | ||
try { | ||
return hljs.highlightAuto(str).value | ||
} catch (_error) { | ||
console.error(_error) | ||
} | ||
return '' | ||
} | ||
|
||
const md = markdownIt({ | ||
html: true, | ||
linkify: true, | ||
typographer: true, | ||
highlight, | ||
}) | ||
.use(require('markdown-it-sub')) | ||
.use(require('markdown-it-footnote')) | ||
.use(require('markdown-it-deflist')) | ||
.use(require('markdown-it-abbr')) | ||
.use(require('markdown-it-attrs')) | ||
|
||
module.exports = function (content) { | ||
this.cacheable() | ||
const meta = frontMatter(content) | ||
const body = md.render(meta.body) | ||
const result = objectAssign({}, meta.attributes, { | ||
body, | ||
}) | ||
this.value = result | ||
return `module.exports = ${JSON.stringify(result)}` | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,15 @@ | |
"author": "Kyle Mathews <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"front-matter": "^2.0.6", | ||
"highlight.js": "^9.2.0", | ||
"markdown-it": "^6.0.0", | ||
"markdown-it-abbr": "^1.0.3", | ||
"markdown-it-attrs": "^0.1.8", | ||
"markdown-it-deflist": "^2.0.1", | ||
"markdown-it-footnote": "^2.0.0", | ||
"markdown-it-sub": "^1.0.0", | ||
"object-assign": "^4.0.1", | ||
"react": "^0.14.7", | ||
"react-document-title": "^2.0.1", | ||
"react-dom": "^0.14.7", | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import React from 'react' | ||
import 'css/markdown-styles.css' | ||
|
||
module.exports = React.createClass({ | ||
propTypes () { | ||
|