|
@@ -1,15 +1,32 @@
|
|
|
import plantuml from '@akebifiky/remark-simple-plantuml';
|
|
import plantuml from '@akebifiky/remark-simple-plantuml';
|
|
|
|
|
+import type { Code } from 'mdast';
|
|
|
import type { Plugin } from 'unified';
|
|
import type { Plugin } from 'unified';
|
|
|
|
|
+import { visit } from 'unist-util-visit';
|
|
|
import urljoin from 'url-join';
|
|
import urljoin from 'url-join';
|
|
|
|
|
|
|
|
type PlantUMLPluginParams = {
|
|
type PlantUMLPluginParams = {
|
|
|
plantumlUri: string,
|
|
plantumlUri: string,
|
|
|
|
|
+ isDarkMode?: boolean,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const remarkPlugin: Plugin<[PlantUMLPluginParams]> = (options) => {
|
|
export const remarkPlugin: Plugin<[PlantUMLPluginParams]> = (options) => {
|
|
|
- const plantumlUri = options.plantumlUri;
|
|
|
|
|
|
|
+ const { plantumlUri, isDarkMode } = options;
|
|
|
|
|
|
|
|
const baseUrl = urljoin(plantumlUri, '/svg');
|
|
const baseUrl = urljoin(plantumlUri, '/svg');
|
|
|
|
|
+ const simplePlantumlPlugin = plantuml.bind(this)({ baseUrl });
|
|
|
|
|
|
|
|
- return plantuml.bind(this)({ baseUrl });
|
|
|
|
|
|
|
+ return (tree, file) => {
|
|
|
|
|
+ visit(tree, 'code', (node: Code) => {
|
|
|
|
|
+ if (node.lang === 'plantuml') {
|
|
|
|
|
+ const themeLine = isDarkMode
|
|
|
|
|
+ ? '!theme reddress-darkblue'
|
|
|
|
|
+ : '!theme carbon-gray';
|
|
|
|
|
+
|
|
|
|
|
+ // node.value = `${themeLine}\n${node.value}`;
|
|
|
|
|
+ node.value = `${''}\n${node.value}`;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ simplePlantumlPlugin(tree, file);
|
|
|
|
|
+ };
|
|
|
};
|
|
};
|