Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit90fa20c

Browse files
committed
add syntax highlighting for code blocks
1 parentd11e637 commit90fa20c

File tree

5 files changed

+146
-21
lines changed

5 files changed

+146
-21
lines changed

‎web-app/package-lock.json

Lines changed: 8 additions & 6 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎web-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"private":true,
55
"dependencies": {
66
"@alifd/next":"^1.15.12",
7-
"highlight.js":"^9.15.8",
87
"markdown-it":"^9.0.1",
98
"markdown-it-emoji":"^1.4.0",
9+
"markdown-it-prism":"^2.0.2",
1010
"moment":"^2.24.0",
1111
"react":"^16.8.6",
1212
"react-dom":"^16.8.6",

‎web-app/src/components/Markdown/index.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
1-
importsyntaxHighlighterfrom'highlight.js'
21
importMarkdownItfrom'markdown-it'
32
//@ts-ignore no types for package
43
importmarkdownEmojifrom'markdown-it-emoji'
4+
//@ts-ignore no types for package
5+
importprismfrom'markdown-it-prism'
56
import*asReactfrom'react'
67

7-
// syntax highlighting https://github.com/markdown-it/markdown-it
8-
constsyntaxHighlight=(str:string,lang:string)=>{
9-
if(lang&&syntaxHighlighter.getLanguage(lang)){
10-
try{
11-
returnsyntaxHighlighter.highlight(lang,str).value
12-
}catch(__){
13-
// ignore
14-
}
15-
}
16-
return''// use external default escaping
17-
}
8+
import'./prism.css'
189

1910
// markdown highlighter instance
2011
constmd=newMarkdownIt({
2112
breaks:true,
22-
highlight:syntaxHighlight,
13+
//highlight: syntaxHighlight,
2314
html:true,
2415
linkify:true,
2516
})
2617
// add emoji: https://github.com/markdown-it/markdown-it-emoji
2718
.use(markdownEmoji)
19+
.use(prism,{
20+
defaultLanguage:'js',
21+
})
2822

2923
interfaceProps{
3024
children:string
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/* PrismJS 1.16.0
2+
https://prismjs.com/download.html#themes=prism-tomorrow&languages=markup+css+clike+javascript+typescript+jsx+tsx */
3+
/**
4+
* prism.js tomorrow night eighties for JavaScript, CoffeeScript, CSS and HTML
5+
* Based on https://github.com/chriskempson/tomorrow-theme
6+
* @author Rose Pritchard
7+
*/
8+
9+
code[class*="language-"],
10+
pre[class*="language-"] {
11+
color:#ccc;
12+
background: none;
13+
font-family: Consolas, Monaco,'Andale Mono','Ubuntu Mono', monospace;
14+
font-size:1em;
15+
text-align: left;
16+
white-space: pre;
17+
word-spacing: normal;
18+
word-break: normal;
19+
word-wrap: normal;
20+
line-height:1.5;
21+
22+
-moz-tab-size:4;
23+
-o-tab-size:4;
24+
tab-size:4;
25+
26+
-webkit-hyphens: none;
27+
-moz-hyphens: none;
28+
-ms-hyphens: none;
29+
hyphens: none;
30+
31+
}
32+
33+
/* Code blocks */
34+
pre[class*="language-"] {
35+
padding:1em;
36+
margin:.5em0;
37+
overflow: auto;
38+
}
39+
40+
:not(pre)>code[class*="language-"],
41+
pre[class*="language-"] {
42+
background:#2d2d2d;
43+
}
44+
45+
/* Inline code */
46+
:not(pre)>code[class*="language-"] {
47+
padding:.1em;
48+
border-radius:.3em;
49+
white-space: normal;
50+
}
51+
52+
.token.comment,
53+
.token.block-comment,
54+
.token.prolog,
55+
.token.doctype,
56+
.token.cdata {
57+
color:#999;
58+
}
59+
60+
.token.punctuation {
61+
color:#ccc;
62+
}
63+
64+
.token.tag,
65+
.token.attr-name,
66+
.token.namespace,
67+
.token.deleted {
68+
color:#e2777a;
69+
}
70+
71+
.token.function-name {
72+
color:#6196cc;
73+
}
74+
75+
.token.boolean,
76+
.token.number,
77+
.token.function {
78+
color:#f08d49;
79+
}
80+
81+
.token.property,
82+
.token.class-name,
83+
.token.constant,
84+
.token.symbol {
85+
color:#f8c555;
86+
}
87+
88+
.token.selector,
89+
.token.important,
90+
.token.atrule,
91+
.token.keyword,
92+
.token.builtin {
93+
color:#cc99cd;
94+
}
95+
96+
.token.string,
97+
.token.char,
98+
.token.attr-value,
99+
.token.regex,
100+
.token.variable {
101+
color:#7ec699;
102+
}
103+
104+
.token.operator,
105+
.token.entity,
106+
.token.url {
107+
color:#67cdcc;
108+
}
109+
110+
.token.important,
111+
.token.bold {
112+
font-weight: bold;
113+
}
114+
.token.italic {
115+
font-style: italic;
116+
}
117+
118+
.token.entity {
119+
cursor: help;
120+
}
121+
122+
.token.inserted {
123+
color: green;
124+
}
125+

‎web-app/stories/Step.stories.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ storiesOf('Tutorial SideBar', module)
2727
<Step
2828
content={object('content',{
2929
text:`Markdown included \`code\`, *bold*, & _italics_.
30-
\`\`\`
30+
\`\`\`javascript
3131
var a = 12
32+
33+
function example(a) {
34+
return a + 1
35+
}
3236
\`\`\`
3337
3438
Headers can be added:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp