Markdown dependency analyzer โ extract all dependencies, generate diagrams and charts
Project description
mdflow
AI Cost Tracking
- ๐ค LLM usage: $0.1500 (1 commits)
- ๐ค Human dev: ~$200 (2.0h @ $100/h, 30min dedup)
Generated on 2026-05-03 using openrouter/qwen/qwen3-coder-next
Markdown dependency analyzer โ extract all dependencies, generate diagrams and charts.
mdflow parses Markdown files and extracts every possible structural element:
headings, links, fenced code blocks (including markpact:* embedded file references),
list items, TOON/YAML quality sections, and document metadata.
It then generates Mermaid diagrams, HTML reports, and Markdown summaries.
What it extracts
| Element | Details |
|---|---|
| Headings | Full H1โH6 hierarchy, anchor slugs |
| Links | [text](href) โ classified as internal / external / anchor / image |
| Code blocks | Language, content, line range, markpact:type path=... metadata |
| List items | Depth, parent heading, clean text |
| TOON sections | ALERTS, REFACTOR, HOTSPOTS, HEALTH, NEXT, RISKS, PIPELINESโฆ |
| Document metadata | ## Metadata key/value lists |
| Cross-doc dependencies | Links between files, markpact embedded file paths |
Generated outputs
| Output | Description |
|---|---|
{stem}_report.html |
Self-contained HTML report with all diagrams (Mermaid.js) |
{stem}_report.md |
Markdown summary with inline Mermaid |
{stem}_heading_mindmap.mermaid |
Mindmap of heading hierarchy |
{stem}_section_flow.mermaid |
Section flowchart with code/link annotations |
{stem}_code_pie.mermaid |
Pie chart of code blocks by language |
{stem}_markpact_graph.mermaid |
Graph of embedded file references |
{stem}_alerts_graph.mermaid |
TOON alerts & refactor tasks flowchart |
{stem}_workflow.mermaid |
DOQL workflow steps diagram |
dependency_graph.html |
Cross-document dependency graph (directory scan) |
Installation
# Clone or copy the mdflow/ directory, then:
pip install -e .
# No mandatory dependencies โ pure stdlib.
Usage
Python API
from mdflow import MdFlow
flow = MdFlow()
# โโ Single file โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
doc = flow.parse("SUMR.md")
print(doc.title) # "Ze ลบrรณdeล"
print(len(doc.headings)) # 24
print([ts.name for ts in doc.toon_sections]) # ['HEALTH', 'REFACTOR', ...]
print(doc.metadata) # {'name': 'redsl', 'version': '1.2.45', ...}
# Access markpact embedded file references
for cb in doc.markpact_blocks:
print(f"markpact:{cb.markpact_type} path={cb.markpact_path}")
# Get TOON quality metrics
metrics = flow.toon_metrics(doc)
print(metrics["health"]) # {'cc_mean': 20.0, 'critical': 7}
print(metrics["refactors"][:3]) # list of refactor tasks
# Get all Mermaid diagrams as strings (no files written)
diagrams = flow.diagrams(doc)
print(diagrams["section_flow"]) # flowchart TD ...
# Generate reports to disk
flow.report(doc, "output/") # writes HTML + MD + .mermaid files
# โโ Directory scan โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
docs, graph = flow.scan("docs/", "output/")
print(f"{len(docs)} files, {len(graph.edges)} dependency edges")
CLI
# Analyze a single file
mdflow analyze SUMR.md --output output/
# Select formats
mdflow analyze SUMR.md --format html,md
# Scan a directory
mdflow scan docs/ --output output/
# Print a specific Mermaid diagram to stdout
mdflow diagram SUMR.md --diagram section_flow
mdflow diagram SUMR.md --diagram list # list available diagrams
# Write diagram to file
mdflow diagram SUMR.md --diagram alerts_graph -o alerts.mermaid
Examples
The examples/ directory contains comprehensive usage examples:
- basic_usage.py - Basic parsing and report generation
- advanced_analysis.py - Structure analysis, code inventory, TOON metrics
- directory_scan.py - Scanning multiple files and dependency graphs
- custom_diagrams.py - Working with diagrams programmatically
- cli_usage.sh - CLI usage examples
Run examples from the project root:
python examples/basic_usage.py
python examples/advanced_analysis.py
python examples/directory_scan.py
python examples/custom_diagrams.py
bash examples/cli_usage.sh
See examples/README.md for detailed documentation.
Architecture
mdflow/
โโโ __init__.py โ MdFlow faรงade (high-level API)
โโโ models.py โ Data classes: MdDocument, DependencyGraph, โฆ
โโโ parser.py โ Core Markdown parser (stdlib only)
โโโ analyzers/
โ โโโ __init__.py โ DependencyAnalyzer, StructureAnalyzer,
โ CodeInventoryAnalyzer, ToonAnalyzer
โโโ generators/
โ โโโ __init__.py
โ โโโ mermaid.py โ All Mermaid diagram generators
โ โโโ html.py โ Self-contained HTML report
โ โโโ markdown.py โ Markdown summary report
โโโ cli.py โ argparse CLI entry point
Supported TOON sections
mdflow recognises these TOON section names inside toon / yaml code blocks
and in blocks tagged markpact:analysis:
ALERTS ยท REFACTOR ยท HOTSPOTS ยท HEALTH ยท NEXT ยท RISKS ยท PIPELINES
ยท DUPLICATES ยท WARNINGS ยท MODULES ยท EVOLUTION ยท COUPLING
Extension points
- Custom extractor: subclass or monkey-patch
MdParser - Custom diagram: call
flow.diagrams(doc)and extend themermaidmodule - Graphviz output: install
graphvizPython package and useDependencyGraphdata directly
License
Licensed under Apache-2.0.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mdflow-0.1.2.tar.gz.
File metadata
- Download URL: mdflow-0.1.2.tar.gz
- Upload date:
- Size: 24.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb702e7f9eddbf6e184d3726e06c324d1437dbfd17fb1224aeed6bb1b9f1eb91
|
|
| MD5 |
ea7e25fc402d2dc35b3814ef775f8cce
|
|
| BLAKE2b-256 |
3de0c5684c2e54525985113c5d61380964b9646e77d208b7c03dbbc1acb9f27d
|
File details
Details for the file mdflow-0.1.2-py3-none-any.whl.
File metadata
- Download URL: mdflow-0.1.2-py3-none-any.whl
- Upload date:
- Size: 25.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0faeab7c792554fb61276fd7fcd5aea6ba89aa7c8b3c189d3067c5e04b77195d
|
|
| MD5 |
5b43650a123a76c6cf64016fdcd2fc77
|
|
| BLAKE2b-256 |
eaed2069e5e8d554ecaf7243a0eb7a4ff8c3f3800416af4c5441277b089c30a6
|