Add support for mermaid diagrams to the forum

Mermaid seems to allow for many different kinds of figures (some info and examples here: About Mermaid | Mermaid), and it would be great to have the ability to quickly create diagrams in posts. The following discourse component appears to support this:

Might this possibly be worth setting up for the rust forum site?

1 Like

I kind of hate mermaid, but much less than everything else I've tried, and it's supported pretty much everywhere now. I guess this is agreement? :person_shrugging:

1 Like

Who is responsible for the site, and what is the process for trying out something new like this?

Bumping this thread - does anyone know what the process / governance related to making site changes is?

Perhaps @moderators can help here.

Or perhaps not? :frowning:

The site is powered by Discourse. I would recommend you submit this feature request to them as the moderators on this site (presumably) aren't the correct people to ask to add this given that (if I recall correctly) this forum is hosted for us by the folks at Discourse.

The link at the top of this thread is to the official Discourse component for Mermaid.

Here's some Discourse info on the feature.

It doesn't work with fontawesome (whatever that is).

Under Discourse pricing it is not listed as optional.

Oops, I completely missed that omnibox. My apologies...

Given that there really hasn't been any discussion about whether we should add mermaid or not, I'd like to raise my concerns of adding this as a feature, mainly for two reasons:

  • I feel like URLO/Discourse is already quite slow to load and interact with on mobile. Adding 30MB of JS for a feature that I believe won't be used really that often isn't going to help.

  • You can just link your mermaid diagram from the online mermaid editor and embed it as markdown. Here an example I created for one of my projects:

    It is literally as easy as linking to a playground.

3 Likes

Linking to the mermaid-editor does look like a decent solution. The only concern I see is about how long these diagrams will be available, and if there's a chance that the service will change in the future in a way that prevents them from being accessed.

And for reference in case the online editor is ever removed, the underlying diagram is stored in the URL as base 64 encoded deflated JSON. The following code is a bad implementation of URL to JSON string conversion:

use anyhow::Context as _;
use base64::engine::general_purpose::URL_SAFE;
use base64::Engine;
use flate2::Decompress;

const MAX_DECOMPRESSED_SIZE: usize = 2 * 65536;

fn main() -> anyhow::Result<()> {
    let url = "https://mermaid.live/edit#pako:eNp1k9uK2zAQhl9l0FULsZftmVwUGmcPtKS71O1SsENRpPFaxJaMDlsWO-_ecXwopKkvjDTzjWb-GallwkhkS1ZU5rcoufWw-p5roM-F3aPlTQlGNxbrrOBuWfDIoX1CC3ca7smqHG5PcGGNzhL6wWezG52rzAb9a8fFPjSxK0crajks-pAo-thdxrAxQfsumbKVUsKFxKcLJ_nl9i8NPf4-hh-6PgZAcuJ7FUPaKA2h6UAY7bnSVPUAJVEUrbMXD6YKNb78p_6Jphp2fQ3SiD3FJpN9DLjK_qtnXly37SgkUN_gk6yVPhxOEu4_uEmuqEyQkFTB-TnPTXbXoH64_zrub7OURqAEws8tSY3gS5Z67rEIVYqejKfNndVTX6B7HfdKNApq2s1Z4g0RFulEWB0FdnB7lnsbwzrUzUi5DtZnsXc0CSoGrqINVxV0cM0WrEZbcyXp4rV9UM58iTXmbElLiQUPlc_ZYnDNV7N3t0OOmfpGR6NFO4Ritc9ZT1CPD5SGB2_SZy3Y0tuAC2ZNeCwZdbpytAuNJJVrxWkO9YSgVN7YzfAqjo_j8Ac9Xgak";

    let stripped = url
        .strip_prefix("https://mermaid.live/edit#pako:")
        .context("Removing URL prefix")?;
    let decoded = URL_SAFE
        .decode(stripped)
        .context("While decoding base64 lump")?;

    let mut decompressor = Decompress::new(true);
    let mut output = Vec::with_capacity(MAX_DECOMPRESSED_SIZE);
    decompressor.decompress_vec(&decoded, &mut output, flate2::FlushDecompress::Finish)?;

    let output = String::from_utf8_lossy(&output);
    println!("{output}");

    Ok(())
}
2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.