Preview Mode for Headless CMS
The following content is derived from the Tailwind CSS documentation. It's included here to test markdown styles. Tailwind is an excellent tool for styling. We highly recommend using it.
Styling articles, documents, or blog posts with Tailwind CSS has traditionally been a challenge, requiring careful attention to typography and extensive custom CSS. Tailwind’s default behavior strips away browser styles from elements like paragraphs, headings, and lists, which is fantastic for building application UIs. However, it can be counterintuitive when styling content directly from a rich-text editor in a CMS or a markdown file.
We often receive feedback like:
Why is Tailwind removing default styles from my h1 elements? How do I disable this? Why are all the other base styles gone too?
While simply disabling Tailwind's base styles might seem like a solution, it's not ideal. You’d end up constantly battling default margins in your UI. Plus, user-agent styles don’t always look great in a blog post—you want your content to look awesome, not bland
To address this, we created the @tailwindcss/typography plugin. It provides a prose class that you can apply to any block of vanilla HTML content, instantly transforming it into a beautifully formatted document.
<article class="prose">
<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>
For more details on how to use the plugin and its features, you can read the documentation.
What’s Next?
The following sections are filled with sample content to demonstrate the plugin’s capabilities. You'll find examples of typographic elements such as bold text, unordered and ordered lists, code blocks, block quotes, and even italics.
Typography Should Be Effortless
Here’s a header to show you how simple it can be to make your text look good with Tailwind.
One wise person once said:
Typography is crucial if you want your content to be visually appealing. Do it well, and your content won’t just look good—it'll shine.
Here's a polished version of your article with improved layout and descriptions:
Preview Mode for Headless CMS Learn how to implement preview mode in your headless CMS using BuouNext. This guide will walk you through the process step by step.
We often receive feedback like:
Why is Tailwind removing default styles from my h1 elements? How do I disable this? Why are all the other base styles gone too?
While simply disabling Tailwind's base styles might seem like a solution, it's not ideal. You’d end up constantly battling default margins in your UI. Plus, user-agent styles don’t always look great in a blog post—you want your content to look awesome, not bland.
To address this, we created the @tailwindcss/typography plugin. It provides a prose class that you can apply to any block of vanilla HTML content, instantly transforming it into a beautifully formatted document.
html 复制代码
Garlic Bread with Cheese: What the Science Tells Us
For years, parents have praised the health benefits of eating garlic bread with cheese, with the dish achieving iconic status in our culture. So much so, that kids often dress up as a warm, cheesy loaf for Halloween.
However, a recent study suggests that the beloved appetizer may be linked to a series of rabies cases across the country.
For more details on how to use the plugin and its features, you can read the documentation.
What’s Next? The following sections are filled with sample content to demonstrate the plugin’s capabilities. You'll find examples of typographic elements such as bold text, unordered and ordered lists, code blocks, block quotes, and even italics.
Typography Should Be Effortless Here’s a header to show you how simple it can be to make your text look good with Tailwind.
One wise person once said:
Typography is crucial if you want your content to be visually appealing. Do it well, and your content won’t just look good—it'll shine.
Images should also look well-integrated:
Contrary to popular belief, Lorem Ipsum is not just random text. It originates from classical Latin literature from 45 BC, making it over 2000 years old.
Now, let’s check out an unordered list to ensure it looks great:
- This is the first item in the list.
- We’re keeping the items short for this example.
- In later sections, we’ll explore longer, more complex list items.
And that concludes this section.
Handling Stacked Headings
Let’s Make Sure This Looks Good, Too
Sometimes, you might have headings stacked directly beneath each other. In these cases, you often need to adjust the top margin of the second heading. This usually results in a better visual flow compared to a paragraph followed by a heading.
When a Heading Follows a Paragraph
When a heading comes after a paragraph, a bit more space is required, as previously mentioned. Let’s explore what a more complex list looks like:
- List items with headings can be tricky.
I like this style, though it can be challenging to get the spacing right between paragraphs, headings, and list items. It’s tough, and you could argue that it’s better to avoid writing this way altogether.
-
Lists should have at least two items.
As mentioned before, a list needs at least two items to feel complete. I added a second item to make this example look more realistic.
-
A third item helps balance the list.
Though two items might suffice, three items offer a better balance, especially since I’m having no trouble making up arbitrary text.
After such a list, a closing paragraph usually works best, as it provides a nice visual break before the next heading.
Ensuring Code Blocks Look Good by Default
Most people will use highlight.js or Prism for syntax highlighting. However, it’s essential to ensure that code blocks look decent even without additional styling.
Here’s what a basic tailwind.config.js
file looks like:
module.exports = {
purge: [],
theme: {
extend: {},
},
variants: {},
plugins: [],
}
Hopefully that looks good enough to you.
Handling Nested Lists
Nested lists often look bad, which is why platforms like Medium discourage their use. However, for those who insist on using them, we need to ensure they work reasonably well.
- Nested lists are rarely a good idea.
- You might feel like you are being really "organized" or something but you are just creating a gross shape on the screen that is hard to read.
- Nested navigation in UIs is a bad idea too, keep things as flat as possible.
- Nesting tons of folders in your source code is also not helpful.
- More items help balance the list.
- I'm not sure if we'll bother styling more than two levels deep.
- Two is already too much, three is guaranteed to be a bad idea.
- If you nest four levels deep you belong in prison.
- Three items make a list feel complete.
- Again please don't nest lists if you want people to actually read your content.
- Nobody wants to look at this.
- I'm upset that we even have to bother styling this.
The most annoying thing about lists in Markdown is that <li>
elements aren't given a child <p>
tag unless there are multiple paragraphs in the list item. That means I have to worry about styling that annoying situation too.
-
For example, here's another nested list.
But this time with a second paragraph.
- These list items won't have
<p>
tags - Because they are only one line each
- These list items won't have
-
But in this second top-level list item, they will.
This is especially annoying because of the spacing on this paragraph.
-
As you can see here, because I've added a second line, this list item now has a
<p>
tag.This is the second line I'm talking about by the way.
-
Finally here's another list item so it's more like a list.
-
-
A closing list item, but with no nested list, because why not?
And finally a sentence to close off this section.
There are other elements we need to style
I almost forgot to mention links, like this link to the Tailwind CSS website. We almost made them blue but that's so yesterday, so we went with dark gray, feels edgier.
We even included table styles, check it out:
Wrestler | Origin | Finisher |
---|---|---|
Bret "The Hitman" Hart | Calgary, AB | Sharpshooter |
Stone Cold Steve Austin | Austin, TX | Stone Cold Stunner |
Randy Savage | Sarasota, FL | Elbow Drop |
Vader | Boulder, CO | Vader Bomb |
Razor Ramon | Chuluota, FL | Razor's Edge |
We also need to make sure inline code looks good, like if I wanted to talk about <span>
elements or tell you the good news about @tailwindcss/typography
.
Sometimes I even use code
in headings
Even though it's probably a bad idea, and historically I've had a hard time making it look good. This "wrap the code blocks in backticks" trick works pretty well though really.
Another thing I've done in the past is put a code
tag inside of a link, like if I wanted to tell you about the tailwindcss/docs
repository. I don't love that there is an underline below the backticks but it is absolutely not worth the madness it would require to avoid it.
We haven't used an h4
yet
But now we have. Please don't use h5
or h6
in your content, Medium only supports two heading levels for a reason, you animals. I honestly considered using a before
pseudo-element to scream at you if you use an h5
or h6
.
We don't style them at all out of the box because h4
elements are already so small that they are the same size as the body copy. What are we supposed to do with an h5
, make it smaller than the body copy? No thanks.
We still need to think about stacked headings though.
Let's make sure we don't screw that up with h4
elements, either.
Phew, with any luck we have styled the headings above this text and they look pretty good.
Let's add a closing paragraph here so things end with a decently sized block of text. I can't explain why I want things to end that way but I have to assume it's because I think things will look weird or unbalanced if there is a heading too close to the end of the document.
What I've written here is probably long enough, but adding this final sentence can't hurt.
GitHub Flavored Markdown
I've also added support for GitHub Flavored Mardown using remark-gfm
.
With remark-gfm
, we get a few extra features in our markdown. Example: autolink literals.
A link like www.example.com or https://example.com would automatically be converted into an a
tag.
This works for email links too: [email protected].