Skip to content

Commit ed2d699

Browse files
committed
feat(site) Parse Tips custom markdown
1 parent b96633b commit ed2d699

File tree

4 files changed

+80
-2
lines changed

4 files changed

+80
-2
lines changed

DISCUSSION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ easier to discuss...
88
Here's the TLDR; in terms of actual blocking TODOs if we wanted to stick with
99
this branch:
1010

11-
- [ ] Finish porting the markdown process to `remark` (may require new plugins)
11+
- [ ] Finish porting the markdown process to `remark` (may require new plugins) (Fernando)
1212
- [ ] Rethink external population process
1313
- [x] Extract anchors into `_content.json` via `DirectoryTreePlugin` (Fernando)
1414
- [ ] Finish re-incorporating mobile sidebar

src/components/Markdown/Markdown.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
border-left: 4px solid #dddddd;
7979
padding:0.75em 1em;
8080
color:getColor(dove-grey);
81+
font-style: italic;
8182

8283
> :first-child { margin-top: 0; }
8384
> :last-child { margin-bottom: 0; }

tip.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// var unified = require('unified');
2+
// var parse = require('remark-parse');
3+
// var html = require('remark-html');
4+
var visit = require('unist-util-visit');
5+
6+
// const md = `T> This is a tip.
7+
8+
// The [configuration](/configuration) properties should be ordered alphabetically as well:
9+
10+
// W> This is a warning.
11+
12+
// ?> This is a todo.`;
13+
14+
// const header = `## Header`;
15+
16+
// const md = "T> The `output` property has [many more configurable features](/configuration/output) and if you like to know more about the concepts behind the `output` property, you can [read more in the concepts section](/concepts/output)."
17+
18+
const classMap = {
19+
'T>': 'tip',
20+
'W>': 'warning',
21+
'?>': 'todo'
22+
};
23+
24+
// unified()
25+
// .use(parse)
26+
// .use(tip)
27+
// .use(html)
28+
// .process(md, function(err, file) {
29+
// console.log({ err })
30+
// console.log(file);
31+
// });
32+
33+
module.exports = tip;
34+
35+
function tip(options) {
36+
return transformer;
37+
}
38+
39+
function transformer(tree, file) {
40+
visit(tree, 'paragraph', visitor);
41+
42+
function visitor(node) {
43+
const { children } = node;
44+
const textNode = children[0].value;
45+
46+
if (!textNode) return;
47+
48+
if (
49+
textNode.startsWith('T>') ||
50+
textNode.startsWith('W>') ||
51+
textNode.startsWith('?>')
52+
) {
53+
let className = classMap[textNode.substr(0, 2)];
54+
55+
node.type = 'blockquote';
56+
node.data = {
57+
hName: 'blockquote',
58+
hProperties: {
59+
className
60+
}
61+
};
62+
node.children = [
63+
{
64+
type: 'paragraph',
65+
children: [
66+
{
67+
...children[0],
68+
value: children[0].value.slice(3)
69+
},
70+
...children.slice(1)
71+
]
72+
}
73+
];
74+
}
75+
}
76+
}

webpack.common.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ module.exports = (env = {}) => ({
3737
options: {
3838
plugins: [
3939
// TODO: Add necessary remark plugins
40+
require('./tip'),
4041
require('remark-slug'),
4142
[
4243
require('remark-autolink-headings'),
4344
{
4445
behaviour: 'append'
4546
}
4647
],
47-
require('remark-html')
48+
require('remark-html'),
4849
require('remark-mermaid')
4950
]
5051
}

0 commit comments

Comments
 (0)