[a-zA-Z0-9_]*)>$/;
+
+module.exports = function() {
+ const snippets = {};
+
+ function processFile(filePath, relativeFilePath) {
+ const content = fs.readFileSync(filePath, 'utf8');
+ const lines = content.split('\n');
+ const blocks = {};
+
+ lines.forEach((line, index) => {
+ const match = line.match(codeBockRegex);
+ if (match) {
+ const { closing, tag } = match.groups;
+ if (closing) {
+ const code = blocks[tag];
+ if (!code) {
+ throw new Error(`Code block not closed: ${tag} (${relativeFilePath}:${index + 1})`);
+ }
+ blocks[tag] = null;
+ snippets[tag] = {
+ file: relativeFilePath,
+ content: code.join('\n')
+ };
+ return;
+ }
+
+ blocks[tag] = [];
+ } else {
+ for (const tag in blocks) {
+ const code = blocks[tag];
+ if (!code) continue;
+ code.push(line);
+ }
+ }
+ });
+
+ // Handle any unclosed blocks
+ for (const tag in blocks) {
+ const code = blocks[tag];
+ if (!code) continue;
+ snippets[tag] = {
+ file: relativeFilePath,
+ content: code.join('\n')
+ };
+ }
+ }
+
+ function traverseDirectory(dir, baseDir) {
+ const files = fs.readdirSync(dir);
+ files.forEach(file => {
+ const filePath = path.join(dir, file);
+ const relativeFilePath = path.relative(baseDir, filePath);
+ const stat = fs.statSync(filePath);
+ if (stat.isDirectory()) {
+ traverseDirectory(filePath, baseDir);
+ } else if (path.extname(filePath) === '.kt') {
+ processFile(filePath, relativeFilePath);
+ }
+ });
+ }
+
+ // Assuming the adapters directory is at the root of your project
+ const adaptersDir = path.resolve(__dirname, '../../../adapters/_DocsAdapter');
+ traverseDirectory(adaptersDir, adaptersDir);
+
+ // console.log(`Exporting ${Object.keys(snippets).length} snippets: ${Object.keys(snippets)}`);
+
+ this.cacheable(false);
+
+ return `export default ${JSON.stringify(snippets, null, 2)}`;
+};
diff --git a/documentation/plugins/code-snippets/index.js b/documentation/plugins/code-snippets/index.js
new file mode 100644
index 0000000000..4e56d94bb4
--- /dev/null
+++ b/documentation/plugins/code-snippets/index.js
@@ -0,0 +1,24 @@
+const path = require('path');
+const crypto = require('crypto');
+
+export default function codeSnippets() {
+ return {
+ name: 'code-snippets',
+ configureWebpack(_config, isServer) {
+ return {
+ module: {
+ rules: [
+ {
+ test: /snippets\.ts$/,
+ use: [
+ {
+ loader: path.resolve(__dirname, 'codeSnippets.js'),
+ },
+ ],
+ },
+ ],
+ },
+ };
+ },
+ };
+}
diff --git a/documentation/src/components/CodeSnippet/index.tsx b/documentation/src/components/CodeSnippet/index.tsx
new file mode 100644
index 0000000000..003b006a1f
--- /dev/null
+++ b/documentation/src/components/CodeSnippet/index.tsx
@@ -0,0 +1,23 @@
+import codeSnippets from "./snippets";
+import CodeBlock from '@theme/CodeBlock';
+
+interface CodeSnippetProps {
+ tag: string;
+}
+
+export default function CodeSnippet({ tag }: CodeSnippetProps) {
+ const codeSnippet = codeSnippets[tag];
+ if (codeSnippet == null) {
+ return Code snippet not found: {tag}
;
+ }
+ const { file, content } = codeSnippet;
+ if (file == null || content == null) {
+ return Code snippet not found: {tag} ({codeSnippet})
;
+ }
+ const fileName = file.split('/').pop();
+ return (
+
+ {content}
+
+ );
+}
diff --git a/documentation/src/components/CodeSnippet/snippets.ts b/documentation/src/components/CodeSnippet/snippets.ts
new file mode 100644
index 0000000000..b4d2f942b4
--- /dev/null
+++ b/documentation/src/components/CodeSnippet/snippets.ts
@@ -0,0 +1,2 @@
+// This file will be replaced with the processed snippets
+export default {};
diff --git a/documentation/src/css/custom.css b/documentation/src/css/custom.css
index a63b9787b8..a3717768e4 100644
--- a/documentation/src/css/custom.css
+++ b/documentation/src/css/custom.css
@@ -108,23 +108,71 @@
border-radius: 0.5rem;
}
+code {
+ border-collapse: collapse;
+}
+
code span {
margin: 0;
}
+/* Line Numbers */
+.token-line > span:first-child:not(.token) {
+ background-color: transparent;
+}
+
+.token-line > span:nth-child(2):not(.token) {
+ display: table-cell;
+}
+
.highlight-red {
background-color: #ff000020; /* Light red background */
- border-left: 3px solid #ff000080; /* Darker red border */
display: block;
margin: 0 calc(-1 * var(--ifm-pre-padding));
padding: 0 var(--ifm-pre-padding);
+ border-left: 3px solid #ff000080;
+}
+
+[data-theme='dark'] .highlight-red {
+ background-color: #e52e4d20;
+ border-left: 3px solid #e52e4d80;
}
.highlight-green {
background-color: #00ff0020; /* Light green background */
- border-left: 3px solid #00ff0080; /* Darker green border */
display: block;
margin: 0 calc(-1 * var(--ifm-pre-padding));
padding: 0 var(--ifm-pre-padding);
+ border-left: 3px solid #00ff0080;
+}
+
+[data-theme='dark'] .highlight-green {
+ background-color: #00ff000d;
+ border-left: 3px solid #00ff0070;
}
+.highlight-blue {
+ background-color: #0000ff20; /* Light blue background */
+ display: block;
+ margin: 0 calc(-1 * var(--ifm-pre-padding));
+ padding: 0 var(--ifm-pre-padding);
+ border-left: 3px solid #0000ff80;
+}
+
+[data-theme='dark'] .highlight-blue {
+ background-color: #396ce320;
+ border-left: 3px solid #396ce380;
+}
+
+.highlight-line {
+ background-color: #0000000d;
+ display: block;
+ margin: 0 calc(-1 * var(--ifm-pre-padding));
+ padding: 0 var(--ifm-pre-padding);
+ border-left: 2px solid #00000080;
+}
+
+[data-theme='dark'] .highlight-line {
+ background-color: #ffffff0d;
+ border-left: 2px solid #ffffff80;
+}
diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts
index 12b43eb70e..7ca0a6bfd8 100644
--- a/plugin/build.gradle.kts
+++ b/plugin/build.gradle.kts
@@ -28,7 +28,6 @@ repositories {
// Floodgate
maven("https://repo.opencollab.dev/maven-snapshots/")
// PacketEvents, CommandAPI
- maven("https://repo.codemc.io/repository/maven-snapshots/")
maven("https://repo.codemc.io/repository/maven-releases/")
// PlaceholderAPI
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
@@ -97,12 +96,6 @@ kotlin {
jvmToolchain(languageJavaVersion)
}
-tasks.withType().configureEach {
- kotlinOptions {
- jvmTarget = "$languageJavaVersion"
- }
-}
-
tasks.test {
useJUnitPlatform()
}