You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+28-5Lines changed: 28 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,17 @@
1
1
# gatsby-remark-classes
2
+
2
3
Automatically add class attributes to markdown elements.
3
4
4
5
This is a plugin for [gatsby-transformer-remark](https://www.gatsbyjs.org/packages/gatsby-transformer-remark/?=gatsby-transformer-remark).
5
6
6
7
## Install
8
+
7
9
```
8
10
npm install --save gatsby-remark-classes
9
11
```
10
12
11
13
## Configure
14
+
12
15
In your `gatsby-config.js`:
13
16
14
17
```js
@@ -20,9 +23,9 @@ In your `gatsby-config.js`:
20
23
resolve:`gatsby-remark-classes`,
21
24
options: {
22
25
classMap: {
23
-
h1:'title',
24
-
h2:'subtitle',
25
-
paragraph:'para'
26
+
"heading[depth=1]":"title",
27
+
"heading[depth=2]":"subtitle",
28
+
paragraph:"para",
26
29
}
27
30
}
28
31
}
@@ -35,27 +38,47 @@ The rules above applied to the following markdown
35
38
36
39
```markdown
37
40
# Main heading
41
+
38
42
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eum, odio.
39
43
40
44
## Sub header
45
+
41
46
Lorem ipsum dolor sit amet, consectetur adipisicing.
42
47
```
43
48
44
49
Will result in this HTML output:
45
50
46
51
```html
47
52
<h1class="title">Main heading</h1>
48
-
<pclass="para">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eum, odio.</p>
53
+
<pclass="para">
54
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eum, odio.
55
+
</p>
49
56
50
57
<h2class="subtitle">Sub header</h2>
51
58
<pclass="para">Lorem ipsum dolor sit amet, consectetur adipisicing.</p>
52
59
```
53
60
54
61
## The classMap
55
-
Right now you can add styles for **heading** elements (h1 - h6), **paragraphs** and **tables**.
62
+
63
+
For supported selectors please please consult [syntax-tree/mdast](https://github.com/syntax-tree/mdast#nodes) for the node list and have a look at the [Support section of unist-util-select](https://github.com/syntax-tree/unist-util-select#support)
56
64
57
65
## Motivation
58
66
59
67
Applying custom styles is also possible by just wrapping your converted markdown in a parent element and write the styles for that. This will however not work if you use atomic css in your project or a framework like Semantic UI or Tailwind CSS.
60
68
61
69
With this project you define which classes get assigned to which element.
70
+
71
+
## Upgrade guide
72
+
73
+
When upgrading from version 0.x.x to 1.x.x, you will have to update the selectors in your `gatsby-config.js` file.
74
+
75
+
Some common selectors:
76
+
77
+
-`h1` is now `heading[depth=1]`
78
+
-`h2` is now `heading[depth=2]`
79
+
-`ul` is now `list[ordered=false]`
80
+
-`ol` is now `list[ordered=true]`
81
+
-`li` is now `listItem`
82
+
-`paragraph` is still `paragraph`
83
+
84
+
Additionally you have now the chance to target child elements `code > pre` or even adjacent elements `paragraph + paragraph`. As stated above, please consult [syntax-tree/mdast](https://github.com/syntax-tree/mdast#nodes) for the node list and [syntax-tree/unist-util-select](https://github.com/syntax-tree/unist-util-select#support) for pseudo selectors and syntax.
0 commit comments