Last active
September 23, 2022 10:28
-
-
Save valsteen/4ba14804f9b54955f263ddf9825967ad to your computer and use it in GitHub Desktop.
Quick and dirty : converting from sequencediagram.org charts to mermaid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from sys import stdin | |
def main(): | |
result = "" | |
title_re = re.compile("^title (.*)$") | |
right_arrow_re = re.compile(r"(.+?)\s*(-?)->\s*(.+?)(:(.+))?$") | |
left_arrow_re = re.compile(r"(.+?)\s*<-(-?)\s*(.+?)(:(.+))?$") | |
empty = re.compile("^\s*$") | |
entryspacing = re.compile("^\s*entryspacing") | |
group_re = re.compile("^group (.+)$") | |
title = "" | |
for line in stdin.readlines(): | |
if empty.match(line) or entryspacing.match(line): | |
continue | |
elif m := title_re.match(line): | |
title = f"# {m.group(1)}" | |
continue | |
elif m := group_re.match(line): | |
line = f"alt {m.group(1)}" | |
elif m := right_arrow_re.match(line): | |
line = f"{m.group(1)} {m.group(2)}->> {m.group(3)}: {m.group(5)}" | |
elif m := left_arrow_re.match(line): | |
line = f"{m.group(3)} {m.group(2)}->> {m.group(1)}: {m.group(5)}" | |
line = line.replace(r"\n", "<br>") | |
result = f"{result}\n{line}" | |
print(f""" | |
{title} | |
```mermaid | |
sequenceDiagram | |
{result} | |
``` | |
""") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment