# mdcx Markdown to Confluence XML converter with bidirectional sync for self-hosted Confluence Server/Data Center. Converts Markdown to [Confluence storage format](https://confluence.atlassian.com/doc/confluence-storage-format-790796544.html) XML and back. Pull pages from Confluence, edit locally as Markdown, push changes back. Template-aware embedding preserves metadata tables, changelogs, inline comment markers, user references, and attachment images through round-trips. ## Install ```bash go install go.bigb.es/confluence-md-utilities/cmd/mdcx@latest ``` Or build locally with [just](https://github.com/casey/just): ```bash just install ``` ## Commands ### convert Markdown to Confluence XML. ```bash mdcx convert input.md -o output.xml cat input.md | mdcx convert > output.xml ``` ### embed Convert Markdown and insert between marker comments in an existing Confluence document, preserving everything outside the markers (metadata table, TOC, changelog, etc.). ```bash mdcx embed input.md --template template.xml -o output.xml ``` Template must contain marker comments: ```xml ``` ### extract Extract content between markers from a Confluence XML document and convert back to Markdown. ```bash mdcx extract input.xml -o output.md mdcx extract input.xml --raw # raw Confluence XML, no conversion ``` ### pull Fetch a page from Confluence and convert to Markdown. ```bash mdcx pull "https://confluence.example.com/pages/viewpage.action?pageId=12345" -o page.md mdcx pull "https://confluence.example.com/display/TEAM/Page+Title" -o page.md mdcx pull "https://confluence.example.com/display/TEAM/Page+Title" --raw -o page.xml ``` ### push Convert local Markdown and update a Confluence page. ```bash # Replace entire page body mdcx push "https://confluence.example.com/display/TEAM/Page" page.md # Template mode: only replace content between markers, keep everything else mdcx push "https://confluence.example.com/display/TEAM/Page" page.md --template # With version message mdcx push "https://confluence.example.com/display/TEAM/Page" page.md -m "Updated intro" ``` ### fmt Pretty-print Confluence storage XML with syntax highlighting. ```bash mdcx fmt page.xml mdcx fmt page.xml --color=force # force colors even when piped mdcx fmt page.xml --color=disabled # no colors mdcx fmt page.xml -o formatted.xml # write to file (colors auto-disabled) ``` Colors: tags in blue/magenta/cyan by namespace, attributes in yellow, values in green, CDATA and comments in gray. Enabled by default when output is a terminal. Block elements get their own lines with indentation. Short `
` |
| Fenced code blocks | `` with CDATA |
| `- item` / `1. item` | `/` with `- ` |
| Nested lists | Nested `
/` inside `- ` |
| `- [x] task` | `
/` |
| `[text](url)` | `` |
| `` | ` ` |
| `> blockquote` | `` (info panel) |
| `---` | `
` |
| GFM tables | `` with `/ ` wrapped in `` |
## Round-trip preservation
Confluence-specific elements that have no Markdown equivalent are preserved through round-trips using HTML spans:
| Confluence element | Markdown representation |
|---|---|
| `` | `text` |
| ` ` | `` |
| ` ` | `` |
These are converted back to proper Confluence tags on push.
## License
MIT