Skip to content

Commit 7b543b0

Browse files
committed
feat: anchor for Example block
1 parent 3be8b4b commit 7b543b0

File tree

8 files changed

+35
-6
lines changed

8 files changed

+35
-6
lines changed

docs/.vitepress/config.mts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {VitePressI18nOptions} from 'vitepress-i18n/dist/types';
66
import {VitePressSidebarOptions, withSidebar} from "vitepress-sidebar";
77
import {tabsPlugin} from "./theme/tabs/codesMarkdownPlugin";
88
import fs from "fs";
9+
import {exampleAutoAnchorPreprocessor} from "./theme/anchor/exampleAutoAnchorPreprocessor";
910

1011
const defaultLocale: string = 'en';
1112
const supportLocales: string[] = [defaultLocale, 'zhHans'];
@@ -92,7 +93,8 @@ const vitepressOptions: UserConfig = {
9293
})
9394
},
9495
config: (md) => {
95-
tabsPlugin(md)
96+
tabsPlugin(md);
97+
exampleAutoAnchorPreprocessor(md);
9698
}
9799
}
98100
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import MarkdownIt from "markdown-it";
2+
import slugify from "@sindresorhus/slugify";
3+
4+
export const exampleAutoAnchorPreprocessor = (md: MarkdownIt) => {
5+
md.core.ruler.before('normalize', 'example-auto-anchor', (state) => {
6+
const lines = state.src.split("\n");
7+
const processedLines = lines.map((line) => {
8+
if (line.startsWith(":::") && (line.includes(":::tip Example") || line.includes("::: tip Example"))) {
9+
const title = line.split(/tip (.+)/)[1]
10+
return `
11+
<div style="height: 0; color: rgba(0,0,0,0%);position: relative;top: 50px">
12+
<h3 id="${slugify(title.replace(" – ", ""))}">${title}</h3>
13+
</div>
14+
15+
${line}
16+
`;
17+
} else {
18+
return line;
19+
}
20+
});
21+
state.src = processedLines.join("\n");
22+
});
23+
}
24+

docs/en/create-commands/arguments/types/chat/spigot-chat-arguments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ This is converted into Spigot's `BaseComponent[]`, which can be used for the fol
7474
sender.spigot().sendMessage(BaseComponent[]);
7575
```
7676

77-
::::tip Example - Book made from raw JSON
77+
::::tip Example Book made from raw JSON
7878

7979
Say we want to generate a book using raw JSON. For this example, we'll use the following JSON (generated from [minecraftjson.com](https://minecraftjson.com/)) to generate our book:
8080

docs/en/user-setup/command-conversion/conversion.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ If you're uncertain if your configuration is valid (or you're getting weird erro
4949

5050
To convert all the commands that a plugin has, add the name of the plugin, followed by a `~` character to the list of plugins to convert in the `config.yml` file.
5151

52-
::: tip **Example – Converting all commands from EssentialsX**
52+
::: tip Example – Converting all commands from EssentialsX
5353

5454
For example, if you wanted to convert all commands that [EssentialsX](https://www.spigotmc.org/resources/essentialsx.9089/) has, you can use the following `config.yml`:
5555

docs/en/user-setup/command-conversion/single-command.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The CommandAPI has two ways of doing this:
1717

1818
To convert a single command, you need to first populate the `config.yml` with the name of the plugin and commands to be converted. To illustrate this, we'll use an example:
1919

20-
::: tip Example - Converting plugin commands
20+
::::tip Example Converting plugin commands
2121

2222
Say we're using [EssentialsX](https://www.spigotmc.org/resources/essentialsx.9089/) on our server, and we want to be able to use `/afk` and `/hat` in command blocks. This would allow us to use (for example) the following commands in command blocks:
2323

@@ -67,6 +67,8 @@ commands:
6767

6868
:::
6969

70+
::::
71+
7072
## Arbitrary command conversion
7173

7274
Some commands that are registered by plugins aren’t present in the plugin's `plugin.yml` file. Due to this, the CommandAPI can’t link a command to its respective plugin for command conversion. To deal with this, the CommandAPI can link arbitrary commands via the `other-commands-to-convert` option in the CommandAPI's `config.yml` file.

docs/en/user-setup/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ Controls the list of plugins to process for command conversion. See [Command con
255255
plugins-to-convert: []
256256
```
257257

258-
**Example values**
258+
**Example value**
259259

260260
```yml
261261
plugins-to-convert:

docs/en/user-setup/install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ This can be mitigated by running a [Paper](https://papermc.io/) Minecraft server
6565
```
6666

6767

68-
::: tip **Example - Running the CommandAPI using Java 17 and Minecraft 1.13.2**
68+
::: tip Example - Running the CommandAPI using Java 17 and Minecraft 1.13.2
6969

7070
For example, to use the CommandAPI with Java 17 and Minecraft 1.13.2:
7171

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"devDependencies": {
1313
"@nolebase/vitepress-plugin-enhanced-readabilities": "^2.10.0",
14+
"@sindresorhus/slugify": "^2.2.1",
1415
"@types/markdown-it": "^14.1.2",
1516
"@types/markdown-it-container": "^2.0.10",
1617
"fs": "^0.0.1-security",

0 commit comments

Comments
 (0)