Skip to content

Instantly share code, notes, and snippets.

@valsteen
Last active September 23, 2022 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valsteen/4ba14804f9b54955f263ddf9825967ad to your computer and use it in GitHub Desktop.
Save valsteen/4ba14804f9b54955f263ddf9825967ad to your computer and use it in GitHub Desktop.
Quick and dirty : converting from sequencediagram.org charts to mermaid
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