Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mermaid.js 対応 #150

Merged
merged 15 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "0.1.82-alpha.2",
"version": "0.1.82",
"npmClient": "yarn",
"useWorkspaces": true
}
188 changes: 188 additions & 0 deletions packages/example/articles/embed.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,191 @@ https://gist.github.com/mattpodwysocki/218388
@[gist](https://gist.github.com/hofmannsven/9164408?file=my.cnf)

ssfafafaffafa

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note] サンプルを記載していますがこんなに数がいらなければ言ってください。


## mermaid.js

```mermaid
%%{init: { 'theme': 'forest' } }%%
graph LR;
A-->B & C-->D & E-->F & Z-->X;
F-->G
G-->H
H-->I
I-->J
J-->K
K-->L
L-->M
M-->N
N-->O
O-->P
P-->ID1[ノード1<br>ノード2]
```
Copy link
Member Author

@cm-wada-yusuke cm-wada-yusuke Jun 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note]

  • グラフかつチェイン(&)を使った例
  • 横幅を越えようとすると図と文字が小さくなる例

image


### flowchart

```mermaid
flowchart TB
c1-->a2
subgraph one
a1-->a2
end
subgraph two
b1-->b2
end
subgraph three
c1-->c2
end
one --> two
three --> two
two --> c2
```
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note] フローチャートの例


### sequence diagram

```mermaid
sequenceDiagram
autonumber
アリス->>光輝: Hello John, how are you?
loop Healthcheck
光輝->>光輝: Fight against hypochondria
end
Note right of 光輝: Rational thoughts!
光輝-->>アリス: Great!
光輝->>Bob: How about you?
Bob-->>光輝: Jolly good!
```
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note]

  • シーケンス図の例
  • 日本語の例

image


### class diagram

```mermaid
classDiagram
Animal <|-- Duck
Animal <|-- Fish
Animal <|-- Zebra
Animal : +int age
Animal : +String gender
Animal: +isMammal()
Animal: +mate()
class Duck{
+String beakColor
+swim()
+quack()
}
class Fish{
-int sizeInFeet
-canEat()
}
class Zebra{
+bool is_wild
+run()
}
```
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note]

  • クラス図の例



### state diagram

```mermaid
stateDiagram-v2
[*] --> Active

state Active {
[*] --> NumLockOff
NumLockOff --> NumLockOn : EvNumLockPressed
NumLockOn --> NumLockOff : EvNumLockPressed
--
[*] --> CapsLockOff
CapsLockOff --> CapsLockOn : EvCapsLockPressed
CapsLockOn --> CapsLockOff : EvCapsLockPressed
--
[*] --> ScrollLockOff
ScrollLockOff --> ScrollLockOn : EvScrollLockPressed
ScrollLockOn --> ScrollLockOff : EvScrollLockPressed

}
```
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note] 状態遷移図の例




```mermaid
graph LR
A:::someclass B
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
classDef someclass fill:#f96;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
A-->B & C-->D & E-->F & Z-->X;
```
Copy link
Member Author

@cm-wada-yusuke cm-wada-yusuke Jun 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note]

  • エラーの例
  • 表示を相談したい

image



```mermaid
graph LR;
A["<img src=invalid onerror=alert('XSS')></img>"] --> B;
alert`md5_salt`-->B;
click alert`md5_salt` eval "Tooltip for a callback"
click B "javascript:alert('XSS')" "This is a tooltip for a link"
```
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note]

  • prevent xss な例
  • 基本的には escapeHTML 済みのコードを mermaidAPI がレンダリングすることになるのでXSSは最後は mermaid 側にゆだねられます


```mermaid
graph LR;
alert`md5_salt`-->B;
click alert`md5_salt` eval "Tooltip for a callback"
click B "javascript:alert('XSS')" "This is a tooltip for a link"
link Zebra "http://www.github.com" "This is a link"
```
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note]

  • mermaid 側のセキュリティ対策により link Zebra "http://www.github.com" "This is a link" は文法エラーになる例

4 changes: 2 additions & 2 deletions packages/example/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"private": true,
"name": "example",
"version": "0.1.82-alpha.2",
"version": "0.1.82",
"dependencies": {
"zenn-cli": "^0.1.82-alpha.2"
"zenn-cli": "^0.1.82"
}
}
8 changes: 4 additions & 4 deletions packages/zenn-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zenn-cli",
"license": "MIT",
"version": "0.1.82-alpha.2",
"version": "0.1.82",
"description": "Preview Zenn content locally.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -49,9 +49,9 @@
"socket.io": "^3.1.0",
"socket.io-client": "^3.1.0",
"update-notifier": "^5.1.0",
"zenn-content-css": "^0.1.82-alpha.2",
"zenn-embed-elements": "^0.1.82-alpha.2",
"zenn-markdown-html": "^0.1.82-alpha.2"
"zenn-content-css": "^0.1.82",
"zenn-embed-elements": "^0.1.82",
"zenn-markdown-html": "^0.1.82"
},
"devDependencies": {
"@testing-library/react": "^11.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/zenn-content-css/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenn-content-css",
"version": "0.1.82-alpha.2",
"version": "0.1.82",
"license": "MIT",
"description": "Zenn flavor content style.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/zenn-embed-elements/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenn-embed-elements",
"version": "0.1.82-alpha.2",
"version": "0.1.82",
"description": "Web components for embedded contents.",
"repository": {
"type": "git",
Expand Down
Loading