Skip to content

Commit cc2a2f6

Browse files
committed
Markdown内のコードにSyntax highlightenをいれる
1 parent d526540 commit cc2a2f6

7 files changed

Lines changed: 23 additions & 7 deletions

File tree

browser/finder/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<link rel="stylesheet" href="../../node_modules/font-awesome/css/font-awesome.min.css" media="screen" charset="utf-8">
1111
<link rel="stylesheet" href="../../node_modules/devicon/devicon.min.css">
12+
<link rel="stylesheet" href="../../node_modules/highlight.js/styles/xcode.css">
1213
<link rel="shortcut icon" href="favicon.ico">
1314

1415
<style>

browser/main/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<link rel="stylesheet" href="../../node_modules/font-awesome/css/font-awesome.min.css" media="screen" charset="utf-8">
88
<link rel="stylesheet" href="../../node_modules/devicon/devicon.min.css">
9+
<link rel="stylesheet" href="../../node_modules/highlight.js/styles/xcode.css">
910
<link rel="shortcut icon" href="favicon.ico">
1011

1112
<style>

browser/styles/mixins/marked.styl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ marked()
6262
display list-item
6363
line-height 1.8em
6464
code
65-
font-family monospace
65+
font-family Monaco, Menlo, 'Ubuntu Mono', Consolas, source-code-pro, monospace;
6666
padding 2px 4px
6767
border solid 1px borderColor
6868
border-radius 4px

lib/markdown.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
11
import markdownit from 'markdown-it'
2+
import hljs from 'highlight.js'
23

34
var md = markdownit({
45
typographer: true,
5-
linkify: true
6+
linkify: true,
7+
highlight: function (str, lang) {
8+
if (lang && hljs.getLanguage(lang)) {
9+
try {
10+
return hljs.highlight(lang, str).value;
11+
} catch (__) {}
12+
}
13+
14+
try {
15+
return hljs.highlightAuto(str).value;
16+
} catch (__) {}
17+
18+
return ''; // use external default escaping
19+
}
620
})
721

822
export default function markdown (content) {

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "boost",
3-
"version": "0.4.1-beta.3",
3+
"version": "0.4.1-beta.4",
44
"description": "Boost App",
55
"main": "main.js",
66
"scripts": {
@@ -40,6 +40,7 @@
4040
"devicon": "^2.0.0",
4141
"font-awesome": "^4.3.0",
4242
"fs-jetpack": "^0.7.0",
43+
"highlight.js": "^8.9.1",
4344
"lodash": "^3.10.1",
4445
"markdown-it": "^4.3.1",
4546
"md5": "^2.0.0",
@@ -59,10 +60,9 @@
5960
"react-dom": "^0.14.0",
6061
"react-redux": "^4.0.0",
6162
"react-router": "^1.0.0-rc1",
62-
"react-select": "^0.8.1",
6363
"react-transform-catch-errors": "^1.0.0",
6464
"react-transform-hmr": "^1.0.1",
65-
"redbox-react": "^1.1.1",
65+
"redbox-react": "^1.2.0",
6666
"redux": "^3.0.2",
6767
"standard": "^5.3.1",
6868
"style-loader": "^0.12.4",

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var config = {
6969
'lodash',
7070
'markdown-it',
7171
'moment',
72-
'node-notifier'
72+
'highlight.js'
7373
]
7474
}
7575

webpack.config.production.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = {
4545
'lodash',
4646
'markdown-it',
4747
'moment',
48-
'node-notifier'
48+
'highlight.js'
4949
],
5050
resolve: {
5151
extensions: ['', '.js', '.jsx', 'styl']

0 commit comments

Comments
 (0)