Skip to content

Commit 1c49231

Browse files
committed
fix: bukkit.yml settings.minimum-api, pass MD config to on-demand renderer
Fixes #586.
1 parent 59cedad commit 1c49231

File tree

9 files changed

+33
-6
lines changed

9 files changed

+33
-6
lines changed

CONTRIBUTING.md

+6
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ loader: io.papermc.testplugin.TestPluginLoader
160160
```
161161
````
162162

163+
For inline code blocks, i.e. `my code block` (`` `my code block` `` in Markdown), you do not need to use a property - replacements are done for all inline code blocks.
164+
165+
```markdown
166+
- `api-version: '\{LATEST_PAPER_RELEASE}'`
167+
```
168+
163169
## Linking to Javadocs
164170

165171
Many Javadoc sites support a `latest` tag, such as javadoc.io or similar, in which case, just use that in a plain Markdown link.

astro.config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,15 @@ export default defineConfig({
394394
pad: 50,
395395
skipGeneration: !prod, // comment out if you have D2 locally and want to use it during dev
396396
}),
397+
// save Markdown renderer configuration to globals for use by the on-demand renderer
398+
{
399+
name: "docs:config-md",
400+
hooks: {
401+
"astro:config:done": ({ config }) => {
402+
globalThis.markdownConfig = config.markdown;
403+
},
404+
},
405+
},
397406
],
398407
build: {
399408
inlineStylesheets: "always",

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"yaml": "^2.7.1"
3131
},
3232
"devDependencies": {
33+
"@types/mdast": "^4.0.4",
3334
"@types/node": "^22.14.1",
3435
"prettier": "3.5.3",
3536
"prettier-plugin-astro": "0.14.1",

pnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config/paper/bukkit.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ settings:
4444
default: none
4545
description: >
4646
Minimum plugin [api-version](/paper/dev/plugin-yml#api-version). A string
47-
containing the server version, ignoring minor part, from 1.13 to 1.20. If
47+
containing the server version, from `1.13` to `\{LATEST_PAPER_RELEASE}`. If
4848
below this, or not specified, the plugin is prevented from loading.
4949
use-map-color-cache:
5050
default: "true"

src/content/docs/paper/dev/getting-started/plugin-yml.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ This will be shown in the plugin info commands.
9494
The version of the Paper API that your plugin is using. This doesn't include the minor version until 1.20.5. From 1.20.5 and onward, a minor version is supported.
9595
Servers with a version lower than the version specified here will refuse to load the plugin.
9696
The valid versions are 1.13 - {LATEST_PAPER_RELEASE}.
97-
- <code>api-version: '{LATEST_PAPER_RELEASE}'</code>
97+
- `api-version: '\{LATEST_PAPER_RELEASE}'`
9898
9999
:::note
100100

src/env.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { AstroMarkdownOptions } from "@astrojs/markdown-remark";
2+
3+
declare global {
4+
// for passing the Markdown configuration to the on-demand renderer
5+
var markdownConfig: AstroMarkdownOptions;
6+
}

src/utils/markdown.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createMarkdownProcessor } from "@astrojs/markdown-remark";
22

3-
const renderer = await createMarkdownProcessor();
3+
const renderer = await createMarkdownProcessor(globalThis.markdownConfig);
44

55
export const render = async (content: string): Promise<string> => {
66
const code = (await renderer.render(content)).code;

src/utils/remark/code_const.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { RemarkPlugin } from "@astrojs/markdown-remark";
2+
import type { Literal } from "mdast";
23
import { visit } from "unist-util-visit";
34

45
// replaces constants in code blocks
@@ -10,12 +11,13 @@ interface Options {
1011

1112
const plugin: RemarkPlugin = ({ constants }: Options) => {
1213
return (tree) => {
13-
visit(tree, "code", (node) => {
14-
if (!node.meta?.includes("replace")) {
14+
visit(tree, ["code", "inlineCode"], (node) => {
15+
if (node.type === "code" && !node.meta?.includes("replace")) {
1516
return;
1617
}
1718

18-
node.value = node.value.replace(/\\\{([^}]+?)}/g, (_, name) => constants[name] ?? name);
19+
const code = node as Literal;
20+
code.value = code.value.replace(/\\\{([^}]+?)}/g, (_, name) => constants[name] ?? name);
1921
});
2022
};
2123
};

0 commit comments

Comments
 (0)