Skip to main content

A Markdown toolbox — convert, template, and publish Markdown documents

Project description

marksmith

A Markdown toolbox — write docs in Markdown, ship them as polished DOCX or publish them to Confluence.

PyPI Python CI License: MIT

Installation

pip install marksmith

Optional extras for template support:

pip install marksmith[template]

Optional extras for Confluence publishing:

pip install marksmith[confluence]

Quick start

# Explicit output path
marksmith to-docx my-doc.md output.docx

# Output path taken from docx-path in the file's front-matter
marksmith to-docx my-doc.md

# Recursively convert all .md files in a directory tree that have docx-path set
marksmith to-docx --directory docs/

# Or via python -m
python -m marksmith to-docx my-doc.md output.docx

Markdown front-matter

You can add a YAML front-matter block at the top of your Markdown file. The metadata is written to the DOCX core properties (title, author, etc.) and is also available as Jinja2 template variables when using --template.

---
title:          My Document
version:        1.0
author:         Fred Bloggs
date:           2026-03-16
classification: Internal
docx-path:      '%MY_DOCS%\Reports\My Document.docx'
---

# My Document

Content goes here...

docx-path

The optional docx-path key sets the default output path for marksmith to-docx. If you omit the output argument on the command line, the path from front-matter is used. Environment variables are expanded automatically (%VAR% on Windows, $VAR on Linux/macOS).

Windows paths: Always use single quotes around the value in YAML. In double-quoted YAML strings, backslashes are escape characters and will corrupt the path.

# ✅ Correct
docx-path: '%MY_DOCS%\Reports\myfile.docx'

# ❌ Wrong — \R and \m etc. are YAML escape sequences
docx-path: "%MY_DOCS%\Reports\myfile.docx"

Supported Markdown elements

Element Status
Headings H1 – H6
Bold / italic / inline code
Fenced and indented code blocks
Unordered lists (nested)
Ordered lists (nested)
Block-quotes
Tables
Thematic breaks (horizontal rules)
Strikethrough
Links (text rendered, no hyperlink) ⚠️
Images ⚠️ placeholder text only
Inline HTML ➖ ignored

Template support

Keep your content in plain Markdown while producing brand-consistent DOCX output from a corporate template.

pip install marksmith[template]
marksmith to-docx my-doc.md output.docx --template company-template.docx

MARKSMITH_TEMPLATE environment variable

If you always use the same template, set MARKSMITH_TEMPLATE once in your environment and marksmith will use it automatically — no --template argument needed. An explicit --template argument always takes priority.

# Windows (set permanently via System Properties → Environment Variables)
$env:MARKSMITH_TEMPLATE = "C:\Users\You\Templates\company-template.docx"

# Then just run — template is applied automatically
marksmith to-docx my-doc.md

How it works

  1. Create a .docx template in Word with Jinja2-style placeholders for metadata sourced from your Markdown front-matter:

    {{ title }}        {{ version }}      {{ author }}
    {{ date }}         {{ classification }}
    
  2. Add a {{p marksmith_content }} paragraph alone on its own line at the exact point where the Markdown body should be inserted:

    {{p marksmith_content }}
    

    Important: Use {{p ... }} (with the p modifier), not {{ ... }}. The p modifier inserts a paragraph-level sub-document rather than plain text, so all headings, lists, tables, and code blocks are preserved.

  3. Run the conversion — marksmith will:

    • Render all front-matter metadata into the Jinja2 placeholders.
    • Convert the Markdown body to native DOCX content.
    • Insert the body at {{p marksmith_content }}.
    • Save the merged document.

Style inheritance

Content is inserted as a sub-document, so heading and paragraph styles are matched by name against those in your template. If your template defines Heading 1 with a custom font and colour, the converted content will pick it up automatically.


Publishing to Confluence

Publish Markdown files directly to a Confluence space.

pip install marksmith[confluence]

Credentials

Create a .env file with your Confluence URL and a Personal Access Token. marksmith checks the following locations in order:

  1. .env in the current working directory
  2. .env in your home directory (~/.env on Linux/macOS, %USERPROFILE%\.env on Windows)
CONFLUENCE_URL=https://your-confluence.example.com
CONFLUENCE_TOKEN=your-personal-access-token

Front-matter fields

Each file must include a YAML front-matter block that tells marksmith where to publish the page:

---
title: My Page Title
space: MYSPACE
parent_title: My Parent Page   # resolved by title; or use parent_id: 12345
labels:
  - my-label
page-properties:
  description: A short description of this page
  created_by: Fred Bloggs
  version: "1.0"
  document_status: DRAFT       # DRAFT (yellow) | PUBLISHED (green) | other (red)
---

# My Page Title

Content goes here...
Field Required Description
title Yes Confluence page title
space Yes Confluence space key
parent_title One of Title of the parent page (resolved at publish time)
parent_id One of Numeric Confluence page ID of the parent
labels No List of labels to apply
page-properties No Renders a Page Properties macro at the top of the page

If the page already exists it is updated; otherwise it is created.

Commands

# Publish a single file
marksmith to-confluence --upload-file path/to/my-doc.md

# Publish all .md files in a directory
marksmith to-confluence --upload-directory path/to/docs/

# Publish a tree of repositories (each must have a confluence.yml at its root)
marksmith to-confluence --process-repo-tree path/to/repos/

Repository tree mode — confluence.yml

When using --process-repo-tree, each subdirectory that contains a confluence.yml is processed. The file defines the target space, parent page, and index page title for that repository:

repo-docs-path: docs/               # relative path to the docs directory
conflu-directory-title: My Service  # title of the index page created in Confluence
conflu-parent-id: "12345"           # Confluence page ID to create the index under
conflu-space-id: MYSPACE            # Confluence space key

All four fields are mandatory.

Additional features

Image attachments — local images referenced in Markdown are automatically uploaded as attachments to the published page.

Confluence link replacements — annotate a Markdown link with a <!-- replace_link(<page_id>) --> comment to rewrite it as a Confluence internal link at publish time:

[See related page](./other.md) <!-- replace_link(98765) -->

Roadmap

Action Description
to-docx Markdown → DOCX ✔️
to-docx --template Merge into branded DOCX template ✔️
to-docx (docx-path) Output path from front-matter docx-path key ✔️
to-docx --directory Recursively convert all files with docx-path set ✔️
to-confluence Publish Markdown to Confluence ✔️
lint Validate Markdown style and structure
toc Generate / update table of contents
diff Show structural diff between two Markdown files
Images Embed local images via run.add_picture()
Hyperlinks Full OOXML hyperlink support

Development

git clone https://github.com/tkdpython/marksmith
cd marksmith
pip install -e .[dev,template]

# Run tests
pytest

# Lint
ruff check .

Releasing

  1. Bump __version__ in marksmith/__init__.py.
  2. Commit and push.
  3. Create a GitHub Release with a tag matching the version (e.g. v0.2.0).
  4. The publish workflow fires automatically and publishes to PyPI via OIDC Trusted Publisher — no API tokens needed.

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

marksmith-0.5.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

marksmith-0.5.0-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file marksmith-0.5.0.tar.gz.

File metadata

  • Download URL: marksmith-0.5.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for marksmith-0.5.0.tar.gz
Algorithm Hash digest
SHA256 5b2836fd73f72b60460612dd7064f1a782682463f76622103ad65b0b1a2009c9
MD5 deccc712997dabfa44e77d0f3bf3b2aa
BLAKE2b-256 4b579197116ae57a095ae8e40313f436be120db0773f41b8ce3e36c1a70b725d

See more details on using hashes here.

Provenance

The following attestation bundles were made for marksmith-0.5.0.tar.gz:

Publisher: publish.yml on tkdpython/marksmith

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file marksmith-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: marksmith-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for marksmith-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08fb7c0ee6fb44f3a1a15f77451da7bfdc48fe67f2348c6e83c94853771b41b0
MD5 6eb2f4e8a2813ca74dc9759b8bff0d0c
BLAKE2b-256 6f3834786dd9b5d3f3e61e276677fbc3c99c989c5f42ce040e805de857b5a7d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for marksmith-0.5.0-py3-none-any.whl:

Publisher: publish.yml on tkdpython/marksmith

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page