소스 검색

WIP: insert theme line

Yuki Takei 9 달 전
부모
커밋
51b666dbe5
1개의 변경된 파일19개의 추가작업 그리고 2개의 파일을 삭제
  1. 19 2
      apps/app/src/services/renderer/remark-plugins/plantuml.ts

+ 19 - 2
apps/app/src/services/renderer/remark-plugins/plantuml.ts

@@ -1,15 +1,32 @@
 import plantuml from '@akebifiky/remark-simple-plantuml';
+import type { Code } from 'mdast';
 import type { Plugin } from 'unified';
+import { visit } from 'unist-util-visit';
 import urljoin from 'url-join';
 
 type PlantUMLPluginParams = {
   plantumlUri: string,
+  isDarkMode?: boolean,
 }
 
 export const remarkPlugin: Plugin<[PlantUMLPluginParams]> = (options) => {
-  const plantumlUri = options.plantumlUri;
+  const { plantumlUri, isDarkMode } = options;
 
   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);
+  };
 };