forked from react-navigation/react-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMDPage.js
More file actions
88 lines (84 loc) · 2.3 KB
/
Copy pathMDPage.js
File metadata and controls
88 lines (84 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React from 'react';
const Markdown = require('react-markdown');
const DocsMD = require('../docs-dist.json');
import Link from './Link';
import PhoneGraphic from './PhoneGraphic';
const slugify = require('slugify');
import CodeBlock from './CodeBlock';
const safeString = s =>
slugify(s)
.replace(/\)/g, '-')
.replace(/\(/g, '-')
.replace(/^-/, '')
.replace(/-$/, '');
const getHeadingForLevel = level => {
switch (level) {
case 2:
return 'h2';
case 3:
return 'h3';
case 4:
return 'h4';
case 5:
return 'h5';
case 6:
return 'h6';
case 7:
return 'h7';
default:
case 1:
return 'h1';
}
};
const MDPage = ({ navigation, docPath }) => (
<Markdown
source={DocsMD[docPath]}
className="md-section"
renderers={{
CodeBlock: function CodeBlockComponent({ literal, language }) {
if (language === 'phone-example') {
const graphicName = literal.trim();
return (
<PhoneGraphic
alt
sources={{
iphone: `/assets/examples/${graphicName}-iphone.png`,
android: `/assets/examples/${graphicName}-android.png`,
}}
/>
);
}
return <CodeBlock code={literal} />;
},
Heading: function HeadingComponent({ level, children }) {
let id = React.Children
.map(children, child => {
if (typeof child === 'string') {
return safeString(child);
} else if (typeof child.props.children === 'string') {
return safeString(child.props.children);
}
})
.join('-');
const Header = getHeadingForLevel(level);
const linkHeader = id ? '' : 'link-header';
const className = `md-header ${linkHeader}`;
return (
<Header id={id} className={className}>
{children}{' '}
<a href={`#${id}`} title={children}>
#
</a>
</Header>
);
},
link: function LinkComponent({ children, href }) {
if (href.indexOf('PhoneGraphic:') === 0) {
const graphicName = href.split('PhoneGraphic:')[1];
}
return <Link href={href}>{children}</Link>;
},
}}
/>
);
export default MDPage;