Skip to main content

Crate rushdown_diagram

Crate rushdown_diagram 

Source
Expand description

§rushdown-diagram

rushdown-diagram is a diagram plugin for rushdown, a markdown parser. It allows you to easily embed diagrams in your markdown documents.

§Installation

Add dependency to your Cargo.toml:

[dependencies]
rushdown-diagram = "x.y.z"

§Syntax

Currently, rushdown-diagram supports diagrams in the following formats:

  • MermaidJS
    • client-side rendering
  • PlantUML
    • server-side rendering (requires a plantuml command)

You can use the following syntax to embed diagrams:

```mermaid
graph LR
    A --- B
    B-->C[fa:fa-ban forbidden]
    B-->D(fa:fa-spinner);
```

```plantuml
@startuml
Hello <|-- World
@enduml
```

§Usage

§Example

use core::fmt::Write;
use rushdown::{
    new_markdown_to_html,
    parser::{self, ParserExtension},
    renderer::html::{self, RendererExtension},
    Result,
};
use rushdown_diagram::{diagram_parser_extension, diagram_html_renderer_extension, DiagramParserOptions, DiagramHtmlRendererOptions};

let markdown_to_html = new_markdown_to_html(
    parser::Options::default(),
    html::Options::default(),
    diagram_parser_extension(DiagramParserOptions::default()),
    diagram_html_renderer_extension(DiagramHtmlRendererOptions::default()),
);
let mut output = String::new();
let input = r#"
```mermaid
graph LR
    A --- B
    B-->C[fa:fa-ban forbidden]
    B-->D(fa:fa-spinner);
```
"#;
match markdown_to_html(&mut output, input) {
    Ok(_) => {
        println!("HTML output:\n{}", output);
    }
    Err(e) => {
        println!("Error: {:?}", e);
    }
}

§Donation

BTC: 1NEDSyUmo4SMTDP83JJQSWi1MvQUGGNMZB

Github sponsors also welcome.

§License

MIT

§Author

Yusuke Inuzuka

Structs§

ClientSideMermaidHtmlRendereringOptions
Diagram
A struct representing a diagram in the AST.
DiagramHtmlRendererOptions
Options for the diagram HTML renderer.
DiagramParserOptions
Options for the diagram parser.
MermaidParserOptions
Options for the Mermaid diagram parser.
PlantUmlHtmlRenderingOptions
Options for the PlantUML diagram HTML renderer.
PlantUmlParserOptions
Options for the PlantUML diagram parser.

Enums§

DiagramType
An enum representing the type of a diagram.
MermaidHtmlRenderingOptions
Options for the Mermaid diagram HTML renderer.

Functions§

diagram_html_renderer_extension
Returns a renderer extension that renders diagrams in HTML.
diagram_parser_extension
Returns a parser extension that parses diagrams.