aquamarine

repository·master·Indexed 20 days ago

https://github.com/mersinvald/aquamarine

A procedural macro for Rust that integrates Mermaid.js into rustdoc, enabling the rendering of interactive diagrams within technical documentation. It provides the #[aquamarine] attribute to process doc comments and the include_mmd! macro to load diagrams from external .mmd files. Version 0.6.0.

Tokens
1.1K
Snippets
6
Records
7
Agent score
19%

What's inside aquamarine

  1. Configure Mermaid diagram themes

    master

    Aquamarine automatically selects the dark theme if your rustdoc theme is set to ayu or dark.

    You can override the default theme on a per-diagram basis using the Mermaid %%init%% attribute within the doc comment. This is useful for ensuring specific diagrams match your documentation's visual style or for applying custom colors.

    Refer to the Mermaid.js Theming documentation for a full list of available configuration options.

    /// ```mermaid
    /// %%{init: { 'theme': 'base', 'themeVariables': { 'primaryColor': '#ffcccc' }}}%%
    /// graph TD
    ///      A --> B
    /// ```
  2. Load Mermaid diagrams from external files

    master

    To keep your Rust source code clean and reduce clutter in doc comments, you can load Mermaid diagrams from external files using the include_mmd! macro. This allows you to maintain complex diagrams in separate .mmd files while still rendering them in your rustdoc output.

    #[cfg_attr(doc, aquamarine::aquamarine)]
    /// My diagram #1
    /// include_mmd!("diagram1.mmd")
    /// My diagram #2
    /// include_mmd!("diagram2.mmd")
    pub fn example_load_from_file() {}
  3. Use Aquamarine to render Mermaid diagrams in rustdoc

    master

    Aquamarine is a procedural macro extension for rustdoc that embeds mermaid.js into your generated documentation. This allows you to render Mermaid diagrams directly within your Rust doc comments.

    To enable Aquamarine for a module, struct, or function, apply the #[cfg_attr(doc, aquamarine::aquamarine)] attribute. Then, include a code block starting with ```mermaid within your doc comments. The diagram will be rendered in place of the code block in the final HTML documentation.

    #[cfg_attr(doc, aquamarine::aquamarine)]
    /// ```mermaid
    /// graph LR
    ///     A --> B
    /// ```
    pub fn example() {}
  4. How dark-mode theming works in Aquamarine

    master

    Aquamarine automatically detects your rustdoc theme. If your documentation is using the ayu or dark themes, Aquamarine will default to the dark Mermaid theme to ensure visual consistency.

    If you switch themes in your documentation, you may need to reload the page to trigger a redraw of the diagrams.

  5. Customize Mermaid themes per diagram

    master

    You can override the default theme for a specific diagram by using the Mermaid %%init%% attribute directly inside the doc-comment code block. This allows you to apply custom colors and styles to individual diagrams.

    To learn more about available configuration options, refer to the Mermaid.js Theming documentation.

    /// ```mermaid
    /// %%{init: { 'theme': 'base', 'themeVariables': { 'primaryColor': '#ffcccc' }}}%%
    /// graph TD
    ///      A --> B
    /// ```
    # fn example() {}
  6. Use the `#[aquamarine]` macro to add Mermaid diagrams

    master

    Aquamarine is a procedural macro that embeds mermaid.js into your rustdoc HTML output. To use it, apply the #[aquamarine] attribute to an item (like a function or struct) and include a mermaid code block within its doc comments. The diagram will render in place of the code block in the generated documentation.

    Note: It is recommended to use #[cfg_attr(doc, aquamarine)] so that the macro only affects the documentation attributes and doesn't interfere with your actual code logic during compilation.

    # use aquamarine::aquamarine;
    #[cfg_attr(doc, aquamarine)]
    /// ```mermaid
    /// graph LR
    ///     A --> B
    /// ```
    pub fn my_function() {}
  7. The `#[aquamarine]` attribute

    master

    The #[aquamarine] attribute is a procedural macro that processes doc comments to inject Mermaid.js support.

    Constraints:

    • You cannot apply multiple #[aquamarine] attributes to a single entity. Doing so will result in a compilation error: multiple 'aquamarine' attributes on one entity are illegal.
    #[aquamarine]
    /// ```mermaid
    /// graph LR
    ///     A --> B
    /// ```
    struct Foo;