Skip to content

Commit 6b8d8cc

Browse files
committed
Better code block titles
1 parent 1aef9d2 commit 6b8d8cc

File tree

3 files changed

+10
-35
lines changed

3 files changed

+10
-35
lines changed

docs/assets/css/base.css

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,14 @@ code {
361361
background: var(--rgb-highlight-background, var(--color-base-dark));
362362

363363
.filename {
364-
background-color: rgba(var(--rgb-black), 0.08);
364+
border-bottom: 1px solid rgba(var(--rgb-black), 0.05);
365365
font-family: monospace;
366-
padding: 0.6em 1.2em;
366+
padding: 0.6em 1.2em 0.4em;
367+
margin-bottom: 0.4em;
367368
display: block;
368369
font-size: 0.8em;
369370
border-radius: 0.3em 0.3em 0 0;
371+
width: fit-content;
370372
}
371373
[data-linenos]::before {
372374
color: rgba(var(--rgb-grey-light), 0.8);
@@ -460,9 +462,6 @@ code {
460462
--rgb-highlight-color: #E6E1DC !important;
461463
--rgb-highlight-background: var(--color-base) !important;
462464

463-
.filename {
464-
background-color: rgba(var(--rgb-black), 0.6) !important;
465-
}
466465
.hll { --rgb-hll: 66, 135, 255 !important; }
467466
.c { color: #BC9458 !important; font-style: italic !important; } /* Comment */
468467
.err { color: #E6E1DC !important; } /* Error */
@@ -539,9 +538,6 @@ html.cs-dark .highlight {
539538
--rgb-highlight-color: #E6E1DC !important;
540539
--rgb-highlight-background: var(--color-base) !important;
541540

542-
.filename {
543-
background-color: rgba(var(--rgb-black), 0.6) !important;
544-
}
545541
.hll { --rgb-hll: 66, 135, 255 !important; }
546542
.c { color: #BC9458 !important; font-style: italic !important; } /* Comment */
547543
.err { color: #E6E1DC !important; } /* Error */

docs/content/markdown/code.md

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ Leave one blank line before and after the block for easier reading.
99
/// example | Code block
1010

1111
````md
12-
1312
```javascript
1413
console.log("Hello world");
1514
```
16-
`````
15+
````
1716

1817
```javascript
1918
console.log("Hello world");
@@ -53,13 +52,11 @@ To make your code block clearer, specify the language right after the first thre
5352
/// example | Syntax highlighting
5453

5554
````md
56-
5755
```python
5856
print("Hello, world!")
5957
for i in range(10):
6058
print(i)
6159
```
62-
6360
````
6461

6562
renders as:
@@ -84,14 +81,12 @@ The number _must_ be quoted, and it is the number of the first line (it must be
8481
/// example | Line Numbers
8582

8683
````md
87-
8884
```python {linenums="1"}
8985
import foo.bar
9086

9187
a = "lorem"
9288
b = "ipsum"
9389
```
94-
9590
````
9691

9792
renders as:
@@ -110,15 +105,13 @@ If you want to start with a different line number, simply specify a number other
110105
/// example | Line Numbers
111106

112107
````md
113-
114108
```python {linenums="42"}
115109
def foobar():
116110
a = "lorem"
117111
b = "ipsum"
118112

119113
foobar()
120114
```
121-
122115
````
123116

124117
renders as:
@@ -138,14 +131,12 @@ Pygments also has a few additional options regarding line numbers. One is "line
138131
/// example | N^th^ line
139132

140133
````md
141-
142134
``` {linenums="1 2"}
143135
"""Some file."""
144136
import foo.bar
145137
import boo.baz
146138
import foo.bar.baz
147139
```
148-
149140
````
150141

151142
renders as:
@@ -167,14 +158,12 @@ You can specify certain lines for highlighting by using the `hl_lines` setting d
167158
/// example | Highlight Lines
168159

169160
````md
170-
171161
```python {hl_lines="1 3"}
172162
"""Some file."""
173163
import foo.bar
174164
import boo.baz
175165
import foo.bar.baz
176166
```
177-
178167
````
179168

180169
renders as:
@@ -193,15 +182,13 @@ Line numbers are always referenced starting at 1, regardless of what the line nu
193182
/// example | Highlight Lines with Line Numbers
194183

195184
````md
196-
197185
```python {linenums="42" hl_lines="2"}
198186
def foobar():
199187
a = "lorem"
200188
b = "ipsum"
201189

202190
foobar()
203191
```
204-
205192
````
206193

207194
renders as:
@@ -221,7 +208,6 @@ If you'd like to highlight a range of lines, you can use the notation x-y, where
221208
/// example | Highlight Lines with Line Numbers
222209

223210
````md
224-
225211
```python {hl_lines="1-2 5 7-8"}
226212
import foo
227213
import boo.baz
@@ -233,7 +219,6 @@ class Foo:
233219
self.bar = None
234220
self.baz = None
235221
```
236-
237222
````
238223

239224
renders as:
@@ -253,14 +238,13 @@ class Foo:
253238
///
254239

255240

256-
## Code Block Title Headers
241+
## Title Headers
257242

258243
A header with a title can be applied to a code block using the title option. Typically, you use it to show a filename, but it can be anything.
259244

260245
/// example | Code block with a header
261246

262247
````md
263-
264248
```python {title="cool_file.py"}
265249
import foo
266250
import boo.baz
@@ -272,7 +256,6 @@ class Foo:
272256
self.bar = None
273257
self.baz = None
274258
```
275-
276259
````
277260

278261
renders as:

src/writeadoc/blueprint/assets/css/base.css

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,12 +361,14 @@ code {
361361
background: var(--rgb-highlight-background, var(--color-base-dark));
362362

363363
.filename {
364-
background-color: rgba(var(--rgb-black), 0.08);
364+
border-bottom: 1px solid rgba(var(--rgb-black), 0.05);
365365
font-family: monospace;
366-
padding: 0.6em 1.2em;
366+
padding: 0.6em 1.2em 0.4em;
367+
margin-bottom: 0.4em;
367368
display: block;
368369
font-size: 0.8em;
369370
border-radius: 0.3em 0.3em 0 0;
371+
width: fit-content;
370372
}
371373
[data-linenos]::before {
372374
color: rgba(var(--rgb-grey-light), 0.8);
@@ -460,9 +462,6 @@ code {
460462
--rgb-highlight-color: #E6E1DC !important;
461463
--rgb-highlight-background: var(--color-base) !important;
462464

463-
.filename {
464-
background-color: rgba(var(--rgb-black), 0.6) !important;
465-
}
466465
.hll { --rgb-hll: 66, 135, 255 !important; }
467466
.c { color: #BC9458 !important; font-style: italic !important; } /* Comment */
468467
.err { color: #E6E1DC !important; } /* Error */
@@ -539,9 +538,6 @@ html.cs-dark .highlight {
539538
--rgb-highlight-color: #E6E1DC !important;
540539
--rgb-highlight-background: var(--color-base) !important;
541540

542-
.filename {
543-
background-color: rgba(var(--rgb-black), 0.6) !important;
544-
}
545541
.hll { --rgb-hll: 66, 135, 255 !important; }
546542
.c { color: #BC9458 !important; font-style: italic !important; } /* Comment */
547543
.err { color: #E6E1DC !important; } /* Error */

0 commit comments

Comments
 (0)