{"id":50965686,"url":"https://github.com/harehare/mermaid.mq","last_synced_at":"2026-06-18T20:01:58.410Z","repository":{"id":364515073,"uuid":"1268172599","full_name":"harehare/mermaid.mq","owner":"harehare","description":"A Mermaid diagram parser implemented as an mq module.","archived":false,"fork":false,"pushed_at":"2026-06-13T10:09:30.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-13T11:12:40.479Z","etag":null,"topics":["markdown","mermaid","mq"],"latest_commit_sha":null,"homepage":"https://mqlang.org","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/harehare.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-13T08:12:01.000Z","updated_at":"2026-06-13T10:09:34.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/harehare/mermaid.mq","commit_stats":null,"previous_names":["harehare/mermaid.mq"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/harehare/mermaid.mq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harehare%2Fmermaid.mq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harehare%2Fmermaid.mq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harehare%2Fmermaid.mq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harehare%2Fmermaid.mq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harehare","download_url":"https://codeload.github.com/harehare/mermaid.mq/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harehare%2Fmermaid.mq/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34505423,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-18T02:00:06.871Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["markdown","mermaid","mq"],"created_at":"2026-06-18T20:01:55.936Z","updated_at":"2026-06-18T20:01:58.402Z","avatar_url":"https://github.com/harehare.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003emermaid.mq\u003c/h1\u003e\n\nA [Mermaid](https://mermaid.js.org/) diagram parser implemented as an [mq](https://github.com/harehare/mq) module.\n\n## Features\n\n- **Parse** (`mermaid_parse`) — converts Mermaid diagram text into structured data\n- **Stringify** (`mermaid_stringify`) — converts structured data back to Mermaid diagram text (round-trip)\n- **Flowchart / Graph** — nodes (rect, round, diamond, circle, stadium), edges with optional labels, all direction keywords (`LR`, `RL`, `TD`, `TB`, `BT`)\n- **Sequence diagram** — participants, actors, and messages with all arrow types (`-\u003e\u003e`, `--\u003e\u003e`, `-\u003e`, `--\u003e`, `-x`, `--x`)\n- **Pie chart** — title and labeled slices\n- **Class diagram** — class names and relationships\n\n## Installation\n\nCopy `mermaid.mq` to your mq module directory, or place it anywhere and reference it with `-L`.\n\n```sh\ncp mermaid.mq ~/.local/mq/config/\n```\n\n### HTTP Import (no local installation needed)\n\nIf `mq` was built with the `http-import` feature, you can import directly from GitHub without any local setup:\n\n```sh\nmq -I raw 'import \"github.com/harehare/mermaid.mq\" | mermaid::mermaid_parse(.)' diagram.mmd\n```\n\nPin to a specific release with `@vX.Y.Z`:\n\n```sh\nmq -I raw 'import \"github.com/harehare/mermaid.mq@v0.1.0\" | mermaid::mermaid_parse(.)' diagram.mmd\n```\n\n## Usage\n\n```sh\nmq -L . -I raw 'import \"mermaid\" | mermaid::mermaid_parse(.)' diagram.mmd\n```\n\n## API\n\n### `mermaid_parse(input)`\n\nParses a Mermaid diagram string and returns structured data.\n\n| Diagram type | Output keys |\n|---|---|\n| `flowchart` / `graph` | `type`, `direction`, `nodes`, `edges` |\n| `sequenceDiagram` | `type`, `participants`, `messages` |\n| `pie` | `type`, `title`, `slices` |\n| `classDiagram` | `type`, `classes`, `relations` |\n| other | `type`, `raw_lines` |\n\n### `mermaid_stringify(diagram)`\n\nConverts a parsed diagram object (as returned by `mermaid_parse`) back into Mermaid diagram text. Useful for round-tripping: parse → transform → serialize.\n\n| Diagram type | Output format |\n|---|---|\n| `flowchart` / `graph` | `graph {dir}` + edges + standalone nodes |\n| `sequenceDiagram` | `sequenceDiagram` + participants + messages |\n| `pie` | `pie title {title}` + slices |\n| `classDiagram` | `classDiagram` + class declarations + relations |\n| other | `{type}` + raw lines (indented) |\n\n## Examples\n\n### Flowchart\n\nGiven `flow.mmd`:\n\n```\ngraph LR\n  A[Start] --\u003e B{Is it?}\n  B --\u003e|Yes| C[OK]\n  B --\u003e|No| D[Not OK]\n  C --\u003e E((End))\n```\n\n```sh\n# Extract all node IDs\nmq -L . -I raw 'import \"mermaid\" | mermaid::mermaid_parse(.) | .\"nodes\" | map(fn(n): n[\"id\"];)' flow.mmd\n# =\u003e [\"A\", \"B\", \"C\", \"D\", \"E\"]\n\n# Extract edges with labels\nmq -L . -I raw 'import \"mermaid\" | mermaid::mermaid_parse(.) | .\"edges\" | filter(fn(e): e[\"label\"] != \"\";)' flow.mmd\n# =\u003e [{\"from\":\"B\",\"to\":\"C\",\"label\":\"Yes\"}, {\"from\":\"B\",\"to\":\"D\",\"label\":\"No\"}]\n\n# Get direction\nmq -L . -I raw 'import \"mermaid\" | mermaid::mermaid_parse(.) | .\"direction\"' flow.mmd\n# =\u003e \"LR\"\n```\n\n### Sequence Diagram\n\nGiven `seq.mmd`:\n\n```\nsequenceDiagram\n  participant Alice\n  participant Bob\n  Alice-\u003e\u003eBob: Hello Bob!\n  Bob--\u003e\u003eAlice: Hi Alice!\n  Alice-\u003e\u003eBob: How are you?\n```\n\n```sh\n# List participants\nmq -L . -I raw 'import \"mermaid\" | mermaid::mermaid_parse(.) | .\"participants\" | map(fn(p): p[\"name\"];)' seq.mmd\n# =\u003e [\"Alice\", \"Bob\"]\n\n# Filter messages from Alice\nmq -L . -I raw 'import \"mermaid\" | mermaid::mermaid_parse(.) | .\"messages\" | filter(fn(m): m[\"from\"] == \"Alice\";)' seq.mmd\n# =\u003e [{\"from\":\"Alice\",\"to\":\"Bob\",\"arrow\":\"-\u003e\u003e\",\"text\":\"Hello Bob!\"}, ...]\n```\n\n### Pie Chart\n\nGiven `pie.mmd`:\n\n```\npie title Pets adopted by volunteers\n  \"Dogs\" : 386\n  \"Cats\" : 85\n  \"Rats\" : 15\n```\n\n```sh\n# Get the title\nmq -L . -I raw 'import \"mermaid\" | mermaid::mermaid_parse(.) | .\"title\"' pie.mmd\n# =\u003e \"Pets adopted by volunteers\"\n\n# Get the largest slice\nmq -L . -I raw 'import \"mermaid\" | mermaid::mermaid_parse(.) | .\"slices\" | sort_by(fn(s): s[\"value\"];) | last()' pie.mmd\n# =\u003e {\"label\":\"Dogs\",\"value\":386}\n```\n\n### Class Diagram\n\nGiven `class.mmd`:\n\n```\nclassDiagram\n  class Animal\n  class Dog\n  class Cat\n  Animal \u003c|-- Dog : extends\n  Animal \u003c|-- Cat : extends\n```\n\n```sh\n# List all classes\nmq -L . -I raw 'import \"mermaid\" | mermaid::mermaid_parse(.) | .\"classes\" | map(fn(c): c[\"name\"];)' class.mmd\n# =\u003e [\"Animal\", \"Dog\", \"Cat\"]\n\n# List relationships\nmq -L . -I raw 'import \"mermaid\" | mermaid::mermaid_parse(.) | .\"relations\"' class.mmd\n# =\u003e [{\"from\":\"Animal\",\"to\":\"Dog\",\"rel\":\"\u003c|--\",\"label\":\"extends\"}, ...]\n```\n\n### Round-trip (parse → transform → stringify)\n\nCombine `mermaid_parse` and `mermaid_stringify` to transform a diagram and re-emit valid Mermaid text.\n\n```sh\n# Lossless round-trip\nmq -L . -I raw 'import \"mermaid\" | mermaid::mermaid_parse(.) | mermaid::mermaid_stringify(.)' flow.mmd\n\n# Add a node then re-serialize\nmq -L . -I raw 'import \"mermaid\" | mermaid::mermaid_parse(.) | . + {\"nodes\": .\"nodes\" + [{\"id\":\"F\",\"label\":\"New\",\"shape\":\"rect\"}]} | mermaid::mermaid_stringify(.)' flow.mmd\n\n# Keep only Alice's messages and re-serialize\nmq -L . -I raw 'import \"mermaid\" | mermaid::mermaid_parse(.) | . + {\"messages\": (.\"messages\" | filter(fn(m): m[\"from\"] == \"Alice\";))} | mermaid::mermaid_stringify(.)' seq.mmd\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharehare%2Fmermaid.mq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharehare%2Fmermaid.mq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharehare%2Fmermaid.mq/lists"}