66
77A Webpack loader for converting Markdown files to React components (JSX).
88
9- Currently supports ES6 imports and syntax highlighting.
9+ Currently supports imports, syntax highlighting, and extra data .
1010
1111This loader was built for the purpose of documenting React Components, but can be used for other static documents you want to convert to HTML.
1212
@@ -36,16 +36,24 @@ Note: Requires React 16.2+
3636# Installation
3737
3838```
39- yarn add markdown-to-react-loader
39+ yarn add --dev markdown-to-react-loader
4040```
41- Or
4241```
43- npm install --save-dev babel-loader @babel/preset-env @babel/preset-react markdown-to-react-loader
42+ npm install --save-dev markdown-to-react-loader
4443```
4544
4645# Usage
4746
48- Update your Webpack config. Because this loader outputs JSX its recommended to use the babel-loader after to compile the ES6 how you want.
47+ Because it outputs ES6 and JSX its recommended to use in conjunction with the babel-loader to compile for your targetted environment.
48+
49+ ```
50+ yarn add --dev babel-loader @babel/preset-env @babel/preset-react
51+ ```
52+ ```
53+ npm install --save-dev babel-loader @babel/preset-env @babel/preset-react
54+ ```
55+
56+ Update your Webpack config:
4957
5058``` javascript
5159{
@@ -54,9 +62,9 @@ Update your Webpack config. Because this loader outputs JSX its recommended to u
5462 use: [
5563 {
5664 loader: ' babel-loader' ,
57- options: {
58- presets: [' @babel/env' , ' @babel/react' ]
59- }
65+ options: {
66+ presets: [' @babel/env' , ' @babel/react' ]
67+ }
6068 },
6169 ' markdown-to-react-loader' ,
6270 ],
@@ -83,7 +91,7 @@ import HelloWorld from './HelloWorld.md';
8391ReactDOM .Render (< HelloWorld / > , document .getElementById (' app' ));
8492```
8593
86- # Imports
94+ ## Imports
8795
8896You can write ES6 imports inline using front matter.
8997
@@ -103,14 +111,47 @@ Heres a component rendered inline:
103111
104112```
105113
106- # Syntax Highlighting
114+ ## Syntax Highlighting
107115
108116Syntax highlighting is done using PrismJS and is picked up automatically by tagging code blocks:
109117
110118#### CodeSample.md
111119
112- # Code Sample
120+ # Code Sample
121+
122+ ```javascript
123+ console.log('This will be marked for highlighting');
124+ ```
125+
126+ ## Extra Data
127+
128+ Any front matter that is not under the ` imports ` key is considered extra data. It is parsed and exported as named exports from the module.
129+
130+ ``` markdown
131+ ---
132+ title: Hello World
133+ slug: /post/1
134+ object:
135+ - foo: bar
136+ - baz: biz
137+ array:
138+ - foo
139+ - bar
140+ ---
141+ ```
142+
143+ The above front matter is transformed to:
113144
114- ```javascript
115- console.log('This will be marked for highlighting');
116- ```
145+ ``` javascript
146+ const title = " Hello World" ;
147+ export { title };
148+
149+ const slug = " /post/1" ;
150+ export { slug };
151+
152+ const object = [{ foo: " bar" }, { baz: " biz" }];
153+ export { object };
154+
155+ const array = [" foo" , " bar" ];
156+ export { array };
157+ ```
0 commit comments