Просмотр исходного кода

add remark-drawio-plugin package

Yuki Takei 3 лет назад
Родитель
Сommit
6bd190c423

+ 1 - 0
packages/remark-drawio-plugin/.eslintignore

@@ -0,0 +1 @@
+/dist/**

+ 18 - 0
packages/remark-drawio-plugin/.eslintrc.js

@@ -0,0 +1,18 @@
+module.exports = {
+  extends: [
+    'weseek/react',
+    'weseek/typescript',
+  ],
+  env: {
+  },
+  globals: {
+  },
+  settings: {
+    // resolve path aliases by eslint-import-resolver-typescript
+    'import/resolver': {
+      typescript: {},
+    },
+  },
+  rules: {
+  },
+};

+ 1 - 0
packages/remark-drawio-plugin/.gitignore

@@ -0,0 +1 @@
+/dist

+ 6 - 0
packages/remark-drawio-plugin/README.md

@@ -0,0 +1,6 @@
+# remark-drawio-plugin
+
+[GROWI][growi] remark plugin to draw diagrams with [draw.io (diagrams.net)](https://www.diagrams.net/)
+
+Usage
+------

+ 33 - 0
packages/remark-drawio-plugin/package.json

@@ -0,0 +1,33 @@
+{
+  "name": "@growi/remark-drawio-plugin",
+  "version": "6.0.0-RC.8",
+  "description": "remark plugin to draw diagrams with draw.io (diagrams.net)",
+  "license": "MIT",
+  "keywords": [
+    "unified",
+    "remark",
+    "remark-plugin",
+    "plugin",
+    "mdast",
+    "markdown"
+  ],
+  "main": "dist/index.js",
+  "typings": "dist/index.d.ts",
+  "scripts": {
+    "build": "yarn tsc && tsc-alias -p tsconfig.build.json",
+    "tsc": "tsc -p tsconfig.build.json",
+    "tsc:w": "yarn tsc -w",
+    "clean": "npx -y shx rm -rf dist",
+    "lint:js": "eslint **/*.{js,jsx,ts,tsx}",
+    "lint:styles": "stylelint --allow-empty-input src/**/*.scss src/**/*.css",
+    "lint": "run-p lint:*",
+    "test": ""
+  },
+  "dependencies": {
+  },
+  "devDependencies": {
+    "eslint-plugin-regex": "^1.8.0",
+    "react": "^18.2.0",
+    "react-dom": "^18.2.0"
+  }
+}

+ 2 - 0
packages/remark-drawio-plugin/src/index.ts

@@ -0,0 +1,2 @@
+// export * from './components';
+export * from './services/renderer/remark-drawio-plugin';

+ 46 - 0
packages/remark-drawio-plugin/src/services/renderer/remark-drawio-plugin.ts

@@ -0,0 +1,46 @@
+import { Schema as SanitizeOption } from 'hast-util-sanitize';
+import { Plugin } from 'unified';
+import { Node } from 'unist';
+import { visit } from 'unist-util-visit';
+
+const SUPPORTED_ATTRIBUTES = ['drawioUri'];
+
+type Lang = 'drawio';
+
+function isDrawioBlock(lang: unknown): lang is Lang {
+  return /^drawio$/.test(lang as string);
+}
+
+function rewriteNode(node: Node, lang: Lang) {
+  const contents = node.value as string;
+
+  // TODO: add node
+  console.log('contents', contents);
+}
+
+export const remarkPlugin: Plugin = function() {
+  return (tree) => {
+    visit(tree, (node) => {
+      if (node.type === 'code') {
+        if (isDrawioBlock(node.lang)) {
+          rewriteNode(node, node.lang);
+        }
+      }
+    });
+  };
+};
+
+export type DrawioRehypePluginParams = {
+  drawioUri: string,
+}
+
+export const rehypePlugin: Plugin<[DrawioRehypePluginParams]> = (options) => {
+  // TODO: impl
+};
+
+export const sanitizeOption: SanitizeOption = {
+  tagNames: ['drawio'],
+  attributes: {
+    lsx: SUPPORTED_ATTRIBUTES,
+  },
+};

+ 12 - 0
packages/remark-drawio-plugin/tsconfig.base.json

@@ -0,0 +1,12 @@
+{
+  "extends": "../../tsconfig.base.json",
+  "compilerOptions": {
+    "jsx": "preserve",
+  },
+  "include": [
+    "src"
+  ],
+  "exclude": [
+    "test"
+  ]
+}

+ 16 - 0
packages/remark-drawio-plugin/tsconfig.build.json

@@ -0,0 +1,16 @@
+{
+  "extends": "./tsconfig.base.json",
+  "compilerOptions": {
+    "rootDir": "./src",
+    "outDir": "dist",
+    "declaration": true,
+    "noResolve": false,
+    "preserveConstEnums": true,
+    "sourceMap": false,
+    "noEmit": false,
+
+    "baseUrl": ".",
+    "paths": {
+    }
+  }
+}

+ 10 - 0
packages/remark-drawio-plugin/tsconfig.json

@@ -0,0 +1,10 @@
+{
+  "extends": "./tsconfig.base.json",
+  "compilerOptions": {
+    "baseUrl": ".",
+    "paths": {
+      "~/*": ["./src/*"],
+      "@growi/*": ["../*/src"]
+    }
+  }
+}