Skip to content

Commit 207e6b1

Browse files
committed
📝 Add codeblock title for filename
1 parent ab1765b commit 207e6b1

15 files changed

+45
-20
lines changed

assets/codeblock-title.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.codeblock-title {
2+
display: block;
3+
margin: 0;
4+
padding: 0.5em 1em;
5+
font-size: 0.9em;
6+
color: color-mix(in srgb, var(--fg), #777 50%);
7+
background-color: color-mix(in srgb, var(--bg), #777 20%);
8+
}

assets/codeblock-title.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
document.addEventListener("DOMContentLoaded", () => {
2+
const codeblocks = document.querySelectorAll("pre code");
3+
codeblocks.forEach((codeblock) => {
4+
const found = [...codeblock.classList.values()].find((v) =>
5+
v.startsWith("title=")
6+
);
7+
if (found) {
8+
const title = found.replace(/^title=/, "");
9+
const titleElement = document.createElement("header");
10+
titleElement.classList.add("codeblock-title");
11+
titleElement.textContent = title;
12+
codeblock.parentNode.prepend(titleElement, codeblock);
13+
}
14+
});
15+
});

book.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ title = "Denops Documentation"
77

88
[output.html]
99
default-theme = "coal"
10+
additional-js = ["assets/codeblock-title.js"]
11+
additional-css = ["assets/codeblock-title.css"]
1012

1113
[preprocessor.alerts]

src/getting-started/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $HOME
2121

2222
Next, write the following TypeScript code in `main.ts`:
2323

24-
```typescript:denops/denops-getting-started/main.ts
24+
```typescript,title=denops/denops-getting-started/main.ts
2525
import type { Entrypoint } from "jsr:@denops/[email protected]";
2626

2727
export const main: Entrypoint = (denops) => {
@@ -38,13 +38,13 @@ export const main: Entrypoint = (denops) => {
3838
Add the following line to your Vim or Neovim configuration file (e.g.,
3939
`~/.vimrc` or `~/.config/nvim/init.vim`):
4040

41-
```vim
41+
```vim,title=~/.vimrc
4242
set runtimepath+=~/denops-getting-started
4343
```
4444

4545
Or Neovim Lua configuration file (e.g., `~/.config/nvim/init.lua`):
4646

47-
```lua
47+
```lua,title=~/.config/nvim/init.lua
4848
vim.opt.runtimepath:append("~/denops-getting-started")
4949
```
5050

src/tutorial/helloworld/adding-an-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ will enhance the plugin by adding an API.
66
Open `denops/denops-helloworld/main.ts` and rewrite the content with the
77
following code:
88

9-
```typescript:denops/denops-helloworld/main.ts
9+
```typescript,title=denops/denops-helloworld/main.ts
1010
import type { Entrypoint } from "jsr:@denops/[email protected]";
1111
import { assert, is } from "jsr:@core/[email protected]";
1212

src/tutorial/helloworld/calling-vim-features.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ If you want to use a Vim feature from your Denops plugin, you can call it via
44
the `denops` instance passed to the plugin's `main` function. You can rewrite
55
`main.ts` as follows to register the `DenopsHello` as a Vim command:
66

7-
```ts:denops/denops-helloworld/main.ts
7+
```typescript,title=denops/denops-helloworld/main.ts
88
import type { Entrypoint } from "jsr:@denops/[email protected]";
99
import { assert, is } from "jsr:@core/[email protected]";
1010

@@ -29,7 +29,7 @@ export const main: Entrypoint = (denops) => {
2929
Then, rewrite `plugin/denops-helloworld.vim` to automatically call the `init`
3030
API on plugin load via the `DenopsPluginPost:{plugin_name}` autocmd:
3131

32-
```vim:plugin/denops-helloworld.vim
32+
```vim,title=plugin/denops-helloworld.vim
3333
if exists('g:loaded_denops_helloworld')
3434
finish
3535
endif

src/tutorial/helloworld/creating-a-minimal-denops-plugin.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ denops-helloworld
3131

3232
Here is the content of the `denops/denops-helloworld/main.ts` file:
3333

34-
```typescript:denops/denops-helloworld/main.ts
34+
```typescript,title=denops/denops-helloworld/main.ts
3535
import type { Entrypoint } from "jsr:@denops/[email protected]";
3636

3737
export const main: Entrypoint = (denops) => {

src/tutorial/helloworld/creating-a-minimal-vim-plugin.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ denops-helloworld
1313

1414
The content of the `plugin/denops-helloworld.vim` file is as follows:
1515

16-
```vim:plugin/denops-helloworld.vim
16+
```vim,title=plugin/denops-helloworld.vim
1717
if exists('g:loaded_denops_helloworld')
1818
finish
1919
endif
@@ -45,13 +45,13 @@ Upon startup, Vim searches and loads files named `plugin/*.vim` in directories
4545
specified in `runtimepath`. To activate the plugin, add the following line to
4646
your Vim configuration file (e.g., `~/.vimrc` or `~/.config/nvim/init.vim`):
4747

48-
```vim
48+
```vim,title=~/.vimrc
4949
set runtimepath+=~/denops-helloworld
5050
```
5151

5252
For Neovim's Lua configuration file (e.g., `~/.config/nvim/init.lua`), use:
5353

54-
```lua
54+
```lua,title=~/.config/nvim/init.lua
5555
vim.opt.runtimepath:append("~/denops-helloworld")
5656
```
5757

src/tutorial/maze/adjusting-maze-size-to-fit-the-window.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ to have a maze that fits the current window size.
77
Let's modify the plugin to ensure the generated maze fits the current window
88
size.
99

10-
```typescript:denops/denops-helloworld/main.ts
10+
```typescript,title=denops/denops-helloworld/main.ts
1111
import type { Entrypoint } from "jsr:@denops/[email protected]";
1212
import * as fn from "jsr:@denops/[email protected]/function";
1313
import { Maze } from "npm:@thewizardbear/[email protected]";

src/tutorial/maze/creating-applicative-plugin.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ the maze plugin that will satisfy your crazy addictive maze solver friend.
1111
First, modify `plugin/denops-maze.vim` to accept the `Maze` command with an
1212
optional argument.
1313

14-
```vim:plugin/denops-maze.vim
14+
```vim,title=plugin/denops-maze.vim
1515
if exists('g:loaded_denops_maze')
1616
finish
1717
endif
@@ -32,7 +32,7 @@ Then, modify the `main.ts` file to accept the optional argument for a custom
3232
opener, generate a maze that fits the current window size, configure the buffer
3333
options to make it non-file readonly buffer, etc.
3434

35-
```ts:denops/denops-maze/main.ts
35+
```typescript,title=denops/denops-maze/main.ts
3636
import type { Entrypoint } from "jsr:@denops/[email protected]";
3737
import { batch, collect } from "jsr:@denops/[email protected]/batch";
3838
import * as fn from "jsr:@denops/[email protected]/function";

0 commit comments

Comments
 (0)