File tree Expand file tree Collapse file tree 2 files changed +37
-4
lines changed Expand file tree Collapse file tree 2 files changed +37
-4
lines changed Original file line number Diff line number Diff line change 1+ const visit = require ( 'unist-util-visit' ) ;
2+
3+ const applyClassesToNode = require ( './src/applyClassesToNode' ) ;
4+
5+ module . exports = ( { markdownAST } , { classMap = { } } ) => {
6+ // @see : https://github.com/syntax-tree/mdast#nodes
7+ visit ( markdownAST , `heading` , ( node ) => {
8+ const selector = `h${ node . depth } ` ;
9+
10+ if ( selector in classMap ) {
11+ node = applyClassesToNode ( node , classMap [ selector ] ) ;
12+ }
13+ } ) ;
14+
15+ visit ( markdownAST , `table` , ( node ) => {
16+ const selector = `table` ;
17+
18+ if ( selector in classMap ) {
19+ node = applyClassesToNode ( node , classMap [ selector ] ) ;
20+ }
21+ } ) ;
22+
23+ visit ( markdownAST , `paragraph` , ( node ) => {
24+ const selector = `paragraph` ;
25+
26+ if ( selector in classMap ) {
27+ node = applyClassesToNode ( node , classMap [ selector ] ) ;
28+ }
29+ } ) ;
30+ } ;
Original file line number Diff line number Diff line change 11{
22 "name" : " gatsby-remark-classes" ,
3- "version" : " 0.1.0 " ,
3+ "version" : " 0.1.1 " ,
44 "description" : " Automatically add class attributes to rendered markdown elements" ,
5- "main" : " src/index.js" ,
6- "keywords" : [" gatsby" , " gatsby-plugin" ],
5+ "main" : " index.js" ,
6+ "keywords" : [
7+ " gatsby" ,
8+ " gatsby-plugin"
9+ ],
710 "author" :
" Chris Greindl <[email protected] >" ,
811 "license" : " MIT" ,
912 "dependencies" : {
1619 "bugs" : {
1720 "url" : " https://github.com/chrisg86/gatsby-remark-classes/issues"
1821 }
19- }
22+ }
You can’t perform that action at this time.
0 commit comments