PlantUML Diagram Export Feature#106
Merged
Spenhouet merged 4 commits intoSpenhouet:mainfrom Jan 19, 2026
Merged
Conversation
# PlantUML Diagram Export Feature
## Summary
Successfully extended the Confluence Markdown Exporter to support exporting PlantUML diagrams from Confluence pages to Markdown code blocks.
## Changes Made
### 1. Added Dependencies
- **File**: `pyproject.toml`
- Added `lxml` package to project dependencies for XML parsing support
- This allows proper parsing of the Confluence `editor2` XML format
### 2. Core Implementation
- **File**: `confluence_markdown_exporter/confluence.py`
- Added `json` import for parsing PlantUML data structures
- Implemented `convert_plantuml()` method in the `Page.Converter` class
- Registered `plantuml` handler in the macro handlers dictionary
### 3. Test Coverage
- **File**: `tests/unit/test_plantuml_conversion.py` (new file)
- Created comprehensive test suite with 5 test cases:
- Basic PlantUML conversion
- Missing macro-id handling
- Complex diagram conversion
- Macro not found in editor2 handling
- Invalid JSON handling
## How It Works
1. **Detection**: When the exporter encounters a PlantUML macro in the Confluence HTML (identified by `data-macro-name="plantuml"`), it triggers the `convert_plantuml()` method
2. **XML Parsing**: The method parses the `editor2` XML format to find the corresponding PlantUML macro using the `macro-id` attribute
3. **Data Extraction**: Extracts the PlantUML definition from the JSON structure stored in the CDATA section of the `<ac:plain-text-body>` element
4. **Markdown Conversion**: Converts the UML definition to a Markdown code block with `plantuml` syntax highlighting
## Example
### Input (Confluence XML):
```xml
<ac:structured-macro ac:name="plantuml" ac:macro-id="123">
<ac:plain-text-body><![CDATA[{"umlDefinition":"@startuml\nAlice -> Bob: Hello\n@enduml"}]]></ac:plain-text-body>
</ac:structured-macro>
```
### Output (Markdown):
```plantuml
@startuml
Alice -> Bob: Hello
@enduml
```
## Error Handling
The implementation includes robust error handling for:
- Missing macro-id attributes
- Macro not found in editor2 XML
- Empty or missing content
- Invalid JSON parsing
- Missing UML definition in JSON
All error cases result in HTML comments in the output, allowing the export to continue without failing.
## Testing
All tests pass successfully:
- 5 PlantUML-specific tests
- 78 total unit tests (including existing tests)
Run tests with:
```bash
pytest tests/unit/test_plantuml_conversion.py -v
```
Owner
|
@izhyvaiev Thanks for the contribution. Looks like a great addition. I just added support for Mermaid diagrams via draw.io: #112 |
Owner
|
What PlantUML add-on is this expecting? |
Contributor
Author
|
@Spenhouet conflicts resolved. It's expecting - https://marketplace.atlassian.com/apps/1222993/flowchart-plantuml-diagrams-for-confluence |
Owner
|
@izhyvaiev Thank you for your contribution. This will be released with the next version. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PlantUML Diagram Export Feature
Summary
Successfully extended the Confluence Markdown Exporter to support exporting PlantUML diagrams from Confluence pages to Markdown code blocks.
Changes Made
1. Added Dependencies
pyproject.tomllxmlpackage to project dependencies for XML parsing supporteditor2XML format2. Core Implementation
confluence_markdown_exporter/confluence.pyjsonimport for parsing PlantUML data structuresconvert_plantuml()method in thePage.Converterclassplantumlhandler in the macro handlers dictionary3. Test Coverage
tests/unit/test_plantuml_conversion.py(new file)How It Works
Detection: When the exporter encounters a PlantUML macro in the Confluence HTML (identified by
data-macro-name="plantuml"), it triggers theconvert_plantuml()methodXML Parsing: The method parses the
editor2XML format to find the corresponding PlantUML macro using themacro-idattributeData Extraction: Extracts the PlantUML definition from the JSON structure stored in the CDATA section of the
<ac:plain-text-body>elementMarkdown Conversion: Converts the UML definition to a Markdown code block with
plantumlsyntax highlightingExample
Input (Confluence XML):
Output (Markdown):
Error Handling
The implementation includes robust error handling for:
All error cases result in HTML comments in the output, allowing the export to continue without failing.
Testing
All tests pass successfully: