mermaid-slice
v1.0.4
Published
Slice Mermaid sequence diagrams in markdown files
Readme
Usage
To use this tool, you need to have npm installed, more info in the NPM documentation.
npx mermaid-slice filename.mdWhere filename.md is the path to a markdown file. The first time you do this, you will get a question if you want to install the tool to your computer.
Example
```mermaid
sequenceDiagram
participant a as Customer
participant b as Server
participant c as Baker
a ->> b: Give me a cookie
b ->> c: Bake a cookie
c -->> b: Here is the cookie
b -->> a: Here is your cookie
```sequenceDiagram
participant a as Customer
participant b as Server
participant c as Baker
a ->> b: Give me a cookie
b ->> c: Bake a cookie
c -->> b: Here is the cookie
b -->> a: Here is your cookieMaybe you just need to show the interaction between the customer and server, then you can first add a name to the base or master diagram:
%%% name masterand then add another mermaid section where you specifify the actors and what diagram to use as a base:
```mermaid
%%% actors a, b
%%% slice #master
```When you then run this tool against your md file you get the following total md file:
```mermaid
%%% name master
sequenceDiagram
participant a as Customer
participant b as Server
participant c as Baker
a ->> b: Give me a cookie
b ->> c: Bake a cookie
c -->> b: Here is the cookie
b -->> a: Here is your cookie
```
```mermaid
%%% actors a, b
%%% slice #master
%% generated from #master
sequenceDiagram
participant a as Customer
participant b as Server
a->>b: Give me a cookie
b-->>a: Here is your cookie
```The second diagram rendering as:
%%% actors a, b
%%% slice #master
%% generated from #master
sequenceDiagram
participant a as Customer
participant b as Server
a->>b: Give me a cookie
b-->>a: Here is your cookie
Perspective
If you want to slice from one or more actors and automatically include the actors they exchange messages with, use perspective.
When perspective is set, mermaid-slice will:
- Start with the perspective actors.
- Add all actors that send messages to or receive messages from those actors.
- Apply any
actorslines after that as explicit+or-overrides.
Example:
```mermaid
%%% name order-flow
sequenceDiagram
participant customer
participant api
participant erp
participant mailer
customer->>api: Create order
api->>erp: Save order
erp-->>api: Saved
erp->>mailer: Send email
```
```mermaid
%%% perspective api
%%% actors -customer, +mailer
%%% slice #order-flow
```In this case perspective api starts from customer, api, and erp, and then actors -customer, +mailer removes customer and adds mailer.
Running locally from cloned repo
npm run run (file)
