Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tailwindcss/typography

Package Overview
Dependencies
Maintainers
5
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tailwindcss/typography - npm Package Compare versions

Comparing version 0.0.0-insiders.4c5cb76 to 0.0.0-insiders.53d93e1

53

CHANGELOG.md

@@ -12,2 +12,46 @@ # Changelog

## [0.5.5] - 2022-09-01
### Added
- Add typescript types ([#283](https://github.com/tailwindlabs/tailwindcss-typography/pull/283))
## [0.5.4] - 2022-07-12
### Fixed
- Update `strong` and `code` color styles to inherit from parent ([#276](https://github.com/tailwindlabs/tailwindcss-typography/pull/276))
## [0.5.3] - 2022-07-07
### Added
- Add styles for `tfoot` elements ([#243](https://github.com/tailwindlabs/tailwindcss-typography/pull/243))
- Add `prose-h5` and `prose-h6` variants ([#273](https://github.com/tailwindlabs/tailwindcss-typography/pull/273))
### Fixed
- Fix prose elements `legacy` mode ([#259](https://github.com/tailwindlabs/tailwindcss-typography/pull/259))
- Allow `lead` class to override element styles ([#260](https://github.com/tailwindlabs/tailwindcss-typography/pull/260))
- Fix generation of `prose-headings` variant ([#264](https://github.com/tailwindlabs/tailwindcss-typography/pull/264))
- Fix `figure` spacing ([#267](https://github.com/tailwindlabs/tailwindcss-typography/pull/267))
- Fix child combinator `:where` selectors ([#268](https://github.com/tailwindlabs/tailwindcss-typography/pull/267))
- Fix `prose-headings` variant to include `h5` and `h6` elements ([#273](https://github.com/tailwindlabs/tailwindcss-typography/pull/273))
## [0.5.2] - 2022-02-14
### Fixed
- Ensure nested selectors using `&:hover` work ([#246](https://github.com/tailwindlabs/tailwindcss-typography/pull/246))
## [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

@@ -30,3 +74,3 @@

### Fixed
### Fixed

@@ -103,3 +147,8 @@ - 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...HEAD
[unreleased]: https://github.com/tailwindlabs/tailwindcss-typography/compare/v0.5.5...HEAD
[0.5.5]: https://github.com/tailwindlabs/tailwindcss-typography/compare/v0.5.4...v0.5.5
[0.5.4]: https://github.com/tailwindlabs/tailwindcss-typography/compare/v0.5.3...v0.5.4
[0.5.3]: https://github.com/tailwindlabs/tailwindcss-typography/compare/v0.5.2...v0.5.3
[0.5.2]: https://github.com/tailwindlabs/tailwindcss-typography/compare/v0.5.1...v0.5.2
[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

@@ -106,0 +155,0 @@ [0.5.0-alpha.3]: https://github.com/tailwindlabs/tailwindcss-typography/compare/v0.5.0-alpha.2...v0.5.0-alpha.3

11

package.json
{
"name": "@tailwindcss/typography",
"version": "0.0.0-insiders.4c5cb76",
"version": "0.0.0-insiders.53d93e1",
"description": "A Tailwind CSS plugin for automatically styling plain HTML content with beautiful typographic defaults.",
"main": "src/index.js",
"types": "src/index.d.ts",
"files": [

@@ -29,3 +30,3 @@ "src/*.js",

"peerDependencies": {
"tailwindcss": ">=3.0.0 || >= 3.0.0-alpha.1 || insiders"
"tailwindcss": ">=3.0.0 || insiders"
},

@@ -37,5 +38,2 @@ "devDependencies": {

"autoprefixer": "^10.2.1",
"clean-css": "^4.2.1",
"cssnano": "^4.1.10",
"dedent": "^0.7.0",
"highlight.js": "^10.4.1",

@@ -49,3 +47,2 @@ "jest": "^26.6.1",

"react-dom": "^17.0.2",
"snapshot-diff": "^0.8.1",
"tailwindcss": "^3.0.0-alpha.2"

@@ -57,3 +54,3 @@ },

"lodash.merge": "^4.6.2",
"lodash.uniq": "^4.5.0"
"postcss-selector-parser": "6.0.10"
},

@@ -60,0 +57,0 @@ "jest": {

<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)

@@ -5,2 +5,3 @@ const plugin = require('tailwindcss/plugin')

const styles = require('./styles')
const { commonTrailingPseudos } = require('./utils')

@@ -14,29 +15,12 @@ const computed = {

let prefixedNot = prefix(`.not-${className}`).slice(1)
let selectorPrefix = selector.startsWith('>') ? `.${className} ` : ''
if (selector.endsWith('::before')) {
if (selector.startsWith('>')) {
return `> :where(${selector.slice(2, -8)}):not(:where([class~="${prefixedNot}"] *))::before`
}
return `:where(${selector.slice(0, -8)}):not(:where([class~="${prefixedNot}"] *))::before`
}
// Parse the selector, if every component ends in the same pseudo element(s) then move it to the end
let [trailingPseudo, rebuiltSelector] = commonTrailingPseudos(selector)
if (selector.endsWith('::after')) {
if (selector.startsWith('>')) {
return `> :where(${selector.slice(2, -7)}):not(:where([class~="${prefixedNot}"] *))::after`
}
return `:where(${selector.slice(0, -7)}):not(:where([class~="${prefixedNot}"] *))::after`
if (trailingPseudo) {
return `:where(${selectorPrefix}${rebuiltSelector}):not(:where([class~="${prefixedNot}"] *))${trailingPseudo}`
}
if (selector.endsWith('::marker')) {
if (selector.startsWith('>')) {
return `> :where(${selector.slice(2, -8)}):not(:where([class~="${prefixedNot}"] *))::marker`
}
return `:where(${selector.slice(0, -8)}):not(:where([class~="${prefixedNot}"] *))::marker`
}
if (selector.startsWith('>')) {
return `> :where(${selector.slice(2)}):not(:where([class~="${prefixedNot}"] *))`
}
return `:where(${selector}):not(:where([class~="${prefixedNot}"] *))`
return `:where(${selectorPrefix}${selector}):not(:where([class~="${prefixedNot}"] *))`
}

@@ -54,6 +38,14 @@

if (Array.isArray(v)) {
return [k, v]
}
if (isObject(v)) {
let nested = Object.values(v).some(isObject)
if (nested) {
return [k, Object.fromEntries(Object.entries(v).map(([k, v]) => updateSelector(k, v)))]
return [
inWhere(k, { className, prefix }),
v,
Object.fromEntries(Object.entries(v).map(([k, v]) => updateSelector(k, v))),
]
}

@@ -87,5 +79,4 @@

for (let [name, selector = name] of [
['headings', 'h1, h2, h3, h4, th'],
['lead', '[class~="lead"]'],
for (let [name, ...selectors] of [
['headings', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'th'],
['h1'],

@@ -95,2 +86,4 @@ ['h2'],

['h4'],
['h5'],
['h6'],
['p'],

@@ -116,4 +109,13 @@ ['a'],

['hr'],
['lead', '[class~="lead"]'],
]) {
addVariant(`${className}-${name}`, `& :is(${inWhere(selector, options)})`)
selectors = selectors.length === 0 ? [name] : selectors
let selector =
target === 'legacy' ? selectors.map((selector) => `& ${selector}`) : selectors.join(', ')
addVariant(
`${className}-${name}`,
target === 'legacy' ? selector : `& :is(${inWhere(selector, options)})`
)
}

@@ -120,0 +122,0 @@

@@ -8,4 +8,52 @@ const path = require('path')

let css = String.raw
let javascript = String.raw
let defaults = css`
*,
::before,
::after {
--tw-translate-x: 0;
--tw-translate-y: 0;
--tw-rotate: 0;
--tw-skew-x: 0;
--tw-skew-y: 0;
--tw-scale-x: 1;
--tw-scale-y: 1;
--tw-pan-x: ;
--tw-pan-y: ;
--tw-pinch-zoom: ;
--tw-scroll-snap-strictness: proximity;
--tw-ordinal: ;
--tw-slashed-zero: ;
--tw-numeric-figure: ;
--tw-numeric-spacing: ;
--tw-numeric-fraction: ;
--tw-ring-inset: ;
--tw-ring-offset-width: 0px;
--tw-ring-offset-color: #fff;
--tw-ring-color: rgb(59 130 246 / 0.5);
--tw-ring-offset-shadow: 0 0 #0000;
--tw-ring-shadow: 0 0 #0000;
--tw-shadow: 0 0 #0000;
--tw-shadow-colored: 0 0 #0000;
--tw-blur: ;
--tw-brightness: ;
--tw-contrast: ;
--tw-grayscale: ;
--tw-hue-rotate: ;
--tw-invert: ;
--tw-saturate: ;
--tw-sepia: ;
--tw-drop-shadow: ;
--tw-backdrop-blur: ;
--tw-backdrop-brightness: ;
--tw-backdrop-contrast: ;
--tw-backdrop-grayscale: ;
--tw-backdrop-hue-rotate: ;
--tw-backdrop-invert: ;
--tw-backdrop-opacity: ;
--tw-backdrop-saturate: ;
--tw-backdrop-sepia: ;
}
`
function run(config, plugin = tailwind) {

@@ -80,44 +128,48 @@ let { currentTestName } = expect.getState()

return run(config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.prose {
color: var(--tw-prose-body);
max-width: 65ch;
}
.prose :where([class~='lead']):not(:where([class~='not-prose'] *)) {
color: var(--tw-prose-lead);
}
.prose :where(strong):not(:where([class~='not-prose'] *)) {
color: var(--tw-prose-bold);
font-weight: 600;
}
.prose :where(ol[type='A']):not(:where([class~='not-prose'] *)) {
list-style-type: upper-alpha;
}
.prose :where(blockquote p:first-of-type):not(:where([class~='not-prose'] *))::before {
content: open-quote;
}
.prose :where(blockquote p:last-of-type):not(:where([class~='not-prose'] *))::after {
content: close-quote;
}
.prose :where(h4 strong):not(:where([class~='not-prose'] *)) {
font-weight: 700;
}
.prose :where(figure > *):not(:where([class~='not-prose'] *)) {
margin: 0;
}
.prose :where(ol > li):not(:where([class~='not-prose'] *))::marker {
font-weight: 400;
color: var(--tw-prose-counters);
}
.prose > :where(ul > li p):not(:where([class~='not-prose'] *)) {
margin-top: 16px;
margin-bottom: 16px;
}
.prose :where(code):not(:where([class~='not-prose'] *))::before {
content: '&#96;';
}
.prose :where(code):not(:where([class~='not-prose'] *))::after {
content: '&#96;';
}
`)
expect(result.css).toMatchFormattedCss(
css`
${defaults}
.prose {
color: var(--tw-prose-body);
max-width: 65ch;
}
.prose :where([class~='lead']):not(:where([class~='not-prose'] *)) {
color: var(--tw-prose-lead);
}
.prose :where(strong):not(:where([class~='not-prose'] *)) {
color: var(--tw-prose-bold);
font-weight: 600;
}
.prose :where(ol[type='A']):not(:where([class~='not-prose'] *)) {
list-style-type: upper-alpha;
}
.prose :where(blockquote p:first-of-type):not(:where([class~='not-prose'] *))::before {
content: open-quote;
}
.prose :where(blockquote p:last-of-type):not(:where([class~='not-prose'] *))::after {
content: close-quote;
}
.prose :where(h4 strong):not(:where([class~='not-prose'] *)) {
font-weight: 700;
}
.prose :where(figure > *):not(:where([class~='not-prose'] *)) {
margin: 0;
}
.prose :where(ol > li):not(:where([class~='not-prose'] *))::marker {
font-weight: 400;
color: var(--tw-prose-counters);
}
.prose :where(.prose > ul > li p):not(:where([class~='not-prose'] *)) {
margin-top: 16px;
margin-bottom: 16px;
}
.prose :where(code):not(:where([class~='not-prose'] *))::before {
content: '&#96;';
}
.prose :where(code):not(:where([class~='not-prose'] *))::after {
content: '&#96;';
}
`
)
})

@@ -210,70 +262,74 @@ })

return run(config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.prose {
color: var(--tw-prose-body);
max-width: 65ch;
}
.prose :where([class~='lead']):not(:where([class~='not-prose'] *)) {
color: var(--tw-prose-lead);
}
.prose :where(strong):not(:where([class~='not-prose'] *)) {
color: var(--tw-prose-bold);
font-weight: 600;
}
.prose :where(ol[type='A']):not(:where([class~='not-prose'] *)) {
list-style-type: upper-alpha;
}
.prose :where(blockquote p:first-of-type):not(:where([class~='not-prose'] *))::before {
content: open-quote;
}
.prose :where(blockquote p:last-of-type):not(:where([class~='not-prose'] *))::after {
content: close-quote;
}
.prose :where(h4 strong):not(:where([class~='not-prose'] *)) {
font-weight: 700;
}
.prose :where(figure > *):not(:where([class~='not-prose'] *)) {
margin: 0;
}
.prose :where(ol > li):not(:where([class~='not-prose'] *))::marker {
font-weight: 400;
color: var(--tw-prose-counters);
}
.prose :where(code):not(:where([class~='not-prose'] *))::before {
content: '&#96;';
}
.prose :where(code):not(:where([class~='not-prose'] *))::after {
content: '&#96;';
}
.prose-lg {
font-size: 18px;
line-height: 1.75;
}
.prose-lg :where(p):not(:where([class~='not-prose'] *)) {
margin-top: 24px;
margin-bottom: 24px;
}
.prose-lg :where([class~='lead']):not(:where([class~='not-prose'] *)) {
font-size: 22px;
}
.prose-lg :where(blockquote):not(:where([class~='not-prose'] *)) {
margin-top: 40px;
margin-bottom: 40px;
}
.prose-lg :where(h1):not(:where([class~='not-prose'] *)) {
font-size: 48px;
margin-top: 0;
margin-bottom: 40px;
}
.prose-lg :where(h2):not(:where([class~='not-prose'] *)) {
font-size: 30px;
margin-top: 56px;
margin-bottom: 32px;
}
.prose-lg :where(h3):not(:where([class~='not-prose'] *)) {
font-size: 24px;
margin-top: 40px;
margin-bottom: 16px;
}
`)
expect(result.css).toMatchFormattedCss(
css`
${defaults}
.prose {
color: var(--tw-prose-body);
max-width: 65ch;
}
.prose :where([class~='lead']):not(:where([class~='not-prose'] *)) {
color: var(--tw-prose-lead);
}
.prose :where(strong):not(:where([class~='not-prose'] *)) {
color: var(--tw-prose-bold);
font-weight: 600;
}
.prose :where(ol[type='A']):not(:where([class~='not-prose'] *)) {
list-style-type: upper-alpha;
}
.prose :where(blockquote p:first-of-type):not(:where([class~='not-prose'] *))::before {
content: open-quote;
}
.prose :where(blockquote p:last-of-type):not(:where([class~='not-prose'] *))::after {
content: close-quote;
}
.prose :where(h4 strong):not(:where([class~='not-prose'] *)) {
font-weight: 700;
}
.prose :where(figure > *):not(:where([class~='not-prose'] *)) {
margin: 0;
}
.prose :where(ol > li):not(:where([class~='not-prose'] *))::marker {
font-weight: 400;
color: var(--tw-prose-counters);
}
.prose :where(code):not(:where([class~='not-prose'] *))::before {
content: '&#96;';
}
.prose :where(code):not(:where([class~='not-prose'] *))::after {
content: '&#96;';
}
.prose-lg {
font-size: 18px;
line-height: 1.75;
}
.prose-lg :where(p):not(:where([class~='not-prose'] *)) {
margin-top: 24px;
margin-bottom: 24px;
}
.prose-lg :where([class~='lead']):not(:where([class~='not-prose'] *)) {
font-size: 22px;
}
.prose-lg :where(blockquote):not(:where([class~='not-prose'] *)) {
margin-top: 40px;
margin-bottom: 40px;
}
.prose-lg :where(h1):not(:where([class~='not-prose'] *)) {
font-size: 48px;
margin-top: 0;
margin-bottom: 40px;
}
.prose-lg :where(h2):not(:where([class~='not-prose'] *)) {
font-size: 30px;
margin-top: 56px;
margin-bottom: 32px;
}
.prose-lg :where(h3):not(:where([class~='not-prose'] *)) {
font-size: 24px;
margin-top: 40px;
margin-bottom: 16px;
}
`
)
})

@@ -285,3 +341,5 @@ })

plugins: [typographyPlugin({ target: 'legacy' })],
content: [{ raw: html`<div class="prose"></div>` }],
content: [
{ raw: html`<div class="prose prose-h1:text-center prose-headings:text-ellipsis"></div>` },
],
theme: {

@@ -334,40 +392,68 @@ typography: {

return run(config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.prose {
color: var(--tw-prose-body);
max-width: 65ch;
}
.prose [class~='lead'] {
color: var(--tw-prose-lead);
}
.prose strong {
color: var(--tw-prose-bold);
font-weight: 600;
}
.prose ol[type='A'] {
list-style-type: upper-alpha;
}
.prose blockquote p:first-of-type::before {
content: open-quote;
}
.prose blockquote p:last-of-type::after {
content: close-quote;
}
.prose h4 strong {
font-weight: 700;
}
.prose figure > * {
margin: 0;
}
.prose ol > li::marker {
font-weight: 400;
color: var(--tw-prose-counters);
}
.prose code::before {
content: '&#96;';
}
.prose code::after {
content: '&#96;';
}
`)
expect(result.css).toMatchFormattedCss(
css`
${defaults}
.prose {
color: var(--tw-prose-body);
max-width: 65ch;
}
.prose [class~='lead'] {
color: var(--tw-prose-lead);
}
.prose strong {
color: var(--tw-prose-bold);
font-weight: 600;
}
.prose ol[type='A'] {
list-style-type: upper-alpha;
}
.prose blockquote p:first-of-type::before {
content: open-quote;
}
.prose blockquote p:last-of-type::after {
content: close-quote;
}
.prose h4 strong {
font-weight: 700;
}
.prose figure > * {
margin: 0;
}
.prose ol > li::marker {
font-weight: 400;
color: var(--tw-prose-counters);
}
.prose code::before {
content: '&#96;';
}
.prose code::after {
content: '&#96;';
}
.prose-headings\:text-ellipsis h1 {
text-overflow: ellipsis;
}
.prose-headings\:text-ellipsis h2 {
text-overflow: ellipsis;
}
.prose-headings\:text-ellipsis h3 {
text-overflow: ellipsis;
}
.prose-headings\:text-ellipsis h4 {
text-overflow: ellipsis;
}
.prose-headings\:text-ellipsis h5 {
text-overflow: ellipsis;
}
.prose-headings\:text-ellipsis h6 {
text-overflow: ellipsis;
}
.prose-headings\:text-ellipsis th {
text-overflow: ellipsis;
}
.prose-h1\:text-center h1 {
text-align: center;
}
`
)
})

@@ -427,40 +513,45 @@ })

return run(config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
.markdown {
color: var(--tw-prose-body);
max-width: 65ch;
}
.markdown :where([class~='lead']):not(:where([class~='not-markdown'] *)) {
color: var(--tw-prose-lead);
}
.markdown :where(strong):not(:where([class~='not-markdown'] *)) {
color: var(--tw-prose-bold);
font-weight: 600;
}
.markdown :where(ol[type='A']):not(:where([class~='not-markdown'] *)) {
list-style-type: upper-alpha;
}
.markdown :where(blockquote p:first-of-type):not(:where([class~='not-markdown'] *))::before {
content: open-quote;
}
.markdown :where(blockquote p:last-of-type):not(:where([class~='not-markdown'] *))::after {
content: close-quote;
}
.markdown :where(h4 strong):not(:where([class~='not-markdown'] *)) {
font-weight: 700;
}
.markdown :where(figure > *):not(:where([class~='not-markdown'] *)) {
margin: 0;
}
.markdown :where(ol > li):not(:where([class~='not-markdown'] *))::marker {
font-weight: 400;
color: var(--tw-prose-counters);
}
.markdown :where(code):not(:where([class~='not-markdown'] *))::before {
content: '&#96;';
}
.markdown :where(code):not(:where([class~='not-markdown'] *))::after {
content: '&#96;';
}
`)
expect(result.css).toMatchFormattedCss(
css`
${defaults}
.markdown {
color: var(--tw-prose-body);
max-width: 65ch;
}
.markdown :where([class~='lead']):not(:where([class~='not-markdown'] *)) {
color: var(--tw-prose-lead);
}
.markdown :where(strong):not(:where([class~='not-markdown'] *)) {
color: var(--tw-prose-bold);
font-weight: 600;
}
.markdown :where(ol[type='A']):not(:where([class~='not-markdown'] *)) {
list-style-type: upper-alpha;
}
.markdown
:where(blockquote p:first-of-type):not(:where([class~='not-markdown'] *))::before {
content: open-quote;
}
.markdown :where(blockquote p:last-of-type):not(:where([class~='not-markdown'] *))::after {
content: close-quote;
}
.markdown :where(h4 strong):not(:where([class~='not-markdown'] *)) {
font-weight: 700;
}
.markdown :where(figure > *):not(:where([class~='not-markdown'] *)) {
margin: 0;
}
.markdown :where(ol > li):not(:where([class~='not-markdown'] *))::marker {
font-weight: 400;
color: var(--tw-prose-counters);
}
.markdown :where(code):not(:where([class~='not-markdown'] *))::before {
content: '&#96;';
}
.markdown :where(code):not(:where([class~='not-markdown'] *))::after {
content: '&#96;';
}
`
)
})

@@ -529,110 +620,110 @@ })

return run(config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
:is(:where(hr):not(:where([class~='not-prose'] *))) {
--tw-border-opacity: 1;
border-color: rgb(229 231 235 / var(--tw-border-opacity));
}
.prose {
color: var(--tw-prose-body);
}
.prose :where([class~='lead']):not(:where([class~='not-prose'] *)) {
color: var(--tw-prose-lead);
}
.prose :where(strong):not(:where([class~='not-prose'] *)) {
color: var(--tw-prose-bold);
font-weight: 600;
}
.prose :where(h4 strong):not(:where([class~='not-prose'] *)) {
font-weight: 700;
}
.prose-headings\:underline
:is(:where(h1, h2, h3, h4, th):not(:where([class~='not-prose'] *))) {
text-decoration: underline;
}
.prose-lead\:italic :is(:where([class~='lead']):not(:where([class~='not-prose'] *))) {
font-style: italic;
}
.prose-h1\:text-3xl :is(:where(h1):not(:where([class~='not-prose'] *))) {
font-size: 1.875rem;
line-height: 2.25rem;
}
.prose-h2\:text-2xl :is(:where(h2):not(:where([class~='not-prose'] *))) {
font-size: 1.5rem;
line-height: 2rem;
}
.prose-h3\:text-xl :is(:where(h3):not(:where([class~='not-prose'] *))) {
font-size: 1.25rem;
line-height: 1.75rem;
}
.prose-h4\:text-lg :is(:where(h4):not(:where([class~='not-prose'] *))) {
font-size: 1.125rem;
line-height: 1.75rem;
}
.prose-p\:text-gray-700 :is(:where(p):not(:where([class~='not-prose'] *))) {
--tw-text-opacity: 1;
color: rgb(55 65 81 / var(--tw-text-opacity));
}
.prose-a\:font-bold :is(:where(a):not(:where([class~='not-prose'] *))) {
font-weight: 700;
}
.prose-blockquote\:italic :is(:where(blockquote):not(:where([class~='not-prose'] *))) {
font-style: italic;
}
.prose-figure\:mx-auto :is(:where(figure):not(:where([class~='not-prose'] *))) {
margin-left: auto;
margin-right: auto;
}
.prose-figcaption\:opacity-75 :is(:where(figcaption):not(:where([class~='not-prose'] *))) {
opacity: 0.75;
}
.prose-strong\:font-medium :is(:where(strong):not(:where([class~='not-prose'] *))) {
font-weight: 500;
}
.prose-em\:italic :is(:where(em):not(:where([class~='not-prose'] *))) {
font-style: italic;
}
.prose-code\:font-mono :is(:where(code):not(:where([class~='not-prose'] *))) {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono',
'Courier New', monospace;
}
.prose-pre\:font-mono :is(:where(pre):not(:where([class~='not-prose'] *))) {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono',
'Courier New', monospace;
}
.prose-ol\:pl-6 :is(:where(ol):not(:where([class~='not-prose'] *))) {
padding-left: 1.5rem;
}
.prose-ul\:pl-8 :is(:where(ul):not(:where([class~='not-prose'] *))) {
padding-left: 2rem;
}
.prose-li\:my-4 :is(:where(li):not(:where([class~='not-prose'] *))) {
margin-top: 1rem;
margin-bottom: 1rem;
}
.prose-table\:my-8 :is(:where(table):not(:where([class~='not-prose'] *))) {
margin-top: 2rem;
margin-bottom: 2rem;
}
.prose-thead\:border-red-300 :is(:where(thead):not(:where([class~='not-prose'] *))) {
--tw-border-opacity: 1;
border-color: rgb(252 165 165 / var(--tw-border-opacity));
}
.prose-tr\:border-red-200 :is(:where(tr):not(:where([class~='not-prose'] *))) {
--tw-border-opacity: 1;
border-color: rgb(254 202 202 / var(--tw-border-opacity));
}
.prose-th\:text-left :is(:where(th):not(:where([class~='not-prose'] *))) {
text-align: left;
}
.prose-img\:rounded-lg :is(:where(img):not(:where([class~='not-prose'] *))) {
border-radius: 0.5rem;
}
.prose-video\:my-12 :is(:where(video):not(:where([class~='not-prose'] *))) {
margin-top: 3rem;
margin-bottom: 3rem;
}
.prose-hr\:border-t-2 :is(:where(hr):not(:where([class~='not-prose'] *))) {
border-top-width: 2px;
}
`)
expect(result.css).toMatchFormattedCss(
css`
${defaults}
.prose {
color: var(--tw-prose-body);
}
.prose :where([class~='lead']):not(:where([class~='not-prose'] *)) {
color: var(--tw-prose-lead);
}
.prose :where(strong):not(:where([class~='not-prose'] *)) {
color: var(--tw-prose-bold);
font-weight: 600;
}
.prose :where(h4 strong):not(:where([class~='not-prose'] *)) {
font-weight: 700;
}
.prose-headings\:underline
:is(:where(h1, h2, h3, h4, h5, h6, th):not(:where([class~='not-prose'] *))) {
text-decoration-line: underline;
}
.prose-h1\:text-3xl :is(:where(h1):not(:where([class~='not-prose'] *))) {
font-size: 1.875rem;
line-height: 2.25rem;
}
.prose-h2\:text-2xl :is(:where(h2):not(:where([class~='not-prose'] *))) {
font-size: 1.5rem;
line-height: 2rem;
}
.prose-h3\:text-xl :is(:where(h3):not(:where([class~='not-prose'] *))) {
font-size: 1.25rem;
line-height: 1.75rem;
}
.prose-h4\:text-lg :is(:where(h4):not(:where([class~='not-prose'] *))) {
font-size: 1.125rem;
line-height: 1.75rem;
}
.prose-p\:text-gray-700 :is(:where(p):not(:where([class~='not-prose'] *))) {
--tw-text-opacity: 1;
color: rgb(55 65 81 / var(--tw-text-opacity));
}
.prose-a\:font-bold :is(:where(a):not(:where([class~='not-prose'] *))) {
font-weight: 700;
}
.prose-blockquote\:italic :is(:where(blockquote):not(:where([class~='not-prose'] *))) {
font-style: italic;
}
.prose-figure\:mx-auto :is(:where(figure):not(:where([class~='not-prose'] *))) {
margin-left: auto;
margin-right: auto;
}
.prose-figcaption\:opacity-75 :is(:where(figcaption):not(:where([class~='not-prose'] *))) {
opacity: 0.75;
}
.prose-strong\:font-medium :is(:where(strong):not(:where([class~='not-prose'] *))) {
font-weight: 500;
}
.prose-em\:italic :is(:where(em):not(:where([class~='not-prose'] *))) {
font-style: italic;
}
.prose-code\:font-mono :is(:where(code):not(:where([class~='not-prose'] *))) {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono',
'Courier New', monospace;
}
.prose-pre\:font-mono :is(:where(pre):not(:where([class~='not-prose'] *))) {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono',
'Courier New', monospace;
}
.prose-ol\:pl-6 :is(:where(ol):not(:where([class~='not-prose'] *))) {
padding-left: 1.5rem;
}
.prose-ul\:pl-8 :is(:where(ul):not(:where([class~='not-prose'] *))) {
padding-left: 2rem;
}
.prose-li\:my-4 :is(:where(li):not(:where([class~='not-prose'] *))) {
margin-top: 1rem;
margin-bottom: 1rem;
}
.prose-table\:my-8 :is(:where(table):not(:where([class~='not-prose'] *))) {
margin-top: 2rem;
margin-bottom: 2rem;
}
.prose-thead\:border-red-300 :is(:where(thead):not(:where([class~='not-prose'] *))) {
--tw-border-opacity: 1;
border-color: rgb(252 165 165 / var(--tw-border-opacity));
}
.prose-tr\:border-red-200 :is(:where(tr):not(:where([class~='not-prose'] *))) {
--tw-border-opacity: 1;
border-color: rgb(254 202 202 / var(--tw-border-opacity));
}
.prose-th\:text-left :is(:where(th):not(:where([class~='not-prose'] *))) {
text-align: left;
}
.prose-img\:rounded-lg :is(:where(img):not(:where([class~='not-prose'] *))) {
border-radius: 0.5rem;
}
.prose-video\:my-12 :is(:where(video):not(:where([class~='not-prose'] *))) {
margin-top: 3rem;
margin-bottom: 3rem;
}
.prose-hr\:border-t-2 :is(:where(hr):not(:where([class~='not-prose'] *))) {
border-top-width: 2px;
}
.prose-lead\:italic :is(:where([class~='lead']):not(:where([class~='not-prose'] *))) {
font-style: italic;
}
`
)
})

@@ -702,112 +793,415 @@ })

return run(config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
:is(:where(hr):not(:where([class~='not-markdown'] *))) {
--tw-border-opacity: 1;
border-color: rgb(229 231 235 / var(--tw-border-opacity));
expect(result.css).toMatchFormattedCss(
css`
${defaults}
.markdown {
color: var(--tw-prose-body);
}
.markdown :where([class~='lead']):not(:where([class~='not-markdown'] *)) {
color: var(--tw-prose-lead);
}
.markdown :where(strong):not(:where([class~='not-markdown'] *)) {
color: var(--tw-prose-bold);
font-weight: 600;
}
.markdown :where(h4 strong):not(:where([class~='not-markdown'] *)) {
font-weight: 700;
}
.markdown-headings\:underline
:is(:where(h1, h2, h3, h4, h5, h6, th):not(:where([class~='not-markdown'] *))) {
text-decoration-line: underline;
}
.markdown-h1\:text-3xl :is(:where(h1):not(:where([class~='not-markdown'] *))) {
font-size: 1.875rem;
line-height: 2.25rem;
}
.markdown-h2\:text-2xl :is(:where(h2):not(:where([class~='not-markdown'] *))) {
font-size: 1.5rem;
line-height: 2rem;
}
.markdown-h3\:text-xl :is(:where(h3):not(:where([class~='not-markdown'] *))) {
font-size: 1.25rem;
line-height: 1.75rem;
}
.markdown-h4\:text-lg :is(:where(h4):not(:where([class~='not-markdown'] *))) {
font-size: 1.125rem;
line-height: 1.75rem;
}
.markdown-p\:text-gray-700 :is(:where(p):not(:where([class~='not-markdown'] *))) {
--tw-text-opacity: 1;
color: rgb(55 65 81 / var(--tw-text-opacity));
}
.markdown-a\:font-bold :is(:where(a):not(:where([class~='not-markdown'] *))) {
font-weight: 700;
}
.markdown-blockquote\:italic
:is(:where(blockquote):not(:where([class~='not-markdown'] *))) {
font-style: italic;
}
.markdown-figure\:mx-auto :is(:where(figure):not(:where([class~='not-markdown'] *))) {
margin-left: auto;
margin-right: auto;
}
.markdown-figcaption\:opacity-75
:is(:where(figcaption):not(:where([class~='not-markdown'] *))) {
opacity: 0.75;
}
.markdown-strong\:font-medium :is(:where(strong):not(:where([class~='not-markdown'] *))) {
font-weight: 500;
}
.markdown-em\:italic :is(:where(em):not(:where([class~='not-markdown'] *))) {
font-style: italic;
}
.markdown-code\:font-mono :is(:where(code):not(:where([class~='not-markdown'] *))) {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono',
'Courier New', monospace;
}
.markdown-pre\:font-mono :is(:where(pre):not(:where([class~='not-markdown'] *))) {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono',
'Courier New', monospace;
}
.markdown-ol\:pl-6 :is(:where(ol):not(:where([class~='not-markdown'] *))) {
padding-left: 1.5rem;
}
.markdown-ul\:pl-8 :is(:where(ul):not(:where([class~='not-markdown'] *))) {
padding-left: 2rem;
}
.markdown-li\:my-4 :is(:where(li):not(:where([class~='not-markdown'] *))) {
margin-top: 1rem;
margin-bottom: 1rem;
}
.markdown-table\:my-8 :is(:where(table):not(:where([class~='not-markdown'] *))) {
margin-top: 2rem;
margin-bottom: 2rem;
}
.markdown-thead\:border-red-300 :is(:where(thead):not(:where([class~='not-markdown'] *))) {
--tw-border-opacity: 1;
border-color: rgb(252 165 165 / var(--tw-border-opacity));
}
.markdown-tr\:border-red-200 :is(:where(tr):not(:where([class~='not-markdown'] *))) {
--tw-border-opacity: 1;
border-color: rgb(254 202 202 / var(--tw-border-opacity));
}
.markdown-th\:text-left :is(:where(th):not(:where([class~='not-markdown'] *))) {
text-align: left;
}
.markdown-img\:rounded-lg :is(:where(img):not(:where([class~='not-markdown'] *))) {
border-radius: 0.5rem;
}
.markdown-video\:my-12 :is(:where(video):not(:where([class~='not-markdown'] *))) {
margin-top: 3rem;
margin-bottom: 3rem;
}
.markdown-hr\:border-t-2 :is(:where(hr):not(:where([class~='not-markdown'] *))) {
border-top-width: 2px;
}
.markdown-lead\:italic :is(:where([class~='lead']):not(:where([class~='not-markdown'] *))) {
font-style: italic;
}
`
)
})
})
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) => {
expect(result.css).toMatchFormattedCss(
css`
${defaults}
.prose {
text-align: -webkit-match-parent;
text-align: match-parent;
}
`
)
})
})
it('should be possible to use nested syntax (&) when extending the config', () => {
let config = {
plugins: [typographyPlugin()],
content: [
{
raw: html`<div class="prose"></div>`,
},
],
theme: {
extend: {
typography: {
DEFAULT: {
css: {
color: '#000',
a: {
color: '#888',
'&:hover': {
color: '#ff0000',
},
},
},
},
},
},
},
}
return run(config).then((result) => {
expect(result.css).toIncludeCss(css`
.prose {
color: #000;
max-width: 65ch;
}
.markdown {
color: var(--tw-prose-body);
}
.markdown :where([class~='lead']):not(:where([class~='not-markdown'] *)) {
color: var(--tw-prose-lead);
}
.markdown :where(strong):not(:where([class~='not-markdown'] *)) {
color: var(--tw-prose-bold);
font-weight: 600;
}
.markdown :where(h4 strong):not(:where([class~='not-markdown'] *)) {
font-weight: 700;
}
.markdown-headings\:underline
:is(:where(h1, h2, h3, h4, th):not(:where([class~='not-markdown'] *))) {
`)
expect(result.css).toIncludeCss(css`
.prose :where(a):not(:where([class~='not-prose'] *)) {
color: #888;
text-decoration: underline;
font-weight: 500;
}
.markdown-lead\:italic :is(:where([class~='lead']):not(:where([class~='not-markdown'] *))) {
font-style: italic;
`)
expect(result.css).toIncludeCss(css`
.prose :where(a):not(:where([class~='not-prose'] *)):hover {
color: #ff0000;
}
.markdown-h1\:text-3xl :is(:where(h1):not(:where([class~='not-markdown'] *))) {
font-size: 1.875rem;
line-height: 2.25rem;
`)
})
})
it('should be possible to specify custom h5 and h6 styles', () => {
let config = {
plugins: [typographyPlugin()],
content: [
{
raw: html`<div class="prose prose-h5:text-sm prose-h6:text-xl"></div>`,
},
],
}
return run(config).then((result) => {
expect(result.css).toIncludeCss(css`
.prose-h5\:text-sm :is(:where(h5):not(:where([class~='not-prose'] *))) {
font-size: 0.875rem;
line-height: 1.25rem;
}
.markdown-h2\:text-2xl :is(:where(h2):not(:where([class~='not-markdown'] *))) {
font-size: 1.5rem;
line-height: 2rem;
}
.markdown-h3\:text-xl :is(:where(h3):not(:where([class~='not-markdown'] *))) {
.prose-h6\:text-xl :is(:where(h6):not(:where([class~='not-prose'] *))) {
font-size: 1.25rem;
line-height: 1.75rem;
}
.markdown-h4\:text-lg :is(:where(h4):not(:where([class~='not-markdown'] *))) {
font-size: 1.125rem;
line-height: 1.75rem;
`)
})
})
it('should not break with multiple selectors with pseudo elements using variants', () => {
let config = {
darkMode: 'class',
plugins: [typographyPlugin()],
content: [
{
raw: html`<div class="dark:prose"></div>`,
},
],
theme: {
typography: {
DEFAULT: {
css: {
'ol li::before, ul li::before': {
color: 'red',
},
},
},
},
},
}
return run(config).then((result) => {
expect(result.css).toIncludeCss(css`
.dark .dark\:prose :where(ol li, ul li):not(:where([class~='not-prose'] *))::before {
color: red;
}
.markdown-p\:text-gray-700 :is(:where(p):not(:where([class~='not-markdown'] *))) {
--tw-text-opacity: 1;
color: rgb(55 65 81 / var(--tw-text-opacity));
`)
})
})
it('lifts all common, trailing pseudo elements when the same across all selectors', () => {
let config = {
darkMode: 'class',
plugins: [typographyPlugin()],
content: [
{
raw: html`<div class="prose dark:prose"></div>`,
},
],
theme: {
typography: {
DEFAULT: {
css: {
'ol li::marker::before, ul li::marker::before': {
color: 'red',
},
},
},
},
},
}
return run(config).then((result) => {
expect(result.css).toIncludeCss(css`
.prose :where(ol li, ul li):not(:where([class~='not-prose'] *))::marker::before {
color: red;
}
.markdown-a\:font-bold :is(:where(a):not(:where([class~='not-markdown'] *))) {
font-weight: 700;
`)
// TODO: The output here is a bug in tailwindcss variant selector rewriting
// IT should be ::marker::before
expect(result.css).toIncludeCss(css`
.dark .dark\:prose :where(ol li, ul li):not(:where([class~='not-prose'] *))::before::marker {
color: red;
}
.markdown-blockquote\:italic :is(:where(blockquote):not(:where([class~='not-markdown'] *))) {
font-style: italic;
`)
})
})
it('does not modify selectors with differing pseudo elements', () => {
let config = {
darkMode: 'class',
plugins: [typographyPlugin()],
content: [
{
raw: html`<div class="prose dark:prose"></div>`,
},
],
theme: {
typography: {
DEFAULT: {
css: {
'ol li::before, ul li::after': {
color: 'red',
},
},
},
},
},
}
return run(config).then((result) => {
expect(result.css).toIncludeCss(css`
.prose :where(ol li::before, ul li::after):not(:where([class~='not-prose'] *)) {
color: red;
}
.markdown-figure\:mx-auto :is(:where(figure):not(:where([class~='not-markdown'] *))) {
margin-left: auto;
margin-right: auto;
`)
// TODO: The output here is a bug in tailwindcss variant selector rewriting
expect(result.css).toIncludeCss(css`
.dark .dark\:prose :where(ol li, ul li):not(:where([class~='not-prose'] *))::before,
::after {
color: red;
}
.markdown-figcaption\:opacity-75
:is(:where(figcaption):not(:where([class~='not-markdown'] *))) {
opacity: 0.75;
`)
})
})
it('lifts only the common, trailing pseudo elements from selectors', () => {
let config = {
darkMode: 'class',
plugins: [typographyPlugin()],
content: [
{
raw: html`<div class="prose dark:prose"></div>`,
},
],
theme: {
typography: {
DEFAULT: {
css: {
'ol li::scroll-thumb::before, ul li::scroll-track::before': {
color: 'red',
},
},
},
},
},
}
return run(config).then((result) => {
expect(result.css).toIncludeCss(css`
.prose
:where(ol li::scroll-thumb, ul li::scroll-track):not(:where([class~='not-prose']
*))::before {
color: red;
}
.markdown-strong\:font-medium :is(:where(strong):not(:where([class~='not-markdown'] *))) {
font-weight: 500;
`)
// TODO: The output here is a bug in tailwindcss variant selector rewriting
expect(result.css).toIncludeCss(css`
.dark .dark\:prose :where(ol li, ul li):not(:where([class~='not-prose'] *))::scroll-thumb,
::scroll-track,
::before {
color: red;
}
.markdown-em\:italic :is(:where(em):not(:where([class~='not-markdown'] *))) {
font-style: italic;
`)
})
})
it('ignores common non-trailing pseudo-elements in selectors', () => {
let config = {
darkMode: 'class',
plugins: [typographyPlugin()],
content: [
{
raw: html`<div class="prose dark:prose"></div>`,
},
],
theme: {
typography: {
DEFAULT: {
css: {
'ol li::before::scroll-thumb, ul li::before::scroll-track': {
color: 'red',
},
},
},
},
},
}
return run(config).then((result) => {
expect(result.css).toIncludeCss(css`
.prose
:where(ol li::before::scroll-thumb, ul
li::before::scroll-track):not(:where([class~='not-prose'] *)) {
color: red;
}
.markdown-code\:font-mono :is(:where(code):not(:where([class~='not-markdown'] *))) {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono',
'Courier New', monospace;
`)
// TODO: The output here is a bug in tailwindcss variant selector rewriting
expect(result.css).toIncludeCss(css`
.dark
.dark\:prose
:where(ol li::scroll-thumb, ul li::scroll-track):not(:where([class~='not-prose']
*))::before,
::before {
color: red;
}
.markdown-pre\:font-mono :is(:where(pre):not(:where([class~='not-markdown'] *))) {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono',
'Courier New', monospace;
}
.markdown-ol\:pl-6 :is(:where(ol):not(:where([class~='not-markdown'] *))) {
padding-left: 1.5rem;
}
.markdown-ul\:pl-8 :is(:where(ul):not(:where([class~='not-markdown'] *))) {
padding-left: 2rem;
}
.markdown-li\:my-4 :is(:where(li):not(:where([class~='not-markdown'] *))) {
margin-top: 1rem;
margin-bottom: 1rem;
}
.markdown-table\:my-8 :is(:where(table):not(:where([class~='not-markdown'] *))) {
margin-top: 2rem;
margin-bottom: 2rem;
}
.markdown-thead\:border-red-300 :is(:where(thead):not(:where([class~='not-markdown'] *))) {
--tw-border-opacity: 1;
border-color: rgb(252 165 165 / var(--tw-border-opacity));
}
.markdown-tr\:border-red-200 :is(:where(tr):not(:where([class~='not-markdown'] *))) {
--tw-border-opacity: 1;
border-color: rgb(254 202 202 / var(--tw-border-opacity));
}
.markdown-th\:text-left :is(:where(th):not(:where([class~='not-markdown'] *))) {
text-align: left;
}
.markdown-img\:rounded-lg :is(:where(img):not(:where([class~='not-markdown'] *))) {
border-radius: 0.5rem;
}
.markdown-video\:my-12 :is(:where(video):not(:where([class~='not-markdown'] *))) {
margin-top: 3rem;
margin-bottom: 3rem;
}
.markdown-hr\:border-t-2 :is(:where(hr):not(:where([class~='not-markdown'] *))) {
border-top-width: 2px;
}
`)
})
})

@@ -99,2 +99,3 @@ const colors = require('tailwindcss/colors')

marginBottom: em(16, 14),
paddingLeft: em(22, 14),
},

@@ -104,2 +105,3 @@ ul: {

marginBottom: em(16, 14),
paddingLeft: em(22, 14),
},

@@ -110,11 +112,5 @@ li: {

},
ol: {
paddingLeft: em(22, 14),
},
'ol > li': {
paddingLeft: em(6, 14),
},
ul: {
paddingLeft: em(22, 14),
},
'ul > li': {

@@ -174,3 +170,3 @@ paddingLeft: em(6, 14),

},
'tbody td': {
'tbody td, tfoot td': {
paddingTop: em(8, 12),

@@ -181,6 +177,6 @@ paddingRight: em(12, 12),

},
'tbody td:first-child': {
'tbody td:first-child, tfoot td:first-child': {
paddingLeft: '0',
},
'tbody td:last-child': {
'tbody td:last-child, tfoot td:last-child': {
paddingRight: '0',

@@ -286,2 +282,3 @@ },

marginBottom: em(20, 16),
paddingLeft: em(26, 16),
},

@@ -291,2 +288,3 @@ ul: {

marginBottom: em(20, 16),
paddingLeft: em(26, 16),
},

@@ -297,11 +295,5 @@ li: {

},
ol: {
paddingLeft: em(26, 16),
},
'ol > li': {
paddingLeft: em(6, 16),
},
ul: {
paddingLeft: em(26, 16),
},
'ul > li': {

@@ -361,3 +353,3 @@ paddingLeft: em(6, 16),

},
'tbody td': {
'tbody td, tfoot td': {
paddingTop: em(8, 14),

@@ -368,6 +360,6 @@ paddingRight: em(8, 14),

},
'tbody td:first-child': {
'tbody td:first-child, tfoot td:first-child': {
paddingLeft: '0',
},
'tbody td:last-child': {
'tbody td:last-child, tfoot td:last-child': {
paddingRight: '0',

@@ -473,2 +465,3 @@ },

marginBottom: em(24, 18),
paddingLeft: em(28, 18),
},

@@ -478,2 +471,3 @@ ul: {

marginBottom: em(24, 18),
paddingLeft: em(28, 18),
},

@@ -484,11 +478,5 @@ li: {

},
ol: {
paddingLeft: em(28, 18),
},
'ol > li': {
paddingLeft: em(8, 18),
},
ul: {
paddingLeft: em(28, 18),
},
'ul > li': {

@@ -548,3 +536,3 @@ paddingLeft: em(8, 18),

},
'tbody td': {
'tbody td, tfoot td': {
paddingTop: em(12, 16),

@@ -555,6 +543,6 @@ paddingRight: em(12, 16),

},
'tbody td:first-child': {
'tbody td:first-child, tfoot td:first-child': {
paddingLeft: '0',
},
'tbody td:last-child': {
'tbody td:last-child, tfoot td:last-child': {
paddingRight: '0',

@@ -660,2 +648,3 @@ },

marginBottom: em(24, 20),
paddingLeft: em(32, 20),
},

@@ -665,2 +654,3 @@ ul: {

marginBottom: em(24, 20),
paddingLeft: em(32, 20),
},

@@ -671,11 +661,5 @@ li: {

},
ol: {
paddingLeft: em(32, 20),
},
'ol > li': {
paddingLeft: em(8, 20),
},
ul: {
paddingLeft: em(32, 20),
},
'ul > li': {

@@ -735,3 +719,3 @@ paddingLeft: em(8, 20),

},
'tbody td': {
'tbody td, tfoot td': {
paddingTop: em(16, 18),

@@ -742,6 +726,6 @@ paddingRight: em(12, 18),

},
'tbody td:first-child': {
'tbody td:first-child, tfoot td:first-child': {
paddingLeft: '0',
},
'tbody td:last-child': {
'tbody td:last-child, tfoot td:last-child': {
paddingRight: '0',

@@ -847,2 +831,3 @@ },

marginBottom: em(32, 24),
paddingLeft: em(38, 24),
},

@@ -852,2 +837,3 @@ ul: {

marginBottom: em(32, 24),
paddingLeft: em(38, 24),
},

@@ -858,11 +844,5 @@ li: {

},
ol: {
paddingLeft: em(38, 24),
},
'ol > li': {
paddingLeft: em(10, 24),
},
ul: {
paddingLeft: em(38, 24),
},
'ul > li': {

@@ -922,3 +902,3 @@ paddingLeft: em(10, 24),

},
'tbody td': {
'tbody td, tfoot td': {
paddingTop: em(16, 20),

@@ -929,6 +909,6 @@ paddingRight: em(12, 20),

},
'tbody td:first-child': {
'tbody td:first-child, tfoot td:first-child': {
paddingLeft: '0',
},
'tbody td:last-child': {
'tbody td:last-child, tfoot td:last-child': {
paddingRight: '0',

@@ -1297,2 +1277,11 @@ },

},
'a strong': {
color: 'inherit',
},
'blockquote strong': {
color: 'inherit',
},
'thead th strong': {
color: 'inherit',
},
ol: {

@@ -1362,2 +1351,3 @@ listStyleType: 'decimal',

fontWeight: '900',
color: 'inherit',
},

@@ -1370,2 +1360,3 @@ h2: {

fontWeight: '800',
color: 'inherit',
},

@@ -1378,2 +1369,3 @@ h3: {

fontWeight: '700',
color: 'inherit',
},

@@ -1386,4 +1378,6 @@ h4: {

fontWeight: '700',
color: 'inherit',
},
// TODO: Figure out how to not need this, it's a merging issue
// TODO: Figure out how to not need these, it's a merging issue
img: {},
'figure > *': {},

@@ -1404,4 +1398,22 @@ figcaption: {

'a code': {
color: 'var(--tw-prose-links)',
color: 'inherit',
},
'h1 code': {
color: 'inherit',
},
'h2 code': {
color: 'inherit',
},
'h3 code': {
color: 'inherit',
},
'h4 code': {
color: 'inherit',
},
'blockquote code': {
color: 'inherit',
},
'thead th code': {
color: 'inherit',
},
pre: {

@@ -1456,2 +1468,9 @@ color: 'var(--tw-prose-pre-code)',

},
tfoot: {
borderTopWidth: '1px',
borderTopColor: 'var(--tw-prose-th-borders)',
},
'tfoot td': {
verticalAlign: 'top',
},
},

@@ -1458,0 +1477,0 @@ defaultModifiers.gray.css,

const isPlainObject = require('lodash.isplainobject')
const parser = require('postcss-selector-parser')
const parseSelector = parser()
module.exports = {

@@ -7,2 +10,54 @@ isUsableColor(color, values) {

},
/**
* @param {string} selector
*/
commonTrailingPseudos(selector) {
let ast = parseSelector.astSync(selector)
/** @type {import('postcss-selector-parser').Pseudo[][]} */
let matrix = []
// Put the pseudo elements in reverse order in a sparse, column-major 2D array
for (let [i, sel] of ast.nodes.entries()) {
for (const [j, child] of [...sel.nodes].reverse().entries()) {
// We only care about pseudo elements
if (child.type !== 'pseudo' || !child.value.startsWith('::')) {
break
}
matrix[j] = matrix[j] || []
matrix[j][i] = child
}
}
let trailingPseudos = parser.selector()
// At this point the pseudo elements are in a column-major 2D array
// This means each row contains one "column" of pseudo elements from each selector
// We can compare all the pseudo elements in a row to see if they are the same
for (const pseudos of matrix) {
// It's a sparse 2D array so there are going to be holes in the rows
// We skip those
if (!pseudos) {
continue
}
let values = new Set([...pseudos.map((p) => p.value)])
// The pseudo elements are not the same
if (values.size > 1) {
break
}
pseudos.forEach((pseudo) => pseudo.remove())
trailingPseudos.prepend(pseudos[0])
}
if (trailingPseudos.nodes.length) {
return [trailingPseudos.toString(), ast.toString()]
}
return [null, selector]
},
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc