Skip to content

Add draw.io diagram export as PNG#1

Merged
splieth merged 2 commits intomainfrom
feature/drawio
Mar 27, 2026
Merged

Add draw.io diagram export as PNG#1
splieth merged 2 commits intomainfrom
feature/drawio

Conversation

@splieth
Copy link
Copy Markdown
Owner

@splieth splieth commented Mar 27, 2026

Export draw.io diagrams embedded in Confluence pages as PNG images alongside the Markdown files. Diagrams are automatically downloaded from page attachments and referenced as inline images in the output.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for exporting draw.io diagrams embedded in Confluence pages by downloading the corresponding PNG attachments and converting draw.io macros into inline image references in the generated Markdown.

Changes:

  • Introduce attachment fetching/downloading in the Confluence client layer.
  • Add draw.io macro detection + replacement in the renderer and thread the Confluence client through export APIs.
  • Add renderer tests for draw.io handling and bump package metadata/versioning.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
uv.lock Bumps locked package version to 0.2.0.
src/confluence2md/renderer.py Replaces draw.io macros with image tags and downloads PNG attachments during export.
src/confluence2md/client.py Adds Attachment model plus fetch_attachments and download_attachment helpers.
src/confluence2md/cli.py Passes Confluence client through to export functions so diagrams can be processed.
tests/test_renderer.py Adds unit tests covering draw.io macro parsing, PNG selection, and export behavior.
pyproject.toml Adds readme metadata and updates version to 0.2.0.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/confluence2md/renderer.py
Comment thread src/confluence2md/renderer.py
Comment thread src/confluence2md/renderer.py
Comment thread src/confluence2md/renderer.py
Comment thread src/confluence2md/client.py
Comment thread src/confluence2md/client.py
@splieth
Copy link
Copy Markdown
Owner Author

splieth commented Mar 27, 2026

@copilot apply changes based on the comments in this thread

@splieth splieth merged commit 6a6eecd into main Mar 27, 2026
6 of 7 checks passed
Copy link
Copy Markdown

Copilot AI commented Mar 27, 2026

@copilot apply changes based on the comments in this thread

All review feedback has been applied in commit 1932010 (local), but the push is blocked because PR #1 was already merged and feature/drawio is now a protected ref. These improvements would need to go into a new PR on top of main.

Here's a summary of every change made:

src/confluence2md/renderer.py

  • _find_drawio_png: now filters by media_type == "image/png" and does case-insensitive title matching, so a non-PNG attachment with a .png name is correctly skipped.
  • export_page: creates a per-page assets subdirectory (output_dir/{page_slug}/) so diagram attachments from different pages never overwrite each other.
  • _process_drawio_macros: (a) renamed html param to body to avoid shadowing the stdlib html module; (b) downloads each attachment only once per page using a downloaded: dict[str, str] cache keyed by attachment ID; (c) uses html.escape() on both the src and alt attribute values to prevent HTML injection from user-controlled Confluence content; (d) uses Path(title).name to strip directory separators from filenames before building the relative src path.

src/confluence2md/client.py

  • download_attachment: uses Path(attachment.title).name to strip any ../ path-traversal components before writing to disk.

tests/test_client.py

  • Added test_fetch_attachments, test_fetch_attachments_empty, test_fetch_attachments_multiple — cover response parsing including _links.download and metadata.mediaType.
  • Added test_download_attachment, test_download_attachment_creates_directory, test_download_attachment_prevents_path_traversal — verify correct file path, directory creation, and that ../evil/file.png writes only inside the destination directory.

tests/test_renderer.py

  • Updated test_process_drawio_macros to pass a real Path and assert the per-page subdirectory prefix in the src.
  • Updated test_export_page_with_drawio to assert ![Architecture](Diagrams/Architecture.png) (reflecting the subdirectory).
  • Added test_find_drawio_png_wrong_media_type_skipped — non-image/png attachment with matching name is ignored.
  • Added test_find_drawio_png_case_insensitiveARCHITECTURE.PNG matches diagram name Architecture.
  • Added test_process_drawio_macros_deduplicates_downloads — same diagram referenced twice triggers only one download call.

All 54 tests pass and CodeQL reports no alerts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants