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?
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.
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.
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(())
}