Skip to content

Commit 54cc9ff

Browse files
committed
feat(theme): support title-less custom containers
Adds a special handling for the no-title attribute on the container, which skips rendering the title, alowing for titleless containers. The styles are updated as well to remove the excessive padding for such containers.
1 parent c2eaccd commit 54cc9ff

File tree

9 files changed

+30
-29
lines changed

9 files changed

+30
-29
lines changed

docs/en/guide/what-is-vitepress.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
VitePress is a [Static Site Generator](https://en.wikipedia.org/wiki/Static_site_generator) (SSG) designed for building fast, content-centric websites. In a nutshell, VitePress takes your source content written in [Markdown](https://en.wikipedia.org/wiki/Markdown), applies a theme to it, and generates static HTML pages that can be easily deployed anywhere.
44

5-
<div class="tip custom-block" style="padding-top: 8px">
6-
5+
::: tip {no-title}
76
Just want to try it out? Skip to the [Quickstart](./getting-started).
8-
9-
</div>
7+
:::
108

119
## Use Cases
1210

docs/es/guide/what-is-vitepress.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
VitePress es un [Generador de Sitios Estáticos](https://en.wikipedia.org/wiki/Static_site_generator) (SSG) diseñado para construir sitios web rápidos y enfocados en el contenido. En pocas palabras, VitePress toma tu contenido fuente escrito en [Markdown](https://en.wikipedia.org/wiki/Markdown), le aplica un tema y genera páginas HTML estáticas que se pueden desplegar fácilmente en cualquier lugar.
44

5-
<div class="tip custom-block" style="padding-top: 8px">
6-
5+
::: tip {no-title}
76
¿Quieres probarlo? Ve directo al [Inicio Rápido](./getting-started).
8-
9-
</div>
7+
:::
108

119
## Casos de Uso {#use-cases}
1210

docs/fa/guide/what-is-vitepress.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
ویت‌پرس یک [تولید کننده سایت ایستا](https://en.wikipedia.org/wiki/Static_site_generator) (SSG) است که برای ساخت وب‌سایت‌های سریع و محتوا محور طراحی شده است. به طور خلاصه، ویت‌پرس محتوای منبع شما که به زبان [Markdown](https://en.wikipedia.org/wiki/Markdown) نوشته شده است را گرفته، یک تم بر روی آن اعمال می‌کند و صفحات HTML ایستا تولید می‌کند که به راحتی در هر جایی قابل استقرار هستند.
44

5-
<div class="tip custom-block" style="padding-top: 8px">
6-
5+
::: tip {no-title}
76
فقط می‌خواهید آن را امتحان کنید؟ به [شروع سریع](./getting-started) بروید.
8-
9-
</div>
7+
:::
108

119
## موارد استفاده {#use-cases}
1210

docs/ko/guide/what-is-vitepress.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
VitePress는 빠르고 컨텐츠 중심의 웹사이트를 구축하기 위해 설계된 [정적 사이트 생성기](https://en.wikipedia.org/wiki/Static_site_generator) (SSG)입니다. 다시말해 VitePress는 [마크다운](https://en.wikipedia.org/wiki/Markdown)으로 작성된 소스 컨텐츠를 가져와서 테마를 적용하고, 어디에나 쉽게 배포할 수 있는 정적 HTML 페이지를 생성합니다.
44

5-
<div class="tip custom-block" style="padding-top: 8px">
6-
5+
::: tip {no-title}
76
그냥 한번 사용해보고 싶으신가요? [빠른 시작](./getting-started)으로 건너뛰세요.
8-
9-
</div>
7+
:::
108

119
## 사용 사례 {#use-cases}
1210

docs/pt/guide/what-is-vitepress.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
O VitePress é um [Gerador de Site Estático](https://en.wikipedia.org/wiki/Static_site_generator) (SSG) projetado para criar sites rápidos e centrados em conteúdo. Em suma, VitePress utiliza seu conteúdo-fonte escrito em [Markdown](https://en.wikipedia.org/wiki/Markdown), aplica um tema a ele e gera páginas HTML estáticas que podem ser facilmente implantadas em qualquer lugar.
44

5-
<div class="tip custom-block" style="padding-top: 8px">
6-
5+
::: tip {no-title}
76
Quer apenas experimentar? Pule para o [Início Rápido](./getting-started).
8-
9-
</div>
7+
:::
108

119
## Casos de Uso {#use-cases}
1210

docs/ru/guide/what-is-vitepress.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
VitePress — это [Генератор статических сайтов](https://en.wikipedia.org/wiki/Static_site_generator) (ГСС), предназначенный для быстрого создания сайтов, ориентированных на контент. В двух словах, VitePress берёт ваш исходный контент, написанный в [Markdown](https://ru.wikipedia.org/wiki/Markdown), применяет к нему тему и генерирует статические HTML-страницы, которые можно легко развернуть в любом месте.
44

5-
<div class="tip custom-block" style="padding-top: 8px">
6-
5+
::: tip {no-title}
76
Хотите попробовать прямо сейчас? Перейдите к главе [Первые шаги](./getting-started).
8-
9-
</div>
7+
:::
108

119
## Примеры использования {#use-cases}
1210

docs/zh/guide/what-is-vitepress.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
VitePress 是一个[静态站点生成器](https://en.wikipedia.org/wiki/Static_site_generator) (SSG),专为构建快速、以内容为中心的站点而设计。简而言之,VitePress 获取用 Markdown 编写的内容,对其应用主题,并生成可以轻松部署到任何地方的静态 HTML 页面。
44

5-
<div class="tip custom-block" style="padding-top: 8px">
6-
5+
::: tip {no-title}
76
只是想尝试一下?跳到[快速开始](./getting-started)
8-
9-
</div>
7+
:::
108

119
## 使用场景 {#use-cases}
1210

src/client/theme-default/styles/components/custom-block.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
.custom-block {
22
border: 1px solid transparent;
33
border-radius: 8px;
4-
padding: 16px 16px 8px;
4+
padding: 8px 16px;
55
line-height: 24px;
66
font-size: var(--vp-custom-block-font-size);
77
color: var(--vp-c-text-2);
88
}
99

10+
.custom-block:has(.custom-block-title) {
11+
padding-top: 16px;
12+
}
13+
1014
.custom-block.info {
1115
border-color: var(--vp-custom-block-info-border);
1216
color: var(--vp-custom-block-info-text);

src/node/markdown/plugins/containers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ export const containerPlugin = (
2828

2929
type ContainerArgs = [typeof container, string, { render: RenderRule }]
3030

31+
function attrPop(token: Token, name: string) {
32+
const idx = token.attrIndex(name)
33+
if (idx < 0) return null
34+
return token.attrs!.splice(idx, 1)[0][1]
35+
}
36+
3137
function createContainer(
3238
klass: string,
3339
defaultTitle: string,
@@ -38,10 +44,15 @@ function createContainer(
3844
klass,
3945
{
4046
render(tokens, idx, _options, env: MarkdownEnv & { references?: any }) {
47+
const containerTipToken = tokens.find(
48+
({ type }) => type === 'container_tip_open'
49+
)
50+
const skipTitle = attrPop(containerTipToken!, 'no-title') === ''
4151
const token = tokens[idx]
4252
if (token.nesting === 1) {
4353
token.attrJoin('class', `${klass} custom-block`)
4454
const attrs = md.renderer.renderAttrs(token)
55+
if (skipTitle && klass !== 'details') return `<div ${attrs}>\n`
4556
const info = token.info.trim().slice(klass.length).trim()
4657
const title = md.renderInline(info || defaultTitle, {
4758
references: env.references

0 commit comments

Comments
 (0)