diff --git a/README.md b/README.md index 6db4af4..b1480e8 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Latest Version](https://img.shields.io/pypi/v/adr-viewer)](https://pypi.org/project/adr-viewer/) Show off your Architecture Decision Records with an easy-to-navigate web page, either as a local web-server or generated static content. +Include diagrams in [Mermaid](https://mermaid.js.org) format using code blocks/fences, e.g. [test ADR 5](test/adr/0005-has-mermaid.md). ## Examples diff --git a/adr_viewer/__init__.py b/adr_viewer/__init__.py index b160455..69edf66 100644 --- a/adr_viewer/__init__.py +++ b/adr_viewer/__init__.py @@ -21,6 +21,7 @@ def generate_content(path, template_dir_override=None, title=None) -> str: config = { "project_title": title if title else os.path.basename(os.getcwd()), "records": [], + "include_mermaid": False, } for index, adr_file in enumerate(files): @@ -29,6 +30,8 @@ def generate_content(path, template_dir_override=None, title=None) -> str: if adr_attributes: adr_attributes.index = index + if not config["include_mermaid"]: + config["include_mermaid"] = adr_attributes.includes_mermaid config["records"].append(adr_attributes) else: diff --git a/adr_viewer/parse.py b/adr_viewer/parse.py index 7f072b4..1686db7 100644 --- a/adr_viewer/parse.py +++ b/adr_viewer/parse.py @@ -11,6 +11,7 @@ class Adr: status: str body: str index: int = 0 + includes_mermaid: bool = False def extract_statuses_from_adr(page_object) -> Iterator[str]: @@ -52,7 +53,14 @@ def parse_adr(content: str) -> Optional[Adr]: header = soup.find("h1") + includes_mermaid = soup.find(name="code", attrs={"class": "language-mermaid"}) + if header: - return Adr(header.text, status, adr_as_html) + return Adr( + title=header.text, + status=status, + body=adr_as_html, + includes_mermaid=includes_mermaid, + ) else: return None diff --git a/adr_viewer/templates/index.html b/adr_viewer/templates/index.html index 6ee5e72..01490dc 100644 --- a/adr_viewer/templates/index.html +++ b/adr_viewer/templates/index.html @@ -6,6 +6,9 @@ + {% if config.include_mermaid %} + + {% endif %}