Skip to main content

Convert Markdown documents to Confluence

Project description

md2cf

image

image

A library to convert documents written in Markdown to Confluence Storage format, and optionally upload them to a Confluence Server instance.

Features

  • Convert Markdown documents. The library implements a Mistune renderer that outputs Confluence Storage Format.
  • Basic Confluence API support. Embedded micro-implementation of the Confluence Server REST API with basic support for creating and updating pages.
  • Upload automation. Includes a small script that can automate the upload process for you.

Installation

pip install md2cf

Basic Usage

Renderer

Use the ConfluenceRenderer class to generate Confluence Storage Format output from a markdown document.

import mistune
from md2cf.confluence_renderer import ConfluenceRenderer

renderer = ConfluenceRenderer(use_xhtml=True)
confluence_mistune = mistune.Markdown(renderer=renderer)
confluence_body = confluence_mistune(markdown_data)

API

md2cf embeds a teeny-tiny implementation of the Confluence Server REST API that allows you to create, read, and update pages.

from md2cf.api import MinimalConfluence

confluence = MinimalConfluence(host='http://example.com/rest/api', username='foo', password='bar')

confluence.create_page(space='TEST', title='Test page', body='<p>Nothing</p>', message='Created page')

page = confluence.get_page(title='Test page', space_key='TEST')
confluence.update_page(page=page, body='New content', message='Changed page contents')

Upload script

In order to upload a document, you'll need to supply at least the following five parameters:

  • The hostname of your Confluence instance, including the path to the REST API (e.g. http://confluence.example.com/rest/api)
  • The username to use for logging into the instance
  • The corresponding password
  • The space on which to upload the page
  • The file(s) to be uploaded -- or standard input if the list is missing

Example basic usage:

md2cf --host 'https://confluence.example.com/rest/api' --username foo --password bar --space TEST document.md

Note that entering the password as a parameter on the command line is generally a bad idea. If you're running the script interactively, you can omit the --password parameter and the script will prompt for it.

In addition, for the security conscious out there or those who plan on using this as part of a pipeline, you can also supply the hostname, username, and password as environment variables: CONFLUENCE_HOST, CONFLUENCE_USERNAME, and CONFLUENCE_PASSWORD.

The title of the page will be the first top-level header found in the document (i.e. the first # header), or the filename if there are no top-level headers.

If you want to upload the page under a specific parent, supply the parent's page ID as the --parent parameter.

You can also optionally specify an update message to describe the change you just made by using the --message parameter.

If you want to update a page by page ID, use the --page-id option. This allows you to update the page's title, or to update a page with a title that is hard to use as a parameter.

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

md2cf-0.2.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

md2cf-0.2.2-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file md2cf-0.2.2.tar.gz.

File metadata

  • Download URL: md2cf-0.2.2.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for md2cf-0.2.2.tar.gz
Algorithm Hash digest
SHA256 b679be2652e8c9369b34d0ea6a6afe0b55309990b51e6bb4c87c6583afe3cd5b
MD5 ecd90c2035fd62124c21d611d06b682c
BLAKE2b-256 0e3e4d3c460f13e3a6e7a92d5fa24c0ab4a77f69e4a00a1cb53f7d7a3c75efcd

See more details on using hashes here.

File details

Details for the file md2cf-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: md2cf-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for md2cf-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2e02765f2b81260c45526d07dd92904b722b78015c48fcf3b8a4ba43702680ed
MD5 a95d2696e744f60ed32428c51888888e
BLAKE2b-256 ef11774c25cc03f55cdf52c0696ec2cd1c119ed94faeac2d5bdf460726f482a6

See more details on using hashes here.

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