Coder Social home page Coder Social logo

md_to_conf's Introduction

Markdown to Confluence Converter

A script to import a named markdown document into Confluence.

It handles inline images as well as code blocks.

Also there is support for some custom markdown tags for use with commonly used Confluence macros.

The file will be converted into HTML or Confluence storage markup when required.

Then a page will be created in the space or if it already exists, the page will be uploaded.

Configuration

Download

Requirements

Python 3.6+

Python venv

The project code and dependencies can be used based on python virtualenv.

Create a new python virtualenv:

> python3 -m venv venv

Or in Anaconda

conda create --name md_to_conf python=3.7 --yes

Make the virtualenv active:

> source venv/bin/activate

Dependencies

Required python dependencies can be installed using:

pip3 install -r requirements.txt

Environment Variables

To use it, you will need your Confluence username, API key and organisation name. To generate an API key go to https://id.atlassian.com/manage/api-tokens.

You will also need the organization name that is used in the subdomain. For example the URL: https://fawltytowers.atlassian.net/wiki/ would indicate an organization name of fawltytowers.

If the organization name contains a dot, it will be considered as a Fully Qualified Domain Name. For example the URL: https://fawltytowers.mydomain.com/ would indicate an organization name of fawltytowers.mydomain.com.

These can be specified at runtime or set as Confluence environment variables (e.g. add to your ~/.profile or ~/.bash_profile on Mac OS):

export CONFLUENCE_USERNAME='basil'
export CONFLUENCE_API_KEY='abc123'
export CONFLUENCE_ORGNAME='fawltytowers'

On Windows, this can be set via system properties.

Use

Basic

The minimum accepted parameters are the markdown file to upload as well as the Confluence space key you wish to upload to. For the following examples assume 'Test Space' with key: TST.

python3 md2conf.py readme.md TST

Mandatory Confluence parameters can also be set here if not already set as environment variables:

  • -u --username: Confluence User
  • -p --apikey: Confluence API Key
  • -o --orgname: Confluence Organisation
python3 md2conf.py readme.md TST -u basil -p abc123 -o fawltytowers

Use -h to view a list of all available options.

Other Uses

Use -a or --ancestor to designate the name of a page which the page should be created under.

python md2conf.py readme.md TST -a "Parent Page Name"

Use -d or --delete to delete the page instead of create it. Obviously this won't work if it doesn't already exist.

Use -n or --nossl to specify a non-SSL url, i.e. http:// instead of https://.

Use -l or --loglevel to specify a different logging level, i.e DEBUG.

Use -s or --simulate to stop processing before interacting with confluence API, i.e. only converting the markdown document to confluence format.

Use --title to set the title for the page, otherwise the title is going to be the first line in the markdown file

Use --remove-emojies to emove emojies if there are any. This may be need if the database doesn't support emojies

Markdown

The original markdown to HTML conversion is performed by the Python markdown library. Additionally, the page name is taken from the first line of the markdown file, usually assumed to be the title. In the case of this document, the page would be called: Markdown to Confluence Converter.

Standard markdown syntax for images and code blocks will be automatically converted. The images are uploaded as attachments and the references updated in the HTML. The code blocks will be converted to the Confluence Code Block macro and also supports syntax highlighting.

Doctoc

If present, what is between the doctoc anchor format:

<!-- START doctoc ...
...
... END doctoc -->

will be replaced by confluence "toc" macro leading to something like:

<h2>Table of Content</h2>
<p>
    <ac:structured-macro ac:name="toc">
      <ac:parameter ac:name="printable">true</ac:parameter>
      <ac:parameter ac:name="style">disc</ac:parameter>
      <ac:parameter ac:name="maxLevel">7</ac:parameter>
      <ac:parameter ac:name="minLevel">1</ac:parameter>
      <ac:parameter ac:name="type">list</ac:parameter>
      <ac:parameter ac:name="outline">clear</ac:parameter>
      <ac:parameter ac:name="include">.*</ac:parameter>
    </ac:structured-macro>
    </p>

Information, Note and Warning Macros

Warning: Any blockquotes used will implement an information macro. This could potentially harm your formatting.

Block quotes in Markdown are rendered as information macros.

> This is an info

macros

> Note: This is a note

macros

> Warning: This is a warning

macros

Alternatively, using a custom Markdown syntax also works:

~?This is an info.?~

~!This is a note.!~

~%This is a warning.%~

Miscellaneous

    ╚⊙ ⊙╝
  ╚═(███)═╝
 ╚═(███)═╝
╚═(███)═╝
 ╚═(███)═╝
  ╚═(███)═╝
   ╚═(███)═╝

md_to_conf's People

Contributors

bhundven avatar borkur avatar dependabot[bot] avatar dvaerum avatar jean avatar jiuks avatar juancki avatar natestah avatar olegkarasik avatar pfrom-vizio avatar robinminto avatar ynaka81 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

md_to_conf's Issues

add requirements.txt for Library dependency management

Hi, Thank you for providing a good program!

I'm using this program very well.
By the way, there is one suggestion.
I need a library to run the program, do not you want to manage it as a file?
For example, frequently used requirements.txt.

If you do not mind, I am edit it and pull request.
Thank you again.

Final image on page used for all images

When converting an MD page (in our case an export of our Outline Wiki) it appears that the final image on the page is used for all images that are there.

For instance:

  • Image of dog
  • Image of another dog
  • Image of pack of dogs
  • Image of cat

All 4 images will be the image of cat instead of the (unique) other images.

Images are in the Markdown as such:

First
 ![](uploads/d7ae0a41-0d4b-4710-9f13-c40fb889b142/5d1fa456-68c9-4b55-bda6-7da3a0d8664a/image.png)

Second
 ![](uploads/d7ae0a41-0d4b-4710-9f13-c40fb889b142/12fe282c-aa18-43a4-90a9-aa5617b3801f/image.png)

The problem seems to be that it uploads all found images as image.png, overwriting the previous one

Support for a folder of md files

Would it be possible, using a -r flag to then iterate through all of the different .md files in a specified folder uploading them to the same space in confluence in a single query?

[Wishlist] Support for hosted instances

I see that the importer seems to expect to target a Confluence Cloud instance. It would be great if self-hosted Confluence instances (under an arbitrary domain) were also supported.

HTTPError: 500 Server Error (Local references werent processed)

I am using a self-hosted Confluence instance. This problem occurs when I am trying to update an existing Confluence Page.

INFO - update_page [629] - Updating page...
add_local_refs [464] - Local references werent processed because --markdownsrc wasnt set or specified source isnt supported

Request for adding comment to page history

Hello,
At the moment, md_to_conf.py has an argument called -v which specifies the version of the documentation on Confluence.
It would be very helpful if a new argument (-m/--message) can be added which gets the comment in the page history:
"version": { "message": VERSION_COMMENT, "number": VERSION_NUMBER }

Please escape > character

When your markdown contains > characters, the page update will fail with 400 Bad Request.
Only the closing ( '>' ) needs to be escaped. I recommend replacing it with '\>' before the conversion.

Pypi Package

It would be great to generate a Python package and make it available on Pypi.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.