Skip to content

Commit d5d1daf

Browse files
committed
feat(docs): add vitepress-text-style plugin page and config
1 parent 21262ce commit d5d1daf

9 files changed

Lines changed: 251 additions & 4 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ It documents BinaryNoir's open-source VitePress plugins, Vite plugins and comman
1414
| [`@binarynoir/vitepress-reading-time-tag`](https://github.com/binarynoir/vitepress-reading-time-tag) | `[[readingTime]]` tip blocks |
1515
| [`@binarynoir/vitepress-downloads`](https://github.com/binarynoir/vitepress-downloads) | Downloadable files from a `downloads` folder |
1616
| [`markdown-it-glossary`](https://github.com/binarynoir/markdown-it-glossary) | Hover definitions from `docs/reference/glossary.md` |
17+
| [`@binarynoir/vitepress-text-style`](https://github.com/binarynoir/vitepress-text-style) | `[t:red]text[/t]` colored and sized text |
1718
| [`@binarynoir/vitepress-html-escape`](https://github.com/binarynoir/vitepress-html-escape) | Stray tags like `Array<string>` and `{{ }}` render as text; hints underline them in `docs:dev` |
1819
| [`@binarynoir/vitepress-broken-links`](https://github.com/binarynoir/vitepress-broken-links) | Dead links render as text with a fix-it popover instead of failing the build |
1920
| [`@binarynoir/vitepress-exclude`](https://github.com/binarynoir/vitepress-exclude) | `.exclude` files keep pages out of the build (a draft in `docs/plugins/exclude/` on purpose) |

‎docs/.vitepress/config.mts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { markdownHtmlEscape } from '@binarynoir/vitepress-html-escape';
1414
import { markdownBrokenLinks } from '@binarynoir/vitepress-broken-links';
1515
import { excludeSrc, excludeVitePlugin } from '@binarynoir/vitepress-exclude';
1616
import { readmeLinks, readmeRewrites } from '@binarynoir/vitepress-readme-index';
17+
import { markdownTextStyle } from '@binarynoir/vitepress-text-style';
1718

1819
// import.meta.dirname, not __dirname: VitePress configs are ESM.
1920
const docsRoot = path.resolve(import.meta.dirname, '..');
@@ -134,6 +135,8 @@ export default defineConfig({
134135
md.use(readingTimeTag);
135136
// @binarynoir/vitepress-markdown-tags: ((tag|Done|green)) becomes a badge.
136137
md.use(markdownTags);
138+
// @binarynoir/vitepress-text-style: [t:red:1.2em]text[/t] becomes colored, sized text.
139+
md.use(markdownTextStyle);
137140
// @binarynoir/vitepress-downloads: links into a `downloads` or `files` folder become file downloads.
138141
md.use(downloadsMarkdown, downloadsOptions);
139142
// @binarynoir/vitepress-readme-index: a link to README.md goes to the page it is served as.

‎docs/guide/how-this-site-works.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: How this site works
66

77
[[readingTime]]
88

9-
This site is plain VitePress 2 plus twelve plugins. There is no hand-written navigation anywhere: add a Markdown file in the right folder and it shows up in the sidebar, the navbar, search and the sitemap.
9+
This site is plain VitePress 2 plus thirteen plugins. There is no hand-written navigation anywhere: add a Markdown file in the right folder and it shows up in the sidebar, the navbar, search and the sitemap.
1010

1111
## Folder layout
1212

@@ -40,6 +40,7 @@ docs/
4040
| Status badges | [Markdown Tags](/plugins/markdown-tags/) | `markdown.config`, plus the theme |
4141
| "Reading time" box | [Reading Time Tag](/plugins/reading-time-tag) | `markdown.config` |
4242
| Dotted-underline hovers | [Glossary Tooltips](/plugins/glossary/) | `markdown.config` |
43+
| Colored and sized text | [Text Style](/plugins/text-style) | `markdown.config` |
4344
| File download links | [Downloads](/plugins/downloads) | `markdown.config` and `vite.plugins` |
4445
| Stray `<tags>` shown as text | [HTML Escape](/plugins/html-escape/) | `markdown.config`, plus the theme |
4546
| Dead links shown as text | [Broken Links](/plugins/broken-links) | `markdown.config`, plus the theme |

‎docs/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ features:
3535
width: 28
3636
height: 28
3737
title: Richer pages
38-
details: Markdown Tags, Glossary Tooltips and Reading Time add status badges, hover definitions and reading-time estimates.
38+
details: Markdown Tags, Glossary Tooltips, Reading Time and Text Style add status badges, hover definitions, reading-time estimates and colored text.
3939
link: /plugins/#pages
4040
linkText: Page plugins
4141
- icon:

‎docs/plugins/.sidebar‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ auto-navbar.md:Auto Navbar
99
markdown-tags:Markdown Tags
1010
glossary:Glossary Tooltips
1111
reading-time-tag.md:Reading Time Tag
12+
text-style.md:Text Style
1213
[Content where it lives]
1314
downloads.md:Downloads
1415
exclude:Exclude

‎docs/plugins/index.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: Plugins
66

77
[[readingTime]]
88

9-
Twelve small packages that make a documentation site easier to build and nicer to read. Each one does a single job and they share conventions. All twelve are running on the site you are looking at.
9+
Thirteen small packages that make a documentation site easier to build and nicer to read. Each one does a single job and they share conventions. All thirteen are running on the site you are looking at.
1010

1111
Pick by the job you need done. Each plugin's page has a live demo.
1212

@@ -28,6 +28,7 @@ Small additions that help a reader scan and understand a page.
2828
| [Markdown Tags](/plugins/markdown-tags/) | VitePress, VS Code, Obsidian | Inline status badges and tagged-pages lists. |
2929
| [Glossary Tooltips](/plugins/glossary/) | VitePress, markdown-it | Hover definitions from one glossary file. |
3030
| [Reading Time Tag](/plugins/reading-time-tag) | VitePress 2 | `[[readingTime]]` becomes a reading-time tip block. |
31+
| [Text Style](/plugins/text-style) | VitePress, markdown-it | `[t:red]text[/t]` colors and sizes text inline. |
3132

3233
## Content where it lives {#content}
3334

@@ -70,14 +71,15 @@ npm install --save-dev \
7071
@binarynoir/vitepress-broken-links \
7172
@binarynoir/vitepress-exclude \
7273
@binarynoir/vitepress-readme-index \
74+
@binarynoir/vitepress-text-style \
7375
@binarynoir/vite-plugin-optimize-images \
7476
@binarynoir/vite-plugin-image-fallback \
7577
markdown-it-glossary
7678
```
7779

7880
The VitePress plugins target VitePress 2 (currently an alpha release line). Node 22 or newer is required.
7981

80-
## One config, all twelve
82+
## One config, all thirteen
8183

8284
This is this site's real `config.mts`, included straight from the repository, so it can't drift from what is deployed. [How this site works](/guide/how-this-site-works) walks through it.
8385

‎docs/plugins/text-style.md‎

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
---
2+
title: Text Style
3+
---
4+
5+
# Text Style ((tag|VitePress plugin|blue)) ((tag|markdown-it|orange))
6+
7+
[[readingTime]]
8+
9+
[![GitHub repo](https://img.shields.io/badge/GitHub-binarynoir%2Fvitepress--text--style-181717?logo=github)](https://github.com/binarynoir/vitepress-text-style) [![npm version](https://img.shields.io/npm/v/@binarynoir/vitepress-text-style)](https://www.npmjs.com/package/@binarynoir/vitepress-text-style) [![CI](https://img.shields.io/github/actions/workflow/status/binarynoir/vitepress-text-style/ci.yml?branch=main&label=CI)](https://github.com/binarynoir/vitepress-text-style/actions/workflows/ci.yml) [![License](https://img.shields.io/github/license/binarynoir/vitepress-text-style)](https://github.com/binarynoir/vitepress-text-style/blob/main/LICENSE)
10+
11+
`@binarynoir/vitepress-text-style` colors and sizes text inline, without writing HTML. Write `[t:red]warning[/t]` or `[t::1.2em]larger[/t]` and get a styled `<span>`. Values are checked before they reach the page, code is left alone, and the text inside is still Markdown.
12+
13+
It uses the same `[t:color:size]` syntax as the text-style plugin many VuePress sites carry, so pages can move to VitePress without being rewritten. Every example below is live: each one shows the Markdown as written, then the same Markdown rendered by this site.
14+
15+
## See it live
16+
17+
```md
18+
A [t:red]red[/t] word, a [t:blue:1.4em]big blue[/t] one, and a [t::small]small[/t] one.
19+
```
20+
21+
::: info On the page
22+
A [t:red]red[/t] word, a [t:blue:1.4em]big blue[/t] one, and a [t::small]small[/t] one.
23+
:::
24+
25+
## Install
26+
27+
```sh
28+
npm install --save-dev @binarynoir/vitepress-text-style
29+
```
30+
31+
## Use
32+
33+
Register it in VitePress's `markdown.config` hook, the same place as any other markdown-it plugin:
34+
35+
```ts
36+
// .vitepress/config.mts
37+
import { defineConfig } from 'vitepress';
38+
import { markdownTextStyle } from '@binarynoir/vitepress-text-style';
39+
40+
export default defineConfig({
41+
markdown: {
42+
config(md) {
43+
md.use(markdownTextStyle);
44+
},
45+
},
46+
});
47+
```
48+
49+
Or wrap the config with `withTextStyle` from `@binarynoir/vitepress-text-style/vitepress`. It keeps any `markdown.config` you already have, including one set by another `withX()` wrapper.
50+
51+
```ts
52+
import { withTextStyle } from '@binarynoir/vitepress-text-style/vitepress';
53+
54+
export default withTextStyle(
55+
defineConfig({
56+
// ...your config
57+
}),
58+
);
59+
```
60+
61+
## Syntax
62+
63+
```md
64+
[t:color]text[/t]
65+
[t:color:size]text[/t]
66+
[t::size]text[/t]
67+
```
68+
69+
Either value can be left out, but not both. Whitespace around the values and the text is ignored, so `[t: red ] text [/t]` is the same as `[t:red]text[/t]`.
70+
71+
### Markdown inside
72+
73+
The text in a span is parsed as Markdown, so emphasis, code, links and badges all work inside it:
74+
75+
```md
76+
[t:green]**Done:** see [the overview](/plugins/) and run `npm test`. ((tag|Shipped|green))[/t]
77+
```
78+
79+
::: info On the page
80+
[t:green]**Done:** see [the overview](/plugins/) and run `npm test`. ((tag|Shipped|green))[/t]
81+
:::
82+
83+
### Nesting
84+
85+
Spans nest, and each `[/t]` closes its own opener:
86+
87+
```md
88+
[t:var(--vp-c-brand-1)]The brand color, with [t::1.5em]a larger word[/t] in the middle.[/t]
89+
```
90+
91+
::: info On the page
92+
[t:var(--vp-c-brand-1)]The brand color, with [t::1.5em]a larger word[/t] in the middle.[/t]
93+
:::
94+
95+
### Headings, lists and tables
96+
97+
A span stays within one paragraph, heading, list item or table cell.
98+
99+
```md
100+
- [t:var(--vp-c-tip-1)]Ready[/t] for review
101+
- [t:var(--vp-c-danger-1)]Blocked[/t] on a dependency
102+
103+
| Status | Count |
104+
| ------------------------------------ | ----- |
105+
| [t:var(--vp-c-warning-1)]Pending[/t] | 3 |
106+
```
107+
108+
::: info On the page
109+
110+
- [t:var(--vp-c-tip-1)]Ready[/t] for review
111+
- [t:var(--vp-c-danger-1)]Blocked[/t] on a dependency
112+
113+
| Status | Count |
114+
| ------------------------------------ | ----- |
115+
| [t:var(--vp-c-warning-1)]Pending[/t] | 3 |
116+
117+
:::
118+
119+
### Code is left alone
120+
121+
Inline code, fenced code and indented code blocks are never styled, so you can show the syntax itself in backticks, as this page does. To show it as text outside code, escape the opener with a backslash:
122+
123+
```md
124+
In code: `[t:red]not styled[/t]`. Escaped: \[t:red]not styled[/t].
125+
```
126+
127+
::: info On the page
128+
In code: `[t:red]not styled[/t]`. Escaped: \[t:red]not styled[/t].
129+
:::
130+
131+
## Values
132+
133+
### Colors
134+
135+
| Form | Examples |
136+
| --------------- | ------------------------------------------------------------------------------- |
137+
| Named colors | `red`, `rebeccapurple`, `currentColor`, `transparent` |
138+
| Hex | `#f00`, `#f008`, `#ff0000`, `#ff000080` |
139+
| Color functions | `rgb(255 0 0)`, `rgba(255,0,0,.5)`, `hsl(120deg 50% 50%)`, `oklch(70% 0.1 200)` |
140+
| CSS variables | `var(--vp-c-brand-1)` |
141+
142+
### Sizes
143+
144+
| Form | Examples |
145+
| --------------- | ----------------------------------------------- |
146+
| Number and unit | `16px`, `24pt`, `1.2em`, `.8rem`, `150%`, `5vw` |
147+
| Keywords | `xx-small` to `xxx-large`, `smaller`, `larger` |
148+
| CSS variables | `var(--my-size)` |
149+
150+
```md
151+
[t:#e67e22]Hex[/t], [t:rgb(46 134 222)]rgb()[/t], [t:hsl(280deg 60% 55%)]hsl()[/t], [t:oklch(65% 0.2 145)]oklch()[/t], and [t::x-large]x-large[/t].
152+
```
153+
154+
::: info On the page
155+
[t:#e67e22]Hex[/t], [t:rgb(46 134 222)]rgb()[/t], [t:hsl(280deg 60% 55%)]hsl()[/t], [t:oklch(65% 0.2 145)]oklch()[/t], and [t::x-large]x-large[/t].
156+
:::
157+
158+
### Light and dark mode
159+
160+
A fixed color such as `darkblue` can be hard to read on a dark background. VitePress's theme variables change with the mode, so text colored with them stays readable in both. Switch this site's appearance and compare:
161+
162+
```md
163+
[t:darkblue]darkblue[/t] against [t:var(--vp-c-brand-1)]var(--vp-c-brand-1)[/t] and [t:var(--vp-c-danger-1)]var(--vp-c-danger-1)[/t].
164+
```
165+
166+
::: info On the page
167+
[t:darkblue]darkblue[/t] against [t:var(--vp-c-brand-1)]var(--vp-c-brand-1)[/t] and [t:var(--vp-c-danger-1)]var(--vp-c-danger-1)[/t].
168+
:::
169+
170+
### Invalid values
171+
172+
Anything the plugin doesn't recognise is dropped. If one value is invalid the other is still applied. If neither is, the whole span is shown as written, so a typo is visible on the page instead of silently doing nothing:
173+
174+
```md
175+
[t:red:huge]Red at the normal size[/t]. [t:#ff00000]A seven-digit hex, shown as written[/t].
176+
```
177+
178+
::: info On the page
179+
[t:red:huge]Red at the normal size[/t]. [t:#ff00000]A seven-digit hex, shown as written[/t].
180+
:::
181+
182+
Named colors are accepted as any single word, so a misspelled name such as `redd` still becomes a span, and the browser ignores the color. No value can contain `;`, quotes or `<`, so a marker can't add other CSS or break out of the `style` attribute.
183+
184+
## Options
185+
186+
`markdownTextStyle(md, options)` and `withTextStyle(config, options)` take:
187+
188+
| Option | Default | Description |
189+
| ----------- | ------- | --------------------------------------------------------------------------------------- |
190+
| `className` | none | A class added to every styled `<span>`, for theme CSS that should apply to all of them. |
191+
192+
## Per-page settings
193+
194+
A page turns the plugin off with `textStyle: false` in its frontmatter. On that page `[t:…]` is shown as written.
195+
196+
```md
197+
---
198+
textStyle: false
199+
---
200+
```
201+
202+
## Migrating from VuePress
203+
204+
The syntax and output match the VuePress text-style plugin, with a few differences:
205+
206+
- **Code is detected by markdown-it, not by splitting on backticks.** Indented code blocks and multi-backtick code spans are now left alone too.
207+
- **The text is Markdown.** `**bold**` inside a span is bold, and text containing `[`, such as `array[0]`, now works.
208+
- **Spans nest.**
209+
- **More values are accepted:** 4- and 8-digit hex, modern color functions, CSS variables, and `vmin`, `vmax` and `q` sizes.
210+
211+
[README Index](/plugins/readme-index/) helps with the other half of a VuePress move: it serves `README.md` as a folder's index page.
212+
213+
## Limits
214+
215+
- **A span can't go inside a link's text.** `[[t:red]docs[/t]](/docs)` isn't a link, because markdown-it doesn't allow brackets another rule consumed inside a link label. Put the span around the link instead: `[t:red][docs](/docs)[/t]`.
216+
- **Inline styles only.** For styling you reuse, a class in your theme CSS is easier to change later; `className` adds one to every span.
217+
218+
[Source and full README on GitHub](https://github.com/binarynoir/vitepress-text-style)

‎package-lock.json‎

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@binarynoir/vitepress-markdown-tags": "^0.2.6",
3434
"@binarynoir/vitepress-reading-time-tag": "^0.1.8",
3535
"@binarynoir/vitepress-readme-index": "^0.1.1",
36+
"@binarynoir/vitepress-text-style": "^0.1.0",
3637
"@types/node": "^24.19.2",
3738
"markdown-it-glossary": "^0.4.3",
3839
"prettier": "^3.9.10",

0 commit comments

Comments
 (0)