Skip to content
This repository was archived by the owner on Aug 9, 2020. It is now read-only.

Commit 00f30be

Browse files
author
Zach Sherman
authored
Merge pull request #128 from timberio/fix/markdown-html-parsing
Fix/markdown html parsing
2 parents 1e317a0 + 9346483 commit 00f30be

File tree

7 files changed

+90
-206
lines changed

7 files changed

+90
-206
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"history": "^4.7.2",
7777
"html-minifier": "^3.5.16",
7878
"js-search": "^1.4.2",
79+
"markdown-to-jsx": "^6.6.5",
7980
"markdown-toc": "^1.2.0",
8081
"minimist": "^1.2.0",
8182
"ncp": "^2.0.0",
@@ -90,7 +91,6 @@
9091
"react-feather": "^1.1.0",
9192
"react-helmet": "^5.2.0",
9293
"react-highlight-words": "^0.11.0",
93-
"react-markdown": "^3.3.2",
9494
"react-router-dom": "^4.2.2",
9595
"react-syntax-highlighter": "^7.0.4",
9696
"serve-static": "^1.13.2",

themes/default/markdown/index.js

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,52 @@
11
import React from 'react'
2-
import Markdown from 'react-markdown'
2+
// import Markdown from 'react-markdown'
3+
import Markdown from 'markdown-to-jsx'
34
import { Wrapper } from './styles'
45
import Code from './overrides/Code'
56
import Header from './overrides/Header'
67
import Link from './overrides/Link'
78

89
export default function (props) {
910
const options = {
10-
renderers: {
11-
code: p => <Code {...props} {...p} />,
12-
link: Link,
13-
heading: Header,
14-
},
11+
overrides: {
12+
code: {
13+
component: Code,
14+
props: {
15+
renderer: props.renderer,
16+
lineNumbers: props.lineNumbers
17+
}
18+
},
19+
h1: {
20+
component: Header,
21+
props: { level: 1 },
22+
},
23+
h2: {
24+
component: Header,
25+
props: { level: 2 },
26+
},
27+
h3: {
28+
component: Header,
29+
props: { level: 3 },
30+
},
31+
h4: {
32+
component: Header,
33+
props: { level: 4 },
34+
},
35+
h5: {
36+
component: Header,
37+
props: { level: 5 },
38+
},
39+
h6: {
40+
component: Header,
41+
props: { level: 6 },
42+
},
43+
a: Link,
44+
}
1545
}
1646

1747
return (
1848
<Wrapper>
19-
<Markdown {...options}>
49+
<Markdown options={options}>
2050
{props.source}
2151
</Markdown>
2252
</Wrapper>

themes/default/markdown/overrides/Code.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ import Prism from 'react-syntax-highlighter/prism-light'
44
import { theme, languages } from '@codegen/loadSyntax' // eslint-disable-line
55

66
export default function (props) {
7-
let { language } = props
8-
const { value, renderer } = props
7+
const { children, renderer, className, lineNumbers } = props
8+
9+
if (!className) return <code>{children}</code>
10+
11+
let language = className.split('-')[1]
912

1013
if (language) {
1114
language = language // language name aliases
@@ -27,11 +30,11 @@ export default function (props) {
2730
<Syntax
2831
style={theme}
2932
language={language}
30-
showLineNumbers={props.lineNumbers}
33+
showLineNumbers={lineNumbers}
3134
lineNumberStyle={{ opacity: 0.3 }}
3235
useInlineStyles
3336
>
34-
{value}
37+
{children}
3538
</Syntax>
3639
)
3740
}

themes/default/markdown/styles.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,23 @@ export const Wrapper = styled('div')`
4242
pre {
4343
overflow-x: scroll;
4444
background: #FAFAFD !important;
45+
border-radius: 4px;
46+
border-radius: 3px;
47+
line-height: 19px;
48+
padding: .25rem;
4549
}
4650
51+
// We need this since react-syntax-highlighter adds a pre
52+
pre pre { margin: 0; }
53+
4754
pre, code {
4855
// -webkit-font-smoothing: initial;
4956
}
5057
5158
code {
5259
border-radius: 4px;
53-
padding: .15rem .25rem;
54-
display: inline;
60+
padding: 0 .15rem;
61+
display: inline-block;
5562
word-break: break-all;
5663
background: #EEEAFE;
5764
color: #5742CA;
@@ -61,18 +68,11 @@ export const Wrapper = styled('div')`
6168
border: none;
6269
word-break: break-all;
6370
white-space: pre-wrap;
64-
display: inline-block !important;
71+
display: block;
6572
background: inherit;
6673
color: #485672;
6774
}
6875
69-
pre {
70-
border-radius: 4px;
71-
// font-family: Roboto Mono, monospace;
72-
border-radius: 3px;
73-
line-height: 19px;
74-
}
75-
7676
table {
7777
display: block;
7878
width: 100%;

themes/default/search/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class Search extends Component {
7777
}, async () => {
7878
const results = await this.fetchResults(value)
7979
this.setState({ results, loading: false })
80+
this.results.scrollTop = 0
8081
})
8182
}
8283

@@ -186,7 +187,7 @@ class Search extends Component {
186187
onClick={this.clearSearch}
187188
>
188189
<Link to={r.url}>
189-
<h4>{this.renderBreadCrumb(r)}</h4>
190+
<h5>{this.renderBreadCrumb(r)}</h5>
190191
<p>
191192
<Highlight
192193
highlightClassName="highlight"

themes/default/search/styles.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,25 @@ export const Input = styled('input')`
2323
export const Results = styled('div')`
2424
position: absolute;
2525
width: 100%;
26-
top: 70px;
26+
top: 65px;
2727
height: 50vh;
28+
max-width: 700px;
2829
max-height: 700px;
2930
overflow: scroll;
30-
box-shadow: 0 1px 5px 0 rgba(0,0,0,.07), 0 7px 17px 0 rgba(0,0,0,.1);
31+
border: 1px solid rgba(0,0,0,.1);
32+
box-shadow: 0 0.5rem 1rem rgba(0,0,0,.175);
3133
background: #FFF;
3234
z-index: 99;
3335
`
3436

3537
export const Result = styled('div')`
36-
padding: 1rem;
37-
background: ${props => props.selected ? '#f6f5fb' : '#FFF'};
38+
padding: .5rem 1rem;
39+
background: ${props => props.selected ? '#f7f7fb' : '#FFF'};
3840
a { text-decoration: none }
3941
&:hover {
40-
background: #f6f5fb;
41-
h4 { color: #6457DC; text-decoration: underline; }
42+
h5 { color: #6457DC; text-decoration: underline; }
4243
}
43-
h4 {
44+
h5 {
4445
font-weight: bold;
4546
text-decoration: none;
4647
margin: 0;
@@ -51,11 +52,18 @@ export const Result = styled('div')`
5152
color: rgba(0,0,0,0.75);
5253
text-decoration: none;
5354
margin: 0;
54-
font-size: 1rem;
55+
font-size: .9rem;
56+
}
57+
p .highlight {
58+
// text-decoration: underline;
59+
// text-decoration-color: #d1ccec
60+
border-bottom: 2px solid #b1a9da;
61+
display: inline-block;
62+
background: transparent;
5563
}
56-
p .highlight { background: #d1ccec }
5764
.url {
5865
font-size: 12px;
66+
color: #5343a2;
5967
}
6068
`
6169

0 commit comments

Comments
 (0)