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

Lines changed: 11 additions & 6 deletions
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

Lines changed: 13 additions & 6 deletions
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/setup-deno@v1.1.4
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/action-misspell@v1.15.0

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: 4 additions & 4 deletions
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/std@7.0.0";
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

Lines changed: 3 additions & 3 deletions
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/std@7.0.0";
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/std@7.0.0";
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/std@7.0.0/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

Lines changed: 3 additions & 3 deletions
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/std@7.0.0";
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

Lines changed: 4 additions & 4 deletions
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/std@7.0.0";
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

Lines changed: 2 additions & 2 deletions
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/std@7.0.0";
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!");

0 commit comments

Comments
 (0)