mermaid

module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 29, 2024 License: MIT

README

Go Reference LinuxUnitTest MacUnitTest WindowsUnitTest reviewdog Gosec Coverage

What is mermaid package

The Package mermaid is a simple mermaid builder in golang. This library assembles mermaid using method chaining, not uses a template engine like html/template. Currently, this library supports only sequence diagram.

This library was initially developed to display test results in nao1215/spectest. Therefore, it implements the features required by spectest, but there are no plans to add additional functionalities unless requested by someone. This library is intended to be used in conjunction with nao1215/markdown.

Additionally, complex code that increases the complexity of the library, such as generating nested lists, will not be added. I want to keep this library as simple as possible.

Supported OS and Go version

  • OS: Linux, macOS, Windows
  • Go: 1.18 or later

Supported mermaid syntax (sequence diagram)

  • participant
  • participant alias (not supported)
  • actor
  • actor alias (not supported)
  • activate / deactivate
  • note over / left of / right of
  • link
  • sync / async request
  • sync / async response
  • loop
  • alt / else / opt
  • parallel
  • break
  • critical
  • group

Example

Basic usage

Generate mermaid in markdown. You can generate mermaid using go generate. Please define code to generate Mermaid first. Then, run "go generate ./..." to generate it.

package main

import (
	"os"

	"github.com/nao1215/markdown"
	"github.com/nao1215/mermaid/sequence"
)

//go:generate go run main.go

func main() {
	diagram := sequence.NewDiagram(os.Stdout).
		Participant("Sophia").
		Participant("David").
		Participant("Subaru").
		LF().
		SyncRequest("Sophia", "David", "Please wake up Subaru").
		SyncResponse("David", "Sophia", "OK").
		LF().
		LoopStart("until Subaru wake up").
		SyncRequest("David", "Subaru", "Wake up!").
		SyncResponse("Subaru", "David", "zzz").
		SyncRequest("David", "Subaru", "Hey!!!").
		BreakStart("if Subaru wake up").
		SyncResponse("Subaru", "David", "......").
		BreakEnd().
		LoopEnd().
		LF().
		SyncResponse("David", "Sophia", "wake up, wake up").
		String()

	markdown.NewMarkdown(os.Stdout).
		H2("Sequence Diagram").
		CodeBlocks(markdown.SyntaxHighlightMermaid, diagram).
		Build()
}

Plain text output: markdown is here

## Sequence Diagram
```mermaid
sequenceDiagram
    participant Sophia
    participant David
    participant Subaru

    Sophia->>David: Please wake up Subaru
    David-->>Sophia: OK

    loop until Subaru wake up
    David->>Subaru: Wake up!
    Subaru-->>David: zzz
    David->>Subaru: Hey!!!
    break if Subaru wake up
    Subaru-->>David: ......
    end
    end

    David-->>Sophia: wake up, wake up
```

Mermaid output:

sequenceDiagram
    participant Sophia
    participant David
    participant Subaru

    Sophia->>David: Please wake up Subaru
    David-->>Sophia: OK

    loop until Subaru wake up
    David->>Subaru: Wake up!
    Subaru-->>David: zzz
    David->>Subaru: Hey!!!
    break if Subaru wake up
    Subaru-->>David: ......
    end
    end

    David-->>Sophia: wake up, wake up

Contribution

First off, thanks for taking the time to contribute! Contributions are not only related to development. For example, GitHub Star motivates me to develop! Please feel free to contribute to this project.

LICENSE

MIT License

Directories

Path Synopsis
Package main is generating mermaid sequence diagram.
Package main is generating mermaid sequence diagram.
Package sequence is mermaid sequence diagram builder.
Package sequence is mermaid sequence diagram builder.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL