typography-stylecss 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +433 -0
- package/package.json +58 -0
- package/src/index.d.ts +9 -0
- package/src/index.js +138 -0
- package/src/index.test.js +1442 -0
- package/src/styles.js +1641 -0
- package/src/utils.js +120 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Tailwind Labs, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
<p>
|
|
2
|
+
<a href="https://tailwindcss.com/docs/typography-plugin" target="_blank">
|
|
3
|
+
<h1>tailwindTYPOGRAPHY Style</h1>
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
The official Tailwind CSS Typography Style plugin provides a set of `prose` classes you can utilize to add beautiful typographic styles to any vanilla HTMLs you don’t control, like HTML rendered from Markdown, or pulled from a CMS.
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<article class="prose lg:prose-xl">{{ markdown }}</article>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
To see what it looks like in action, check out our [live demo](https://play.tailwindcss.com/uj1vGACRJA?layout=preview) on Tailwind Play.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Install the plugin from npm:
|
|
20
|
+
|
|
21
|
+
```shell
|
|
22
|
+
npm install -D typography-stylecss
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Then add the plugin to your main `style.css` file:
|
|
26
|
+
|
|
27
|
+
```diff
|
|
28
|
+
@import "tailwindcss";
|
|
29
|
+
+ @plugin "typography-stylecss";
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
If you are still using **Tailwind CSS v3**, add the plugin to your `tailwind.config.js` file:
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
// tailwind.config.js
|
|
36
|
+
module.exports = {
|
|
37
|
+
theme: {
|
|
38
|
+
// ...
|
|
39
|
+
},
|
|
40
|
+
plugins: [
|
|
41
|
+
require('typography-stylecss'),
|
|
42
|
+
// ...
|
|
43
|
+
],
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Basic usage
|
|
50
|
+
|
|
51
|
+
Now you can use the `prose` classes to add sensible typography styles to any vanilla HTML:
|
|
52
|
+
|
|
53
|
+
```html
|
|
54
|
+
<article class="prose lg:prose-xl">
|
|
55
|
+
<h1>Carrots: A Scientific Look at Their Health Benefits</h1>
|
|
56
|
+
<p>
|
|
57
|
+
Recent studies have highlighted the numerous health benefits of carrots, making them a powerhouse in the realm of nutrition. Rich in beta-carotene, a precursor to vitamin A, carrots play a key role in promoting healthy vision and supporting immune function. Research has also shown that the antioxidants found in carrots can help reduce the risk of chronic diseases such as heart disease and certain cancers.
|
|
58
|
+
</p>
|
|
59
|
+
<p>
|
|
60
|
+
Additionally, their high fiber content aids in digestion, contributing to overall gut health. As a result, incorporating carrots into a balanced diet is widely recommended by nutrition experts for maintaining optimal health.
|
|
61
|
+
</p>
|
|
62
|
+
<!-- ... -->
|
|
63
|
+
</article>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Choosing a gray scale
|
|
67
|
+
|
|
68
|
+
This plugin includes a modifier class for each of the five gray scales Tailwind includes by default so you can easily style your content to match the grays you're using in your project.
|
|
69
|
+
|
|
70
|
+
```html
|
|
71
|
+
<article class="prose prose-slate">{{ markdown }}</article>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Here are the classes that are generated using a totally default Tailwind CSS v2.0 build:
|
|
75
|
+
|
|
76
|
+
| Class | Gray scale |
|
|
77
|
+
| ------------------------ | ---------- |
|
|
78
|
+
| `prose-gray` _(default)_ | Gray |
|
|
79
|
+
| `prose-slate` | Slate |
|
|
80
|
+
| `prose-zinc` | Zinc |
|
|
81
|
+
| `prose-neutral` | Neutral |
|
|
82
|
+
| `prose-stone` | Stone |
|
|
83
|
+
|
|
84
|
+
Modifier classes are designed to be used with the [multi-class modifier pattern](http://nicolasgallagher.com/about-html-semantics-front-end-architecture/#component-modifiers) and must be used in conjunction with the base `prose` class.
|
|
85
|
+
|
|
86
|
+
> [!NOTE]
|
|
87
|
+
> Always include the `prose` class when adding a gray scale modifier
|
|
88
|
+
|
|
89
|
+
```html
|
|
90
|
+
<article class="prose prose-stone">{{ markdown }}</article>
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
To learn about creating your own color themes, read the [adding custom color themes](#adding-custom-color-themes) documentation.
|
|
94
|
+
|
|
95
|
+
### Applying a type scale
|
|
96
|
+
|
|
97
|
+
Size modifiers allow you to adjust the overall size of your typography for different contexts.
|
|
98
|
+
|
|
99
|
+
```html
|
|
100
|
+
<article class="prose prose-xl">{{ markdown }}</article>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Five different typography sizes are included out of the box:
|
|
104
|
+
|
|
105
|
+
| Class | Body font size |
|
|
106
|
+
| ------------------------ | ----------------- |
|
|
107
|
+
| `prose-sm` | 0.875rem _(14px)_ |
|
|
108
|
+
| `prose-base` _(default)_ | 1rem _(16px)_ |
|
|
109
|
+
| `prose-lg` | 1.125rem _(18px)_ |
|
|
110
|
+
| `prose-xl` | 1.25rem _(20px)_ |
|
|
111
|
+
| `prose-2xl` | 1.5rem _(24px)_ |
|
|
112
|
+
|
|
113
|
+
These can be used in combination with Tailwind's [breakpoint modifiers](https://tailwindcss.com/docs/responsive-design) to change the overall font size of a piece of content at different viewport sizes:
|
|
114
|
+
|
|
115
|
+
```html
|
|
116
|
+
<article class="prose md:prose-lg lg:prose-xl">{{ markdown }}</article>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Everything about the provided size modifiers has been hand-tuned by professional designers to look as beautiful as possible, including the relationships between font sizes, heading spacing, code block padding, and more.
|
|
120
|
+
|
|
121
|
+
Size modifiers are designed to be used with the [multi-class modifier pattern](http://nicolasgallagher.com/about-html-semantics-front-end-architecture/#component-modifiers) and must be used in conjunction with the base `prose` class.
|
|
122
|
+
|
|
123
|
+
> [!NOTE]
|
|
124
|
+
> Always include the `prose` class when adding a size modifier
|
|
125
|
+
|
|
126
|
+
```html
|
|
127
|
+
<article class="prose prose-lg">{{ markdown }}</article>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
To learn about customizing the included type scales, read the documentation on [customizing the CSS](#customizing-the-css).
|
|
131
|
+
|
|
132
|
+
### Adapting to dark mode
|
|
133
|
+
|
|
134
|
+
Each default color theme includes a hand-designed dark mode version that you can trigger by adding the `prose-invert` class:
|
|
135
|
+
|
|
136
|
+
```html
|
|
137
|
+
<article class="prose dark:prose-invert">{{ markdown }}</article>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
To learn about creating your own color themes, read the [adding custom color themes](#adding-custom-color-themes) documentation.
|
|
141
|
+
|
|
142
|
+
### Element modifiers
|
|
143
|
+
|
|
144
|
+
Use element modifiers to customize the style of individual elements in your content directly in your HTML:
|
|
145
|
+
|
|
146
|
+
```html
|
|
147
|
+
<article class="prose prose-img:rounded-xl prose-headings:underline prose-a:text-blue-600">
|
|
148
|
+
{{ markdown }}
|
|
149
|
+
</article>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
This makes it easy to do things like style links to match your brand, add a border radius to images, and tons more.
|
|
153
|
+
|
|
154
|
+
Here's a complete list of available element modifiers:
|
|
155
|
+
|
|
156
|
+
| Modifier | Target |
|
|
157
|
+
| ---------------------------- | ---------------------------- |
|
|
158
|
+
| `prose-headings:{utility}` | `h1`, `h2`, `h3`, `h4`, `th` |
|
|
159
|
+
| `prose-lead:{utility}` | `[class~="lead"]` |
|
|
160
|
+
| `prose-h1:{utility}` | `h1` |
|
|
161
|
+
| `prose-h2:{utility}` | `h2` |
|
|
162
|
+
| `prose-h3:{utility}` | `h3` |
|
|
163
|
+
| `prose-h4:{utility}` | `h4` |
|
|
164
|
+
| `prose-p:{utility}` | `p` |
|
|
165
|
+
| `prose-a:{utility}` | `a` |
|
|
166
|
+
| `prose-blockquote:{utility}` | `blockquote` |
|
|
167
|
+
| `prose-figure:{utility}` | `figure` |
|
|
168
|
+
| `prose-figcaption:{utility}` | `figcaption` |
|
|
169
|
+
| `prose-strong:{utility}` | `strong` |
|
|
170
|
+
| `prose-em:{utility}` | `em` |
|
|
171
|
+
| `prose-kbd:{utility}` | `kbd` |
|
|
172
|
+
| `prose-code:{utility}` | `code` |
|
|
173
|
+
| `prose-pre:{utility}` | `pre` |
|
|
174
|
+
| `prose-ol:{utility}` | `ol` |
|
|
175
|
+
| `prose-ul:{utility}` | `ul` |
|
|
176
|
+
| `prose-li:{utility}` | `li` |
|
|
177
|
+
| `prose-dl:{utility}` | `dl` |
|
|
178
|
+
| `prose-dt:{utility}` | `dt` |
|
|
179
|
+
| `prose-dd:{utility}` | `dd` |
|
|
180
|
+
| `prose-table:{utility}` | `table` |
|
|
181
|
+
| `prose-thead:{utility}` | `thead` |
|
|
182
|
+
| `prose-tr:{utility}` | `tr` |
|
|
183
|
+
| `prose-th:{utility}` | `th` |
|
|
184
|
+
| `prose-td:{utility}` | `td` |
|
|
185
|
+
| `prose-img:{utility}` | `img` |
|
|
186
|
+
| `prose-picture:{utility}` | `picture` |
|
|
187
|
+
| `prose-video:{utility}` | `video` |
|
|
188
|
+
| `prose-hr:{utility}` | `hr` |
|
|
189
|
+
|
|
190
|
+
When stacking these modifiers with other modifiers like `hover`, you most likely want the other modifier to come last:
|
|
191
|
+
|
|
192
|
+
```html
|
|
193
|
+
<article class="prose prose-a:text-blue-600 prose-a:hover:text-blue-500">{{ markdown }}</article>
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
If you are still using in Tailwind CSS v3, the modifier order is the opposite:
|
|
197
|
+
|
|
198
|
+
```html
|
|
199
|
+
<article class="prose prose-a:text-blue-600 hover:prose-a:text-blue-500">{{ markdown }}</article>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Read the Tailwind CSS documentation on [stacked modifiers](https://tailwindcss.com/docs/hover-focus-and-other-states) to learn more.
|
|
203
|
+
|
|
204
|
+
### Overriding max-width
|
|
205
|
+
|
|
206
|
+
Each size modifier comes with a baked in `max-width` designed to keep the content as readable as possible. This isn't always what you want though, and sometimes you'll want the content to just fill the width of its container.
|
|
207
|
+
|
|
208
|
+
In those cases, all you need to do is add `max-w-none` to your content to override the embedded max-width:
|
|
209
|
+
|
|
210
|
+
```html
|
|
211
|
+
<div class="grid grid-cols-4">
|
|
212
|
+
<div class="col-span-1">
|
|
213
|
+
<!-- ... -->
|
|
214
|
+
</div>
|
|
215
|
+
<div class="col-span-3">
|
|
216
|
+
<article class="prose max-w-none">{{ markdown }}</article>
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Advanced topics
|
|
224
|
+
|
|
225
|
+
### Undoing typography styles
|
|
226
|
+
|
|
227
|
+
If you have a block of markup embedded in some content that shouldn't inherit the `prose` styles, use the `not-prose` class to sandbox it:
|
|
228
|
+
|
|
229
|
+
```html
|
|
230
|
+
<article class="prose">
|
|
231
|
+
<h1>My Heading</h1>
|
|
232
|
+
<p>...</p>
|
|
233
|
+
|
|
234
|
+
<div class="not-prose">
|
|
235
|
+
<!-- Some example or demo that needs to be prose-free -->
|
|
236
|
+
</div>
|
|
237
|
+
|
|
238
|
+
<p>...</p>
|
|
239
|
+
<!-- ... -->
|
|
240
|
+
</article>
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Note that you can't nest new `prose` instances within a `not-prose` block at this time.
|
|
244
|
+
|
|
245
|
+
Even when using a prefix for your utilities `not-prose` should not have a prefix.
|
|
246
|
+
|
|
247
|
+
### Adding custom color themes
|
|
248
|
+
|
|
249
|
+
To customize the color theme beyond simple CSS overrides, add a `@utility` directive to your CSS file:
|
|
250
|
+
|
|
251
|
+
```css
|
|
252
|
+
@utility prose-pink {
|
|
253
|
+
--tw-prose-body: var(--color-pink-800);
|
|
254
|
+
--tw-prose-headings: var(--color-pink-900);
|
|
255
|
+
--tw-prose-lead: var(--color-pink-700);
|
|
256
|
+
--tw-prose-links: var(--color-pink-900);
|
|
257
|
+
--tw-prose-bold: var(--color-pink-900);
|
|
258
|
+
--tw-prose-counters: var(--color-pink-600);
|
|
259
|
+
--tw-prose-bullets: var(--color-pink-400);
|
|
260
|
+
--tw-prose-hr: var(--color-pink-300);
|
|
261
|
+
--tw-prose-quotes: var(--color-pink-900);
|
|
262
|
+
--tw-prose-quote-borders: var(--color-pink-300);
|
|
263
|
+
--tw-prose-captions: var(--color-pink-700);
|
|
264
|
+
--tw-prose-code: var(--color-pink-900);
|
|
265
|
+
--tw-prose-pre-code: var(--color-pink-100);
|
|
266
|
+
--tw-prose-pre-bg: var(--color-pink-900);
|
|
267
|
+
--tw-prose-th-borders: var(--color-pink-300);
|
|
268
|
+
--tw-prose-td-borders: var(--color-pink-200);
|
|
269
|
+
--tw-prose-invert-body: var(--color-pink-200);
|
|
270
|
+
--tw-prose-invert-headings: var(--color-white);
|
|
271
|
+
--tw-prose-invert-lead: var(--color-pink-300);
|
|
272
|
+
--tw-prose-invert-links: var(--color-white);
|
|
273
|
+
--tw-prose-invert-bold: var(--color-white);
|
|
274
|
+
--tw-prose-invert-counters: var(--color-pink-400);
|
|
275
|
+
--tw-prose-invert-bullets: var(--color-pink-600);
|
|
276
|
+
--tw-prose-invert-hr: var(--color-pink-700);
|
|
277
|
+
--tw-prose-invert-quotes: var(--color-pink-100);
|
|
278
|
+
--tw-prose-invert-quote-borders: var(--color-pink-700);
|
|
279
|
+
--tw-prose-invert-captions: var(--color-pink-400);
|
|
280
|
+
--tw-prose-invert-code: var(--color-white);
|
|
281
|
+
--tw-prose-invert-pre-code: var(--color-pink-300);
|
|
282
|
+
--tw-prose-invert-pre-bg: rgb(0 0 0 / 50%);
|
|
283
|
+
--tw-prose-invert-th-borders: var(--color-pink-600);
|
|
284
|
+
--tw-prose-invert-td-borders: var(--color-pink-700);
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
For Tailwind v3, update the `typography` section in the JavaScript config file and provide your colors under the `css` key:
|
|
289
|
+
|
|
290
|
+
```js {{ filename: 'tailwind.config.js' }}
|
|
291
|
+
/** @type {import('tailwindcss').Config} */
|
|
292
|
+
module.exports = {
|
|
293
|
+
theme: {
|
|
294
|
+
extend: {
|
|
295
|
+
typography: () => ({
|
|
296
|
+
pink: {
|
|
297
|
+
css: {
|
|
298
|
+
'--tw-prose-body': 'var(--color-pink-800)',
|
|
299
|
+
'--tw-prose-headings': 'var(--color-pink-900)',
|
|
300
|
+
'--tw-prose-lead': 'var(--color-pink-700)',
|
|
301
|
+
'--tw-prose-links': 'var(--color-pink-900)',
|
|
302
|
+
'--tw-prose-bold': 'var(--color-pink-900)',
|
|
303
|
+
'--tw-prose-counters': 'var(--color-pink-600)',
|
|
304
|
+
'--tw-prose-bullets': 'var(--color-pink-400)',
|
|
305
|
+
'--tw-prose-hr': 'var(--color-pink-300)',
|
|
306
|
+
'--tw-prose-quotes': 'var(--color-pink-900)',
|
|
307
|
+
'--tw-prose-quote-borders': 'var(--color-pink-300)',
|
|
308
|
+
'--tw-prose-captions': 'var(--color-pink-700)',
|
|
309
|
+
'--tw-prose-code': 'var(--color-pink-900)',
|
|
310
|
+
'--tw-prose-pre-code': 'var(--color-pink-100)',
|
|
311
|
+
'--tw-prose-pre-bg': 'var(--color-pink-900)',
|
|
312
|
+
'--tw-prose-th-borders': 'var(--color-pink-300)',
|
|
313
|
+
'--tw-prose-td-borders': 'var(--color-pink-200)',
|
|
314
|
+
'--tw-prose-invert-body': 'var(--color-pink-200)',
|
|
315
|
+
'--tw-prose-invert-headings': 'var(--color-white)',
|
|
316
|
+
'--tw-prose-invert-lead': 'var(--color-pink-300)',
|
|
317
|
+
'--tw-prose-invert-links': 'var(--color-white)',
|
|
318
|
+
'--tw-prose-invert-bold': 'var(--color-white)',
|
|
319
|
+
'--tw-prose-invert-counters': 'var(--color-pink-400)',
|
|
320
|
+
'--tw-prose-invert-bullets': 'var(--color-pink-600)',
|
|
321
|
+
'--tw-prose-invert-hr': 'var(--color-pink-700)',
|
|
322
|
+
'--tw-prose-invert-quotes': 'var(--color-pink-100)',
|
|
323
|
+
'--tw-prose-invert-quote-borders': 'var(--color-pink-700)',
|
|
324
|
+
'--tw-prose-invert-captions': 'var(--color-pink-400)',
|
|
325
|
+
'--tw-prose-invert-code': 'var(--color-white)',
|
|
326
|
+
'--tw-prose-invert-pre-code': 'var(--color-pink-300)',
|
|
327
|
+
'--tw-prose-invert-pre-bg': 'rgb(0 0 0 / 50%)',
|
|
328
|
+
'--tw-prose-invert-th-borders': 'var(--color-pink-600)',
|
|
329
|
+
'--tw-prose-invert-td-borders': 'var(--color-pink-700)',
|
|
330
|
+
},
|
|
331
|
+
},
|
|
332
|
+
}),
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
### Changing the default class name
|
|
340
|
+
|
|
341
|
+
If you need to use a class name other than `prose` for any reason, you can do so using the `className` option when registering the plugin:
|
|
342
|
+
|
|
343
|
+
```css
|
|
344
|
+
@import 'tailwindcss';
|
|
345
|
+
@plugin "typography-stylecss" {
|
|
346
|
+
classname: wysiwyg;
|
|
347
|
+
}
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
Now every instance of `prose` in the default class names will be replaced by your custom class name:
|
|
351
|
+
|
|
352
|
+
```html
|
|
353
|
+
<article class="wysiwyg wysiwyg-slate lg:wysiwyg-xl">
|
|
354
|
+
<h1>My Heading</h1>
|
|
355
|
+
<p>...</p>
|
|
356
|
+
|
|
357
|
+
<div class="not-wysiwyg">
|
|
358
|
+
<!-- Some example or demo that needs to be prose-free -->
|
|
359
|
+
</div>
|
|
360
|
+
|
|
361
|
+
<p>...</p>
|
|
362
|
+
<!-- ... -->
|
|
363
|
+
</article>
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
### Customizing the CSS
|
|
367
|
+
|
|
368
|
+
If you want to customize the raw CSS generated by this plugin, you can use the JavaScript based theme API. To do that, use the `@config` directive:
|
|
369
|
+
|
|
370
|
+
```diff
|
|
371
|
+
@import "tailwindcss";
|
|
372
|
+
@plugin "typography-stylecss";
|
|
373
|
+
+ @config "./tailwind.config.js";
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
You can then create your own config by adding a new `tailwind.config.js` file with the `typography` section and providing your styles under the `css` key:
|
|
377
|
+
|
|
378
|
+
```js {{ filename: 'tailwind.config.js' }}
|
|
379
|
+
/** @type {import('tailwindcss').Config} */
|
|
380
|
+
module.exports = {
|
|
381
|
+
theme: {
|
|
382
|
+
extend: {
|
|
383
|
+
typography: {
|
|
384
|
+
DEFAULT: {
|
|
385
|
+
css: {
|
|
386
|
+
color: '#333',
|
|
387
|
+
a: {
|
|
388
|
+
color: '#3182ce',
|
|
389
|
+
'&:hover': {
|
|
390
|
+
color: '#2c5282',
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
}
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
Like with all theme customizations in Tailwind, you can use CSS variables if you need access to access your theme configuration:
|
|
402
|
+
|
|
403
|
+
```js {{ filename: 'tailwind.config.js' }}
|
|
404
|
+
/** @type {import('tailwindcss').Config} */
|
|
405
|
+
module.exports = {
|
|
406
|
+
theme: {
|
|
407
|
+
extend: {
|
|
408
|
+
typography: {
|
|
409
|
+
DEFAULT: {
|
|
410
|
+
css: {
|
|
411
|
+
color: 'var(--color-gray-800)',
|
|
412
|
+
// ...
|
|
413
|
+
},
|
|
414
|
+
},
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
},
|
|
418
|
+
}
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
Customizations should be applied to a specific modifier like `DEFAULT` or `xl`, and must be added under the `css` property. Customizations are authored in the same [CSS-in-JS syntax](https://v3.tailwindcss.com/docs/plugins#css-in-js-syntax) used to write Tailwind v3 plugins.
|
|
422
|
+
|
|
423
|
+
---
|
|
424
|
+
|
|
425
|
+
## Community
|
|
426
|
+
|
|
427
|
+
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
|
|
428
|
+
|
|
429
|
+
[Discuss the Tailwind CSS Typography plugin on GitHub](https://github.com/tailwindlabs/tailwindcss/discussions)
|
|
430
|
+
|
|
431
|
+
For casual chit-chat with others using the framework:
|
|
432
|
+
|
|
433
|
+
[Join the Tailwind CSS Discord Server](https://tailwindcss.com/discord)
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "typography-stylecss",
|
|
3
|
+
"version": "0.7.2",
|
|
4
|
+
"description": "This is a Tailwind CSS plugin for automatically styling the content of plain HTML with beautiful, stylish typographic defaults.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"types": "src/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"src/*.js",
|
|
9
|
+
"src/*.d.ts",
|
|
10
|
+
"dist/"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"prettier": {
|
|
17
|
+
"printWidth": 100,
|
|
18
|
+
"semi": false,
|
|
19
|
+
"singleQuote": true,
|
|
20
|
+
"trailingComma": "es5"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "jest",
|
|
24
|
+
"dev": "next dev demo",
|
|
25
|
+
"build": "next build demo",
|
|
26
|
+
"export": "next export demo",
|
|
27
|
+
"start": "next start demo",
|
|
28
|
+
"release-channel": "node ./scripts/release-channel.js",
|
|
29
|
+
"release-notes": "node ./scripts/release-notes.js"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"tailwindcss": ">=3.0.0 || insiders || >=4.0.0-alpha.20 || >=4.0.0-beta.1"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@mdx-js/loader": "^1.0.19",
|
|
36
|
+
"@mdx-js/mdx": "^1.6.6",
|
|
37
|
+
"@next/mdx": "^8.1.0",
|
|
38
|
+
"@tailwindcss/typography": "0.5.19",
|
|
39
|
+
"autoprefixer": "^10.2.1",
|
|
40
|
+
"highlight.js": "^10.4.1",
|
|
41
|
+
"jest": "^29.7.0",
|
|
42
|
+
"jest-diff": "^27.3.1",
|
|
43
|
+
"next": "^12.0.1",
|
|
44
|
+
"postcss": "^8.2.3",
|
|
45
|
+
"prettier": "^2.1.2",
|
|
46
|
+
"react": "^17.0.2",
|
|
47
|
+
"react-dom": "^17.0.2",
|
|
48
|
+
"tailwindcss": "^3.2.2"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"postcss-selector-parser": "6.0.10"
|
|
52
|
+
},
|
|
53
|
+
"jest": {
|
|
54
|
+
"setupFilesAfterEnv": [
|
|
55
|
+
"<rootDir>/jest/customMatchers.js"
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
const plugin = require('tailwindcss/plugin')
|
|
2
|
+
const styles = require('./styles')
|
|
3
|
+
const { commonTrailingPseudos, isObject, isPlainObject, merge, castArray } = require('./utils')
|
|
4
|
+
|
|
5
|
+
const computed = {
|
|
6
|
+
// Reserved for future "magic properties", for example:
|
|
7
|
+
// bulletColor: (color) => ({ 'ul > li::before': { backgroundColor: color } }),
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function inWhere(selector, { className, modifier, prefix }) {
|
|
11
|
+
let prefixedNot = prefix(`.not-${className}`).slice(1)
|
|
12
|
+
let selectorPrefix = selector.startsWith('>')
|
|
13
|
+
? `${modifier === 'DEFAULT' ? `.${className}` : `.${className}-${modifier}`} `
|
|
14
|
+
: ''
|
|
15
|
+
|
|
16
|
+
// Parse the selector, if every component ends in the same pseudo element(s) then move it to the end
|
|
17
|
+
let [trailingPseudo, rebuiltSelector] = commonTrailingPseudos(selector)
|
|
18
|
+
|
|
19
|
+
if (trailingPseudo) {
|
|
20
|
+
return `:where(${selectorPrefix}${rebuiltSelector}):not(:where([class~="${prefixedNot}"],[class~="${prefixedNot}"] *))${trailingPseudo}`
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return `:where(${selectorPrefix}${selector}):not(:where([class~="${prefixedNot}"],[class~="${prefixedNot}"] *))`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function configToCss(config = {}, { target, className, modifier, prefix }) {
|
|
27
|
+
function updateSelector(k, v) {
|
|
28
|
+
if (target === 'legacy') {
|
|
29
|
+
return [k, v]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (Array.isArray(v)) {
|
|
33
|
+
return [k, v]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (isObject(v)) {
|
|
37
|
+
let nested = Object.values(v).some(isObject)
|
|
38
|
+
if (nested) {
|
|
39
|
+
return [
|
|
40
|
+
inWhere(k, { className, modifier, prefix }),
|
|
41
|
+
v,
|
|
42
|
+
Object.fromEntries(Object.entries(v).map(([k, v]) => updateSelector(k, v))),
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return [inWhere(k, { className, modifier, prefix }), v]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return [k, v]
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return Object.fromEntries(
|
|
53
|
+
Object.entries(
|
|
54
|
+
merge(
|
|
55
|
+
{},
|
|
56
|
+
...Object.keys(config)
|
|
57
|
+
.filter((key) => computed[key])
|
|
58
|
+
.map((key) => computed[key](config[key])),
|
|
59
|
+
...castArray(config.css || {})
|
|
60
|
+
)
|
|
61
|
+
).map(([k, v]) => updateSelector(k, v))
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = plugin.withOptions(
|
|
66
|
+
({ className = 'prose', target = 'modern' } = {}) => {
|
|
67
|
+
return function ({ addVariant, addComponents, theme, prefix }) {
|
|
68
|
+
let modifiers = theme('typography')
|
|
69
|
+
|
|
70
|
+
let options = { className, prefix }
|
|
71
|
+
|
|
72
|
+
for (let [name, ...selectors] of [
|
|
73
|
+
['headings', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'th'],
|
|
74
|
+
['h1'],
|
|
75
|
+
['h2'],
|
|
76
|
+
['h3'],
|
|
77
|
+
['h4'],
|
|
78
|
+
['h5'],
|
|
79
|
+
['h6'],
|
|
80
|
+
['p'],
|
|
81
|
+
['a'],
|
|
82
|
+
['blockquote'],
|
|
83
|
+
['figure'],
|
|
84
|
+
['figcaption'],
|
|
85
|
+
['strong'],
|
|
86
|
+
['em'],
|
|
87
|
+
['kbd'],
|
|
88
|
+
['code'],
|
|
89
|
+
['pre'],
|
|
90
|
+
['ol'],
|
|
91
|
+
['ul'],
|
|
92
|
+
['li'],
|
|
93
|
+
['dl'],
|
|
94
|
+
['dt'],
|
|
95
|
+
['dd'],
|
|
96
|
+
['table'],
|
|
97
|
+
['thead'],
|
|
98
|
+
['tr'],
|
|
99
|
+
['th'],
|
|
100
|
+
['td'],
|
|
101
|
+
['img'],
|
|
102
|
+
['picture'],
|
|
103
|
+
['video'],
|
|
104
|
+
['hr'],
|
|
105
|
+
['lead', '[class~="lead"]'],
|
|
106
|
+
]) {
|
|
107
|
+
selectors = selectors.length === 0 ? [name] : selectors
|
|
108
|
+
|
|
109
|
+
let selector =
|
|
110
|
+
target === 'legacy' ? selectors.map((selector) => `& ${selector}`) : selectors.join(', ')
|
|
111
|
+
|
|
112
|
+
addVariant(
|
|
113
|
+
`${className}-${name}`,
|
|
114
|
+
target === 'legacy' ? selector : `& :is(${inWhere(selector, options)})`
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
addComponents(
|
|
119
|
+
Object.keys(modifiers).map((modifier) => ({
|
|
120
|
+
[modifier === 'DEFAULT' ? `.${className}` : `.${className}-${modifier}`]: configToCss(
|
|
121
|
+
modifiers[modifier],
|
|
122
|
+
{
|
|
123
|
+
target,
|
|
124
|
+
className,
|
|
125
|
+
modifier,
|
|
126
|
+
prefix,
|
|
127
|
+
}
|
|
128
|
+
),
|
|
129
|
+
}))
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
() => {
|
|
134
|
+
return {
|
|
135
|
+
theme: { typography: styles },
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
);
|