@tailwindcss/typography
Advanced tools
Comparing version 0.0.0-insiders.19f79cb to 0.0.0-insiders.1b543ba
@@ -10,4 +10,14 @@ # Changelog | ||
- Nothing yet! | ||
## [0.5.1] - 2022-01-28 | ||
### Removed | ||
- Remove `dist` folder and related dependencies ([#226](https://github.com/tailwindlabs/tailwindcss-typography/pull/226)) | ||
### Fixed | ||
- Don't generate invalid CSS when given an array of property values ([#224](https://github.com/tailwindlabs/tailwindcss-typography/pull/224)) | ||
## [0.5.0] - 2021-12-09 | ||
## [0.5.0-alpha.3] - 2021-11-08 | ||
@@ -28,3 +38,3 @@ | ||
### Fixed | ||
### Fixed | ||
@@ -101,3 +111,5 @@ - Fix list-style modifier selectors ([#137](https://github.com/tailwindlabs/tailwindcss-typography/pull/137)) | ||
[unreleased]: https://github.com/tailwindlabs/tailwindcss-typography/compare/v0.5.0-alpha.3...HEAD | ||
[unreleased]: https://github.com/tailwindlabs/tailwindcss-typography/compare/v0.5.1...HEAD | ||
[0.5.1]: https://github.com/tailwindlabs/tailwindcss-typography/compare/v0.5.0...v0.5.1 | ||
[0.5.0]: https://github.com/tailwindlabs/tailwindcss-typography/compare/v0.5.0-alpha.3...v0.5.0 | ||
[0.5.0-alpha.3]: https://github.com/tailwindlabs/tailwindcss-typography/compare/v0.5.0-alpha.2...v0.5.0-alpha.3 | ||
@@ -104,0 +116,0 @@ [0.5.0-alpha.2]: https://github.com/tailwindlabs/tailwindcss-typography/compare/v0.5.0-alpha.1...v0.5.0-alpha.2 |
{ | ||
"name": "@tailwindcss/typography", | ||
"version": "0.0.0-insiders.19f79cb", | ||
"version": "0.0.0-insiders.1b543ba", | ||
"description": "A Tailwind CSS plugin for automatically styling plain HTML content with beautiful typographic defaults.", | ||
@@ -36,5 +36,2 @@ "main": "src/index.js", | ||
"autoprefixer": "^10.2.1", | ||
"clean-css": "^4.2.1", | ||
"cssnano": "^4.1.10", | ||
"dedent": "^0.7.0", | ||
"highlight.js": "^10.4.1", | ||
@@ -48,3 +45,2 @@ "jest": "^26.6.1", | ||
"react-dom": "^17.0.2", | ||
"snapshot-diff": "^0.8.1", | ||
"tailwindcss": "^3.0.0-alpha.2" | ||
@@ -55,4 +51,3 @@ }, | ||
"lodash.isplainobject": "^4.0.6", | ||
"lodash.merge": "^4.6.2", | ||
"lodash.uniq": "^4.5.0" | ||
"lodash.merge": "^4.6.2" | ||
}, | ||
@@ -59,0 +54,0 @@ "jest": { |
379
README.md
<p> | ||
<img alt="Tailwind CSS Typography" width="350" src="./.github/logo.svg"> | ||
<a href="https://tailwindcss.com/docs/typography-plugin#gh-light-mode-only" target="_blank"> | ||
<img src="./.github/logo-light.svg" alt="Tailwind CSS Typography" width="450" height="70"> | ||
</a> | ||
<a href="https://tailwindcss.com/docs/typography-plugin#gh-dark-mode-only" target="_blank"> | ||
<img src="./.github/logo-dark.svg" alt="Tailwind CSS Typography" width="450" height="70"> | ||
</a> | ||
</p> | ||
**As of v0.3.0, @tailwindcss/typography is designed for Tailwind CSS v2.0+.** | ||
A plugin that provides a set of `prose` classes you can use to add beautiful typographic defaults to any vanilla HTML you don't control, like HTML rendered from Markdown, or pulled from a CMS. | ||
A plugin that provides a set of `prose` classes you can use to add beautiful typographic defaults to any vanilla HTML you don't control (like HTML rendered from Markdown, or pulled from a CMS). | ||
--- | ||
[View live demo](https://tailwindcss-typography.vercel.app/) | ||
## Documentation | ||
```html | ||
<article class="prose lg:prose-xl"> | ||
{{ markdown }} | ||
</article> | ||
``` | ||
For full documentation, visit [tailwindcss.com/docs/typography-plugin](https://tailwindcss.com/docs/typography-plugin). | ||
## Installation | ||
## Community | ||
Install the plugin from npm: | ||
For help, discussion about best practices, or any other conversation that would benefit from being searchable: | ||
```sh | ||
# Using npm | ||
npm install @tailwindcss/typography | ||
[Discuss the Tailwind CSS Typography plugin on GitHub](https://github.com/tailwindlabs/tailwindcss/discussions) | ||
# Using Yarn | ||
yarn add @tailwindcss/typography | ||
``` | ||
For casual chit-chat with others using the framework: | ||
Then add the plugin to your `tailwind.config.js` file: | ||
```js | ||
// tailwind.config.js | ||
module.exports = { | ||
theme: { | ||
// ... | ||
}, | ||
plugins: [ | ||
require('@tailwindcss/typography'), | ||
// ... | ||
], | ||
} | ||
``` | ||
### Using a CDN | ||
If you need to pull in these styles via CDN, you can do so using services like UNPKG or jsDeliver: | ||
```html | ||
<!-- From UNPKG --> | ||
<link | ||
rel="stylesheet" | ||
href="https://unpkg.com/@tailwindcss/typography@0.4.x/dist/typography.min.css" | ||
/> | ||
<!-- From jsDelivr --> | ||
<link | ||
rel="stylesheet" | ||
href="https://cdn.jsdelivr.net/npm/@tailwindcss/typography@0.4.x/dist/typography.min.css" | ||
/> | ||
``` | ||
To use these styles alongside the rest of Tailwind via CDN, we recommend pulling in each layer separately so you can put the styles in the correct order: | ||
```html | ||
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@^1.5/dist/base.min.css" /> | ||
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@^1.5/dist/components.min.css" /> | ||
<link | ||
rel="stylesheet" | ||
href="https://unpkg.com/@tailwindcss/typography@0.2.x/dist/typography.min.css" | ||
/> | ||
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@^1.5/dist/utilities.min.css" /> | ||
``` | ||
## Usage | ||
Now you can use the `prose` classes to add sensible typography styles to any vanilla HTML: | ||
```html | ||
<article class="prose lg:prose-xl"> | ||
<h1>Garlic bread with cheese: What the science tells us</h1> | ||
<p> | ||
For years parents have espoused the health benefits of eating garlic bread with cheese to their | ||
children, with the food earning such an iconic status in our culture that kids will often dress | ||
up as warm, cheesy loaf for Halloween. | ||
</p> | ||
<p> | ||
But a recent study shows that the celebrated appetizer may be linked to a series of rabies cases | ||
springing up around the country. | ||
</p> | ||
<!-- ... --> | ||
</article> | ||
``` | ||
### Size modifiers | ||
Size modifiers allow you to adjust the overall size of your typography for different contexts. | ||
```html | ||
<article class="prose prose-xl"> | ||
{{ markdown }} | ||
</article> | ||
``` | ||
Five different typography sizes are included out of the box: | ||
| Class | Body font size | | ||
| ----------- | --------------: | | ||
| `prose-sm` | 0.875rem (14px) | | ||
| `prose` | 1rem (16px) | | ||
| `prose-lg` | 1.125rem (18px) | | ||
| `prose-xl` | 1.25rem (20px) | | ||
| `prose-2xl` | 1.5rem (24px) | | ||
Everything about the provided size modifiers has been hand-tuned to look as beautiful as possible, including the relationships between font sizes, heading spacing, code block padding, etc. Just like the Tailwind color palettes, none of these styles are based on naive mathematical formulas, and have been hand-crafted by professional designers. | ||
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**: | ||
```html | ||
<!-- Will not work --> | ||
<article class="prose-lg"> | ||
{{ markdown }} | ||
</article> | ||
<!-- Always add the `prose` class --> | ||
<article class="prose prose-lg"> | ||
{{ markdown }} | ||
</article> | ||
``` | ||
### Color modifiers | ||
Color modifiers allow you to "brand" your typography sections by changing the link color. By default, modifiers are generated for every color in your color palette that include a `600` shade except for `gray` since it's the default. | ||
```html | ||
<article class="prose prose-indigo"> | ||
{{ markdown }} | ||
</article> | ||
``` | ||
Here are the classes that are generated using a totally default Tailwind CSS v2.0 build: | ||
| Class | Link color | | ||
| -------------- | ------------ | | ||
| `prose-red` | `red.600` | | ||
| `prose-yellow` | `yellow.600` | | ||
| `prose-green` | `green.600` | | ||
| `prose-blue` | `blue.600` | | ||
| `prose-indigo` | `indigo.600` | | ||
| `prose-purple` | `purple.600` | | ||
| `prose-pink` | `pink.600` | | ||
For more control, use the [low-level customization API](#customization). | ||
### Responsive variants | ||
None of the sizes are automatically responsive, but responsive variants are provided for each size modifier so you can easily change the typography size at different breakpoints: | ||
```html | ||
<article class="prose prose-sm sm:prose lg:prose-lg xl:prose-xl"> | ||
{{ markdown }} | ||
</article> | ||
``` | ||
## Customization | ||
> The customization API is currently extremely low-level in order to be as flexible as possible. We will be introducing higher-level configuration options over time as we learn what types of customizations are most common. | ||
To customize the styles provided by this plugin, add your overrides under the `typography` key in the `theme` section of your `tailwind.config.js` file: | ||
```js | ||
// tailwind.config.js | ||
module.exports = { | ||
theme: { | ||
extend: { | ||
typography: { | ||
DEFAULT: { | ||
css: { | ||
color: '#333', | ||
a: { | ||
color: '#3182ce', | ||
'&:hover': { | ||
color: '#2c5282', | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
}, | ||
}, | ||
plugins: [ | ||
require('@tailwindcss/typography'), | ||
// ... | ||
], | ||
} | ||
``` | ||
Like with all theme customizations in Tailwind, you can also define the `typography` key as a function if you need access to the `theme` helper: | ||
```js | ||
// tailwind.config.js | ||
module.exports = { | ||
theme: { | ||
extend: { | ||
typography: (theme) => ({ | ||
DEFAULT: { | ||
css: { | ||
color: theme('colors.gray.800'), | ||
// ... | ||
}, | ||
}, | ||
}), | ||
} | ||
}, | ||
plugins: [ | ||
require('@tailwindcss/typography'), | ||
// ... | ||
], | ||
} | ||
``` | ||
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://tailwindcss.com/docs/plugins#css-in-js-syntax) used to write Tailwind plugins. | ||
It's important to note that all customizations are **merged** with the defaults. If you'd like to completely override a provided size modifier, you can do so by disabling that modifier so the default styles are not included. | ||
See [the default styles](./src/styles.js) for this plugin for more in-depth examples of configuring each modifier. | ||
### Customizing shared styles | ||
Many styles _(for example colors, font weight, and text decoration)_ are shared between all size modifiers, and are therefore defined only for the `DEFAULT` modifier, since modifiers are designed to be used with the [multi-class modifier pattern](http://nicolasgallagher.com/about-html-semantics-front-end-architecture/#component-modifiers). | ||
If you'd like to customize these sorts of styles, do so using the `DEFAULT` modifier: | ||
```js | ||
// tailwind.config.js | ||
module.exports = { | ||
theme: { | ||
extend: { | ||
typography: { | ||
DEFAULT: { | ||
css: { | ||
color: '#333', | ||
strong: { | ||
fontWeight: '800', | ||
}, | ||
// ... | ||
}, | ||
}, | ||
}, | ||
} | ||
}, | ||
plugins: [ | ||
require('@tailwindcss/typography'), | ||
// ... | ||
], | ||
} | ||
``` | ||
### Adding new modifiers | ||
You can add a new modifier by creating a new key in the `typography` section of your theme and providing your own styles under the `css` key: | ||
```js | ||
// tailwind.config.js | ||
module.exports = { | ||
theme: { | ||
extend: { | ||
typography: { | ||
'3xl': { | ||
css: { | ||
fontSize: '1.875rem', | ||
h1: { | ||
fontSize: '4rem', | ||
}, | ||
// ... | ||
}, | ||
}, | ||
}, | ||
} | ||
}, | ||
plugins: [ | ||
require('@tailwindcss/typography'), | ||
// ... | ||
], | ||
} | ||
``` | ||
### Overriding max-width | ||
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. | ||
In those cases, all you need to do is add `max-w-none` to your content to override the embedded max-width: | ||
```html | ||
<div class="grid grid-cols-4"> | ||
<div class="col-span-1"> | ||
<!-- ... --> | ||
</div> | ||
<div class="col-span-3"> | ||
<article class="prose max-w-none"> | ||
{{ markdown }} | ||
</article> | ||
</div> | ||
</div> | ||
``` | ||
### Disabling size modifiers | ||
If you'd like to completely disable any size modifiers (either for file size reasons or because you'd like to completely redefine that modifier), you can do so using the `modifiers` option when including the plugin: | ||
```js | ||
// tailwind.config.js | ||
module.exports = { | ||
theme: { | ||
// ... | ||
}, | ||
plugins: [ | ||
require('@tailwindcss/typography')({ | ||
modifiers: ['sm', 'lg'], | ||
}), | ||
// ... | ||
], | ||
} | ||
``` | ||
This option acts as a _safelist_, so you can list only the modifiers you'd actually like included and the others will be removed. | ||
The `DEFAULT` modifier is always included and cannot be disabled. | ||
### Disabling responsive variants | ||
If you'd like to disable the responsive variants for any reason, you can do so by setting the `typography` key to an empty array in the `variants` section of your `tailwind.config.js` file: | ||
```js | ||
// tailwind.config.js | ||
module.exports = { | ||
theme: { | ||
// ... | ||
}, | ||
plugins: [ | ||
require('@tailwindcss/typography'), | ||
// ... | ||
], | ||
variants: { | ||
typography: [], | ||
}, | ||
} | ||
``` | ||
### Changing the default class name | ||
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: | ||
```js | ||
// tailwind.config.js | ||
module.exports = { | ||
theme: { | ||
// ... | ||
}, | ||
plugins: [ | ||
require('@tailwindcss/typography')({ | ||
className: 'markdown', | ||
}), | ||
] | ||
... | ||
} | ||
``` | ||
```html | ||
<article class="markdown md:markdown-lg"> | ||
{{ markdown }} | ||
</article> | ||
``` | ||
[Join the Tailwind CSS Discord Server](https://tailwindcss.com/discord) |
@@ -52,2 +52,6 @@ const plugin = require('tailwindcss/plugin') | ||
if (Array.isArray(v)) { | ||
return [k, v] | ||
} | ||
if (isObject(v)) { | ||
@@ -54,0 +58,0 @@ let nested = Object.values(v).some(isObject) |
@@ -806,1 +806,29 @@ const path = require('path') | ||
}) | ||
test('customizing defaults with multiple values does not result in invalid css', async () => { | ||
let config = { | ||
plugins: [typographyPlugin()], | ||
content: [ | ||
{ | ||
raw: html`<div class="prose"></div>`, | ||
}, | ||
], | ||
theme: { | ||
typography: { | ||
DEFAULT: { | ||
css: { | ||
textAlign: ['-webkit-match-parent', 'match-parent'], | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
return run(config).then((result) => { | ||
// TODO: Fix this test. It should list both properties but there's a bug in tailwind that's overriding them. | ||
expect(result.css).toMatchFormattedCss(css` | ||
.prose { | ||
text-align: match-parent; | ||
} | ||
`) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
4
13
2348
0
76862
8
27
+ Addedfast-glob@3.3.3(transitive)
- Removedlodash.uniq@^4.5.0
- Removedfast-glob@3.3.2(transitive)
- Removedlodash.uniq@4.5.0(transitive)