Skip to content

Commit f58522e

Browse files
authored
Merge pull request #37 from ZenUml/feat/redesign
feat: introduce ZenUML editor
2 parents b9bec0a + 10bddf5 commit f58522e

File tree

8 files changed

+109
-28
lines changed

8 files changed

+109
-28
lines changed

docs/intro.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ Let's discover **Docusaurus in less than 5 minutes**.
88

99
## Getting Started
1010

11+
```zenuml title=Hello%20World
12+
new A {
13+
b = new B
14+
return b
15+
}
16+
17+
```
18+
1119
Get started by **creating a new site**.
1220

1321
Or **try Docusaurus immediately** with **[docusaurus.new](https://docusaurus.new)**.

docusaurus.config.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { themes as prismThemes } from 'prism-react-renderer';
22
import type { Config } from '@docusaurus/types';
33
import type * as Preset from '@docusaurus/preset-classic';
4+
import ZenUMLPlugin from './src/plugins/zenuml';
45

56
const config: Config = {
67
title: 'ZenUML',
@@ -58,22 +59,17 @@ const config: Config = {
5859
[
5960
'classic',
6061
{
61-
docs: false,
62-
blog: false,
63-
// docs: {
64-
// sidebarPath: './sidebars.ts',
65-
// // Please change this to your repo.
66-
// // Remove this to remove the "edit this page" links.
67-
// editUrl:
68-
// 'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
69-
// },
70-
// blog: {
71-
// showReadingTime: true,
72-
// // Please change this to your repo.
73-
// // Remove this to remove the "edit this page" links.
74-
// editUrl:
75-
// 'https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/',
76-
// },
62+
// remove false to enable docs
63+
docs: false && {
64+
sidebarPath: './sidebars.ts',
65+
editUrl: 'https://github.com/ZenUml/docs',
66+
remarkPlugins: [ZenUMLPlugin],
67+
},
68+
// remove false to enable blog
69+
blog: false && {
70+
showReadingTime: true,
71+
editUrl: 'https://github.com/ZenUml/docs',
72+
},
7773
theme: {
7874
customCss: './src/css/custom.css',
7975
},
@@ -176,7 +172,7 @@ const config: Config = {
176172
// },
177173
{
178174
label: 'GitHub',
179-
href: 'https://github.com/facebook/docusaurus',
175+
href: 'https://github.com/ZenUml',
180176
},
181177
{
182178
label: 'EULA',

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"eslint-config-prettier": "^9.0.0",
3232
"prism-react-renderer": "^2.1.0",
3333
"react": "^18.2.0",
34-
"react-dom": "^18.2.0"
34+
"react-dom": "^18.2.0",
35+
"unist-util-visit": "^5.0.0"
3536
},
3637
"devDependencies": {
3738
"@docusaurus/module-type-aliases": "3.0.0",

pnpm-lock.yaml

Lines changed: 10 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/css/custom.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@
3333
--ifm-color-primary-lightest: #00c3ff;
3434
--docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3);
3535
}
36+
37+
.zenuml-embed {
38+
border-radius: 6px;
39+
overflow: hidden;
40+
font-size: 0;
41+
margin-bottom: 20px;
42+
border: 1px solid #dadde1;
43+
}

src/pages/index.module.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ div[class^='announcementBar_'] [aria-label='Close'] {
2525

2626
.subtitle {
2727
max-width: 760px;
28+
color: #fff;
2829
margin: 0 auto;
2930
}
3031

@@ -41,8 +42,9 @@ div[class^='announcementBar_'] [aria-label='Close'] {
4142
}
4243

4344
.getStarted {
44-
border: 1px solid var(--ifm-font-color-base-inverse);
45-
box-shadow: inset 0 0 0 1px var(--ifm-font-color-base-inverse);
45+
color: #fff;
46+
border: 1px solid #fff;
47+
box-shadow: inset 0 0 0 1px #fff;
4648
}
4749

4850
.container {

src/pages/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function HomepageHeader() {
2323
<header className={clsx('hero hero--primary', styles.heroBanner)}>
2424
<div className={styles.container}>
2525
<div className={styles.left}>
26-
<Heading as="h1" className="hero__title">
26+
<Heading as="h1" className={clsx('hero__title', styles.title)}>
2727
Create diagrams faster and better
2828
</Heading>
2929
<p className={clsx('hero__subtitle', styles.subtitle)}>

src/plugins/zenuml.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { visit } from 'unist-util-visit';
2+
3+
function attr(name, value) {
4+
return {
5+
type: 'mdxJsxAttribute',
6+
name,
7+
value,
8+
};
9+
}
10+
11+
async function handleNode(node) {
12+
const code = encodeURIComponent(
13+
JSON.stringify({
14+
js: node.value,
15+
}),
16+
);
17+
const params = new URLSearchParams(node.meta);
18+
19+
const jsxNode = {
20+
type: 'mdxJsxTextElement',
21+
name: 'div',
22+
attributes: [attr('className', 'zenuml-embed')],
23+
children: [
24+
{
25+
type: 'mdxJsxTextElement',
26+
name: 'iframe',
27+
attributes: [
28+
attr(
29+
'src',
30+
`https://app.zenuml.com?embed=1&code=${code}&title=${
31+
params.get('title') || ''
32+
}&stickyOffset=30`,
33+
),
34+
attr('width', '100%'),
35+
attr('height', '600px'),
36+
attr('frameBorder', '0'),
37+
],
38+
children: [],
39+
},
40+
],
41+
};
42+
43+
Object.keys(node).forEach((key) => delete node[key]);
44+
Object.keys(jsxNode).forEach((key) => (node[key] = jsxNode[key]));
45+
}
46+
47+
const plugin = () => {
48+
const transformer = async (ast) => {
49+
const nodesToProcess = [];
50+
visit(ast, 'code', (node) => {
51+
// Need help constructing this AST node?
52+
// Use the MDX Playground and explore what your output mdast should look like
53+
// https://mdxjs.com/playground/
54+
if (node.lang === 'zenuml') {
55+
nodesToProcess.push(handleNode(node));
56+
}
57+
});
58+
await Promise.all(nodesToProcess);
59+
};
60+
return transformer;
61+
};
62+
63+
export default plugin;

0 commit comments

Comments
 (0)