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
Automatically add class attributes to markdown elements
2
+
Automatically add class attributes to markdown elements.
3
+
4
+
This is a plugin for [gatsby-transformer-remark](https://www.gatsbyjs.org/packages/gatsby-transformer-remark/?=gatsby-transformer-remark).
5
+
6
+
## Install
7
+
```
8
+
npm install --save gatsby-remark-classes
9
+
```
10
+
11
+
## Configure
12
+
In your `gatsby-config.js`:
13
+
14
+
```js
15
+
{
16
+
resolve:`gatsby-transformer-remark`,
17
+
options: {
18
+
plugins: [
19
+
{
20
+
resolve:`gatsby-remark-classes`,
21
+
options: {
22
+
classMap: {
23
+
h1:'title',
24
+
h2:'subtitle',
25
+
paragraph:'para'
26
+
}
27
+
}
28
+
}
29
+
]
30
+
}
31
+
}
32
+
```
33
+
34
+
The rules above applied to the following markdown
35
+
36
+
```markdown
37
+
# Main heading
38
+
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eum, odio.
39
+
40
+
## Sub header
41
+
Lorem ipsum dolor sit amet, consectetur adipisicing.
42
+
```
43
+
44
+
Will result in this HTML output:
45
+
46
+
```html
47
+
<h1class="title">Main heading</h1>
48
+
<pclass="para">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eum, odio.</p>
49
+
50
+
<h2class="subtitle">Sub header</h2>
51
+
<pclass="para">Lorem ipsum dolor sit amet, consectetur adipisicing.</p>
52
+
```
53
+
54
+
## The classMap
55
+
Right now you can add styles for **heading** elements (h1 - h6), **paragraphs** and **tables**.
56
+
57
+
## Motivation
58
+
59
+
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
+
61
+
With this project you define which classes get assigned to which element.
0 commit comments