From fb67f6989dc2cabe60498e0e7b8f7a51e1e9826b Mon Sep 17 00:00:00 2001 From: Eugene Blikh Date: Wed, 25 Mar 2026 23:32:46 +0300 Subject: [PATCH] =?UTF-8?q?Initial=20commit:=20mdcx=20=E2=80=94=20Markdown?= =?UTF-8?q?=20to=20Confluence=20XML=20converter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bidirectional converter between Markdown and Confluence storage format XML with self-hosted Confluence Server/Data Center sync support. Features: - convert: Markdown → Confluence XML - extract: Confluence XML → Markdown - embed: embed Markdown into Confluence XML template (marker-based) - pull/push: sync pages with Confluence via REST API + PAT auth - fmt: pretty-print Confluence XML with sensible indentation - Round-trip preservation of inline comments, user refs, attachment images false --- .gitignore | 18 + README.md | 128 +++++++ api/client.go | 35 ++ api/client_test.go | 183 ++++++++++ api/content.go | 179 ++++++++++ api/url.go | 76 ++++ api/url_test.go | 78 ++++ cmd/convert.go | 49 +++ cmd/embed.go | 81 +++++ cmd/extract.go | 77 ++++ cmd/fmt.go | 57 +++ cmd/pull.go | 78 ++++ cmd/push.go | 110 ++++++ cmd/root.go | 35 ++ confluence/elements.go | 50 +++ confluence/renderer.go | 477 +++++++++++++++++++++++++ converter/md2xml.go | 35 ++ converter/md2xml_test.go | 436 +++++++++++++++++++++++ converter/xml2md.go | 746 +++++++++++++++++++++++++++++++++++++++ format/pretty.go | 493 ++++++++++++++++++++++++++ format/pretty_test.go | 161 +++++++++ go.mod | 18 + go.sum | 23 ++ main.go | 7 + template/embed.go | 31 ++ template/embed_test.go | 64 ++++ template/extract.go | 24 ++ template/extract_test.go | 49 +++ template/markers.go | 6 + testdata/sample.md | 48 +++ 30 files changed, 3852 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 api/client.go create mode 100644 api/client_test.go create mode 100644 api/content.go create mode 100644 api/url.go create mode 100644 api/url_test.go create mode 100644 cmd/convert.go create mode 100644 cmd/embed.go create mode 100644 cmd/extract.go create mode 100644 cmd/fmt.go create mode 100644 cmd/pull.go create mode 100644 cmd/push.go create mode 100644 cmd/root.go create mode 100644 confluence/elements.go create mode 100644 confluence/renderer.go create mode 100644 converter/md2xml.go create mode 100644 converter/md2xml_test.go create mode 100644 converter/xml2md.go create mode 100644 format/pretty.go create mode 100644 format/pretty_test.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go create mode 100644 template/embed.go create mode 100644 template/embed_test.go create mode 100644 template/extract.go create mode 100644 template/extract_test.go create mode 100644 template/markers.go create mode 100644 testdata/sample.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..c831e24ee96c95715d688960f0d41bb060a38829 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +# Binary +mdcx + +# Example/test Confluence documents (not part of the project) +0-root.xml +rfc-111.xml +rfc-111.md + +# IDE +.idea/ +.vscode/ +*.swp +*.swo +*~ + +# OS +.DS_Store +Thumbs.db diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..1077af578ce879ef425f517d447872d57ae4bf89 --- /dev/null +++ b/README.md @@ -0,0 +1,128 @@ +# mdcx + +Markdown to Confluence XML converter with bidirectional sync support 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. Supports pulling pages from Confluence, editing locally as Markdown, and pushing changes back — with template-aware embedding that preserves metadata tables, changelogs, and inline comment markers. + +## Install + +```bash +go install sourcecraft.dev/bigbes/markdown-to-confluence-xml@latest +``` + +The binary is named `mdcx`. + +## Commands + +### `convert` — Markdown to Confluence XML + +```bash +mdcx convert input.md -o output.xml +cat input.md | mdcx convert > output.xml +``` + +### `embed` — Embed Markdown into a Confluence XML template + +Converts Markdown and inserts it 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 +``` + +The template must contain marker comments: + +```xml + + +``` + +### `extract` — Extract Markdown from Confluence XML + +Extracts content between markers and converts back to Markdown. + +```bash +mdcx extract input.xml -o output.md +mdcx extract input.xml --raw # output raw Confluence XML +``` + +### `pull` — Pull a page from Confluence + +```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` — Push Markdown to a Confluence page + +```bash +# Replace entire page body +mdcx push "https://confluence.example.com/display/TEAM/Page+Title" page.md + +# Template mode: replace only content between markers +mdcx push "https://confluence.example.com/display/TEAM/Page+Title" page.md --template + +# With version message +mdcx push "https://confluence.example.com/display/TEAM/Page+Title" page.md -m "Updated intro section" +``` + +## Authentication + +For `pull` and `push`, provide a [Personal Access Token](https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html) via: + +- `--token` flag, or +- `CONFLUENCE_TOKEN` environment variable + +```bash +export CONFLUENCE_TOKEN="your-token-here" +mdcx pull "https://confluence.example.com/display/TEAM/RFC-42" -o rfc.md +``` + +## Typical workflow + +```bash +export CONFLUENCE_TOKEN="..." + +# Pull page to local Markdown +mdcx pull "https://confluence.example.com/display/TEAM/RFC-42" -o rfc.md + +# Edit locally +vim rfc.md + +# Push back, preserving template structure +mdcx push "https://confluence.example.com/display/TEAM/RFC-42" rfc.md --template -m "Updated requirements" +``` + +## Supported elements + +| Markdown | Confluence XML | +|---|---| +| `# Heading` | `

` ... `

` | +| `**bold**` | `` | +| `*italic*` | `` | +| `~~strike~~` | `` | +| `` `code` `` | `` | +| Fenced code blocks | `` with CDATA | +| `- item` / `1. item` | `