Skip to content

Commit 9e8b6f7

Browse files
authored
Merge pull request #15 from vim-denops/add-codeblock-title
Add codeblock title
2 parents 9122f91 + 726772c commit 9e8b6f7

18 files changed

+106
-69
lines changed

.github/workflows/mdbook.yml

+11-6
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,22 @@ jobs:
3232
MDBOOK_VERSION: 0.4.36
3333
steps:
3434
- uses: actions/checkout@v4
35-
- name: Install mdBook
36-
run: |
37-
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -y | sh
38-
rustup update
39-
cargo install --force --version ${MDBOOK_VERSION} mdbook
40-
cargo install --force mdbook-alerts
35+
36+
- name: Install mdbook and cargo-binstall binaries
37+
uses: taiki-e/install-action@v2
38+
with:
39+
tool: mdbook,cargo-binstall
40+
41+
- name: Install mdbook extensions
42+
run: cargo binstall -y mdbook-alerts
43+
4144
- name: Setup Pages
4245
id: pages
4346
uses: actions/configure-pages@v4
47+
4448
- name: Build with mdBook
4549
run: mdbook build
50+
4651
- name: Upload artifact
4752
uses: actions/upload-pages-artifact@v3
4853
with:

.github/workflows/test.yml

+13-6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- uses: actions/checkout@v4
19+
1920
- uses: actions/cache@v4
2021
with:
2122
path: |
@@ -26,18 +27,24 @@ jobs:
2627
target/
2728
.tools/
2829
key: ${{ runner.os }}-cargo
30+
2931
- uses: denoland/[email protected]
3032
with:
3133
deno-version: ${{ env.DENO_VERSION }}
32-
- name: Install mdBook
33-
run: |
34-
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -y | sh
35-
rustup update
36-
cargo install --force --version ${MDBOOK_VERSION} mdbook
37-
cargo install --force mdbook-alerts
34+
35+
- name: Install mdbook and cargo-binstall binaries
36+
uses: taiki-e/install-action@v2
37+
with:
38+
tool: mdbook,cargo-binstall
39+
40+
- name: Install mdbook extensions
41+
run: cargo binstall -y mdbook-alerts
42+
3843
- name: Build with mdBook
3944
run: mdbook build
45+
4046
- name: Format
4147
run: deno fmt --check
48+
4249
- name: Misspell
4350
uses: reviewdog/[email protected]

assets/codeblock-title.css

+8
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

+15
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

+2
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

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ $HOME
2121

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

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

2727
export const main: Entrypoint = (denops) => {
2828
denops.dispatcher = {
@@ -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/getting-started/explanation.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ easily call.
9191
In the Getting Started, we wrote the following code in the `main.ts` file:
9292

9393
```typescript
94-
import type { Entrypoint } from "jsr:@denops/[email protected]";
94+
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
9595

9696
export const main: Entrypoint = (denops) => {
9797
denops.dispatcher = {
@@ -107,7 +107,7 @@ Let's break down this code step by step.
107107
### About Imports
108108

109109
```typescript
110-
import type { Entrypoint } from "jsr:@denops/[email protected]";
110+
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
111111
```
112112

113113
The first line imports the `Entrypoint` type from the [@denops/std] standard
@@ -215,7 +215,7 @@ For example, use
215215
Vim's function instead of `denops.call` like:
216216

217217
```typescript
218-
import * as fn from "jsr:@denops/[email protected]/function";
218+
import * as fn from "jsr:@denops/std@^7.0.0/function";
219219

220220
// Bad (result1 is `unknown`)
221221
const result1 = await denops.call("expand", "%");

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ 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
10-
import type { Entrypoint } from "jsr:@denops/[email protected]";
11-
import { assert, is } from "jsr:@core/unknownutil@3.18.1";
9+
```typescript,title=denops/denops-helloworld/main.ts
10+
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
11+
import { assert, is } from "jsr:@core/unknownutil@^4.3.0";
1212

1313
export const main: Entrypoint = (denops) => {
1414
denops.dispatcher = {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ 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
8-
import type { Entrypoint } from "jsr:@denops/[email protected]";
9-
import { assert, is } from "jsr:@core/unknownutil@3.18.1";
7+
```typescript,title=denops/denops-helloworld/main.ts
8+
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
9+
import { assert, is } from "jsr:@core/unknownutil@^4.3.0";
1010

1111
export const main: Entrypoint = (denops) => {
1212
denops.dispatcher = {
@@ -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

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ denops-helloworld
3131

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

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

3737
export const main: Entrypoint = (denops) => {
3838
console.log("Hello, Denops from TypeScript!");

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

+3-3
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

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ 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
11-
import type { Entrypoint } from "jsr:@denops/[email protected]";
12-
import * as fn from "jsr:@denops/[email protected]/function";
13-
import { Maze } from "npm:@thewizardbear/[email protected]";
10+
```typescript,title=denops/denops-helloworld/main.ts
11+
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
12+
import * as fn from "jsr:@denops/std@^7.0.0/function";
13+
import { Maze } from "npm:@thewizardbear/maze_generator@^0.4.0";
1414

1515
export const main: Entrypoint = (denops) => {
1616
denops.dispatcher = {

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

+8-8
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,13 +32,13 @@ 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
36-
import type { Entrypoint } from "jsr:@denops/[email protected]";
37-
import { batch, collect } from "jsr:@denops/[email protected]/batch";
38-
import * as fn from "jsr:@denops/[email protected]/function";
39-
import * as op from "jsr:@denops/[email protected]/option";
40-
import { Maze } from "npm:@thewizardbear/[email protected]";
41-
import { assert, is } from "jsr:@core/unknownutil@3.18.1";
35+
```typescript,title=denops/denops-maze/main.ts
36+
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
37+
import { batch, collect } from "jsr:@denops/std@^7.0.0/batch";
38+
import * as fn from "jsr:@denops/std@^7.0.0/function";
39+
import * as op from "jsr:@denops/std@^7.0.0/option";
40+
import { Maze } from "npm:@thewizardbear/maze_generator@^0.4.0";
41+
import { assert, is } from "jsr:@core/unknownutil@^4.3.0";
4242

4343
export const main: Entrypoint = (denops) => {
4444
denops.dispatcher = {

src/tutorial/maze/outputting-content-to-buffer.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ the maze to a buffer so that users can yank the maze with daily Vim operations!
66

77
Let's modify the code to make the generated maze output to a buffer.
88

9-
```ts:denops/denops-maze/main.ts
10-
import type { Entrypoint } from "jsr:@denops/[email protected]";
11-
import { Maze } from "npm:@thewizardbear/[email protected]";
9+
```typescript,title=denops/denops-maze/main.ts
10+
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
11+
import { Maze } from "npm:@thewizardbear/maze_generator@^0.4.0";
1212

1313
export const main: Entrypoint = (denops) => {
1414
denops.dispatcher = {

src/tutorial/maze/properly-configured-the-buffer.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ configure the buffer options to make the buffer non-modifiable and remove the
66
buffer after closure. Open the `main.ts` file and modify the `maze` method as
77
follows:
88

9-
```typescript:denops/denops-maze/main.ts
10-
import type { Entrypoint } from "jsr:@denops/[email protected]";
11-
import * as buffer from "jsr:@denops/[email protected]/buffer";
12-
import * as fn from "jsr:@denops/[email protected]/function";
13-
import * as op from "jsr:@denops/[email protected]/option";
14-
import { Maze } from "npm:@thewizardbear/[email protected]";
9+
```typescript,title=denops/denops-maze/main.ts
10+
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
11+
import * as buffer from "jsr:@denops/std@^7.0.0/buffer";
12+
import * as fn from "jsr:@denops/std@^7.0.0/function";
13+
import * as op from "jsr:@denops/std@^7.0.0/option";
14+
import { Maze } from "npm:@thewizardbear/maze_generator@^0.4.0";
1515

1616
export const main: Entrypoint = (denops) => {
1717
denops.dispatcher = {

src/tutorial/maze/properly-create-a-virtual-buffer.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ In this section, we will use the `buffer` module of `@denops/std` to create a
99
proper virtual buffer that concretizes the buffer content. Let's modify the
1010
`main.ts` file as follows:
1111

12-
```typescript:denops/denops-maze/main.ts
13-
import type { Entrypoint } from "jsr:@denops/[email protected]";
14-
import * as buffer from "jsr:@denops/[email protected]/buffer";
15-
import * as fn from "jsr:@denops/[email protected]/function";
16-
import { Maze } from "npm:@thewizardbear/[email protected]";
12+
```typescript,title=denops/denops-maze/main.ts
13+
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
14+
import * as buffer from "jsr:@denops/std@^7.0.0/buffer";
15+
import * as fn from "jsr:@denops/std@^7.0.0/function";
16+
import { Maze } from "npm:@thewizardbear/maze_generator@^0.4.0";
1717

1818
export const main: Entrypoint = (denops) => {
1919
denops.dispatcher = {

src/tutorial/maze/reduce-the-number-of-rpc-calls.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ significantly influences the plugin's performance. In this section, we aim to
55
enhance performance by reducing the number of RPC calls using the `batch` module
66
from `@denops/std`. Let's revise the `main.ts` file as follows:
77

8-
```typescript:denops/denops-maze/main.ts
9-
import type { Entrypoint } from "jsr:@denops/[email protected]";
10-
import { batch, collect } from "jsr:@denops/[email protected]/batch";
11-
import * as buffer from "jsr:@denops/[email protected]/buffer";
12-
import * as fn from "jsr:@denops/[email protected]/function";
13-
import * as op from "jsr:@denops/[email protected]/option";
14-
import { Maze } from "npm:@thewizardbear/[email protected]";
8+
```typescript,title=denops/denops-maze/main.ts
9+
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
10+
import { batch, collect } from "jsr:@denops/std@^7.0.0/batch";
11+
import * as buffer from "jsr:@denops/std@^7.0.0/buffer";
12+
import * as fn from "jsr:@denops/std@^7.0.0/function";
13+
import * as op from "jsr:@denops/std@^7.0.0/option";
14+
import { Maze } from "npm:@thewizardbear/maze_generator@^0.4.0";
1515

1616
export const main: Entrypoint = (denops) => {
1717
denops.dispatcher = {

src/tutorial/maze/utilizing-third-party-library.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ directory tree will look like this:
2828

2929
The content of the `denops/denops-maze/main.ts` file will be:
3030

31-
```typescript:denops/denops-maze/main.ts
32-
import type { Entrypoint } from "jsr:@denops/[email protected]";
33-
import { Maze } from "npm:@thewizardbear/[email protected]";
31+
```typescript,title=denops/denops-maze/main.ts
32+
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
33+
import { Maze } from "npm:@thewizardbear/maze_generator@^0.4.0";
3434

3535
export const main: Entrypoint = (denops) => {
3636
denops.dispatcher = {
@@ -45,7 +45,7 @@ export const main: Entrypoint = (denops) => {
4545

4646
The content of the `plugin/denops-maze.vim` file will be:
4747

48-
```vim:plugin/denops-maze.vim
48+
```vim,title=plugin/denops-maze.vim
4949
if exists('g:loaded_denops_maze')
5050
finish
5151
endif
@@ -70,7 +70,7 @@ augroup END
7070
> `denops#plugin#wait_async()` in the function to wait for plugin load, like
7171
> this:
7272
>
73-
> ```vim
73+
> ```vim,title=plugin/denops-maze.vim
7474
> if exists('g:loaded_denops_maze')
7575
> finish
7676
> endif

0 commit comments

Comments
 (0)