Skip to content

Add codeblock title #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions .github/workflows/mdbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,22 @@ jobs:
MDBOOK_VERSION: 0.4.36
steps:
- uses: actions/checkout@v4
- name: Install mdBook
run: |
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -y | sh
rustup update
cargo install --force --version ${MDBOOK_VERSION} mdbook
cargo install --force mdbook-alerts

- name: Install mdbook and cargo-binstall binaries
uses: taiki-e/install-action@v2
with:
tool: mdbook,cargo-binstall

- name: Install mdbook extensions
run: cargo binstall -y mdbook-alerts

- name: Setup Pages
id: pages
uses: actions/configure-pages@v4

- name: Build with mdBook
run: mdbook build

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
Expand Down
19 changes: 13 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/cache@v4
with:
path: |
Expand All @@ -26,18 +27,24 @@ jobs:
target/
.tools/
key: ${{ runner.os }}-cargo

- uses: denoland/setup-deno@v1.1.4
with:
deno-version: ${{ env.DENO_VERSION }}
- name: Install mdBook
run: |
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -y | sh
rustup update
cargo install --force --version ${MDBOOK_VERSION} mdbook
cargo install --force mdbook-alerts

- name: Install mdbook and cargo-binstall binaries
uses: taiki-e/install-action@v2
with:
tool: mdbook,cargo-binstall

- name: Install mdbook extensions
run: cargo binstall -y mdbook-alerts

- name: Build with mdBook
run: mdbook build

- name: Format
run: deno fmt --check

- name: Misspell
uses: reviewdog/action-misspell@v1.15.0
8 changes: 8 additions & 0 deletions assets/codeblock-title.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.codeblock-title {
display: block;
margin: 0;
padding: 0.5em 1em;
font-size: 0.9em;
color: color-mix(in srgb, var(--fg), #777 50%);
background-color: color-mix(in srgb, var(--bg), #777 20%);
}
15 changes: 15 additions & 0 deletions assets/codeblock-title.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
document.addEventListener("DOMContentLoaded", () => {
const codeblocks = document.querySelectorAll("pre code");
codeblocks.forEach((codeblock) => {
const found = [...codeblock.classList.values()].find((v) =>
v.startsWith("title=")
);
if (found) {
const title = found.replace(/^title=/, "");
const titleElement = document.createElement("header");
titleElement.classList.add("codeblock-title");
titleElement.textContent = title;
codeblock.parentNode.prepend(titleElement, codeblock);
}
});
});
2 changes: 2 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ title = "Denops Documentation"

[output.html]
default-theme = "coal"
additional-js = ["assets/codeblock-title.js"]
additional-css = ["assets/codeblock-title.css"]

[preprocessor.alerts]
8 changes: 4 additions & 4 deletions src/getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ $HOME

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

```typescript:denops/denops-getting-started/main.ts
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
```typescript,title=denops/denops-getting-started/main.ts
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";

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

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

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

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

Expand Down
6 changes: 3 additions & 3 deletions src/getting-started/explanation.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ easily call.
In the Getting Started, we wrote the following code in the `main.ts` file:

```typescript
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";

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

```typescript
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
```

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

```typescript
import * as fn from "jsr:@denops/std@7.0.0/function";
import * as fn from "jsr:@denops/std@^7.0.0/function";

// Bad (result1 is `unknown`)
const result1 = await denops.call("expand", "%");
Expand Down
6 changes: 3 additions & 3 deletions src/tutorial/helloworld/adding-an-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ will enhance the plugin by adding an API.
Open `denops/denops-helloworld/main.ts` and rewrite the content with the
following code:

```typescript:denops/denops-helloworld/main.ts
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import { assert, is } from "jsr:@core/unknownutil@3.18.1";
```typescript,title=denops/denops-helloworld/main.ts
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
import { assert, is } from "jsr:@core/unknownutil@^4.3.0";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand Down
8 changes: 4 additions & 4 deletions src/tutorial/helloworld/calling-vim-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ If you want to use a Vim feature from your Denops plugin, you can call it via
the `denops` instance passed to the plugin's `main` function. You can rewrite
`main.ts` as follows to register the `DenopsHello` as a Vim command:

```ts:denops/denops-helloworld/main.ts
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import { assert, is } from "jsr:@core/unknownutil@3.18.1";
```typescript,title=denops/denops-helloworld/main.ts
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
import { assert, is } from "jsr:@core/unknownutil@^4.3.0";

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

```vim:plugin/denops-helloworld.vim
```vim,title=plugin/denops-helloworld.vim
if exists('g:loaded_denops_helloworld')
finish
endif
Expand Down
4 changes: 2 additions & 2 deletions src/tutorial/helloworld/creating-a-minimal-denops-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ denops-helloworld

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

```typescript:denops/denops-helloworld/main.ts
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
```typescript,title=denops/denops-helloworld/main.ts
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";

export const main: Entrypoint = (denops) => {
console.log("Hello, Denops from TypeScript!");
Expand Down
6 changes: 3 additions & 3 deletions src/tutorial/helloworld/creating-a-minimal-vim-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ denops-helloworld

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

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

```vim
```vim,title=~/.vimrc
set runtimepath+=~/denops-helloworld
```

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

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

Expand Down
8 changes: 4 additions & 4 deletions src/tutorial/maze/adjusting-maze-size-to-fit-the-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ to have a maze that fits the current window size.
Let's modify the plugin to ensure the generated maze fits the current window
size.

```typescript:denops/denops-helloworld/main.ts
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import * as fn from "jsr:@denops/std@7.0.0/function";
import { Maze } from "npm:@thewizardbear/maze_generator@0.4.0";
```typescript,title=denops/denops-helloworld/main.ts
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
import * as fn from "jsr:@denops/std@^7.0.0/function";
import { Maze } from "npm:@thewizardbear/maze_generator@^0.4.0";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand Down
16 changes: 8 additions & 8 deletions src/tutorial/maze/creating-applicative-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ the maze plugin that will satisfy your crazy addictive maze solver friend.
First, modify `plugin/denops-maze.vim` to accept the `Maze` command with an
optional argument.

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

```ts:denops/denops-maze/main.ts
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import { batch, collect } from "jsr:@denops/std@7.0.0/batch";
import * as fn from "jsr:@denops/std@7.0.0/function";
import * as op from "jsr:@denops/std@7.0.0/option";
import { Maze } from "npm:@thewizardbear/maze_generator@0.4.0";
import { assert, is } from "jsr:@core/unknownutil@3.18.1";
```typescript,title=denops/denops-maze/main.ts
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
import { batch, collect } from "jsr:@denops/std@^7.0.0/batch";
import * as fn from "jsr:@denops/std@^7.0.0/function";
import * as op from "jsr:@denops/std@^7.0.0/option";
import { Maze } from "npm:@thewizardbear/maze_generator@^0.4.0";
import { assert, is } from "jsr:@core/unknownutil@^4.3.0";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand Down
6 changes: 3 additions & 3 deletions src/tutorial/maze/outputting-content-to-buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ the maze to a buffer so that users can yank the maze with daily Vim operations!

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

```ts:denops/denops-maze/main.ts
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import { Maze } from "npm:@thewizardbear/maze_generator@0.4.0";
```typescript,title=denops/denops-maze/main.ts
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
import { Maze } from "npm:@thewizardbear/maze_generator@^0.4.0";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand Down
12 changes: 6 additions & 6 deletions src/tutorial/maze/properly-configured-the-buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ configure the buffer options to make the buffer non-modifiable and remove the
buffer after closure. Open the `main.ts` file and modify the `maze` method as
follows:

```typescript:denops/denops-maze/main.ts
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import * as buffer from "jsr:@denops/std@7.0.0/buffer";
import * as fn from "jsr:@denops/std@7.0.0/function";
import * as op from "jsr:@denops/std@7.0.0/option";
import { Maze } from "npm:@thewizardbear/maze_generator@0.4.0";
```typescript,title=denops/denops-maze/main.ts
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
import * as buffer from "jsr:@denops/std@^7.0.0/buffer";
import * as fn from "jsr:@denops/std@^7.0.0/function";
import * as op from "jsr:@denops/std@^7.0.0/option";
import { Maze } from "npm:@thewizardbear/maze_generator@^0.4.0";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand Down
10 changes: 5 additions & 5 deletions src/tutorial/maze/properly-create-a-virtual-buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ In this section, we will use the `buffer` module of `@denops/std` to create a
proper virtual buffer that concretizes the buffer content. Let's modify the
`main.ts` file as follows:

```typescript:denops/denops-maze/main.ts
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import * as buffer from "jsr:@denops/std@7.0.0/buffer";
import * as fn from "jsr:@denops/std@7.0.0/function";
import { Maze } from "npm:@thewizardbear/maze_generator@0.4.0";
```typescript,title=denops/denops-maze/main.ts
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
import * as buffer from "jsr:@denops/std@^7.0.0/buffer";
import * as fn from "jsr:@denops/std@^7.0.0/function";
import { Maze } from "npm:@thewizardbear/maze_generator@^0.4.0";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand Down
14 changes: 7 additions & 7 deletions src/tutorial/maze/reduce-the-number-of-rpc-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ significantly influences the plugin's performance. In this section, we aim to
enhance performance by reducing the number of RPC calls using the `batch` module
from `@denops/std`. Let's revise the `main.ts` file as follows:

```typescript:denops/denops-maze/main.ts
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import { batch, collect } from "jsr:@denops/std@7.0.0/batch";
import * as buffer from "jsr:@denops/std@7.0.0/buffer";
import * as fn from "jsr:@denops/std@7.0.0/function";
import * as op from "jsr:@denops/std@7.0.0/option";
import { Maze } from "npm:@thewizardbear/maze_generator@0.4.0";
```typescript,title=denops/denops-maze/main.ts
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
import { batch, collect } from "jsr:@denops/std@^7.0.0/batch";
import * as buffer from "jsr:@denops/std@^7.0.0/buffer";
import * as fn from "jsr:@denops/std@^7.0.0/function";
import * as op from "jsr:@denops/std@^7.0.0/option";
import { Maze } from "npm:@thewizardbear/maze_generator@^0.4.0";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand Down
10 changes: 5 additions & 5 deletions src/tutorial/maze/utilizing-third-party-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ directory tree will look like this:

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

```typescript:denops/denops-maze/main.ts
import type { Entrypoint } from "jsr:@denops/std@7.0.0";
import { Maze } from "npm:@thewizardbear/maze_generator@0.4.0";
```typescript,title=denops/denops-maze/main.ts
import type { Entrypoint } from "jsr:@denops/std@^7.0.0";
import { Maze } from "npm:@thewizardbear/maze_generator@^0.4.0";

export const main: Entrypoint = (denops) => {
denops.dispatcher = {
Expand All @@ -45,7 +45,7 @@ export const main: Entrypoint = (denops) => {

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

```vim:plugin/denops-maze.vim
```vim,title=plugin/denops-maze.vim
if exists('g:loaded_denops_maze')
finish
endif
Expand All @@ -70,7 +70,7 @@ augroup END
> `denops#plugin#wait_async()` in the function to wait for plugin load, like
> this:
>
> ```vim
> ```vim,title=plugin/denops-maze.vim
> if exists('g:loaded_denops_maze')
> finish
> endif
Expand Down