I'm looking for a tool or script to convert Markdown files to Dokuwiki format, that will run on a PC.

This is so that I can use MarkdownPad on a PC to create initial drafts of documents, and then convert them to Dokuwiki format, to upload to a Dokuwiki installation that I have no control over. (This means that the Markdown plugin is no use to me.)

I could spend time writing a Python script to do the conversion myself, but I'd like to avoid spending time on this, if such a thing exists already.

The Markdown tags I'd like to have supported/converted are:

  • Heading levels 1 - 5
  • Bold, italic, underline, fixed width font
  • Numbered and unnumbered lists
  • Hyperlinks
  • Horizontal rules

Does such a tool exist, or is there a good starting point available?

Things I've found and considered

  • Add filter to pandoc for DW output?! And, btw, for requested small subset you can try to start with pure Markdown in DW (did your read DW syntax rules?!) Mar 19, 2012 at 1:42
  • @LazyBadger Thanks. I just read johnmacfarlane.net/pandoc/scripting.html, and as far as I can see, it is about changing the Pandoc AST. I want to keep the AST unchanged, but change the output format. Or have I misunderstood? Mar 19, 2012 at 6:53
  • @LazyBadger Re your second suggestion, yes, I (believe I) know DW syntax very well! However, even if DW supported Markdown, I wish to convert the text to conventional DW syntax, for the sake of my colleagues who may edit it. Mar 19, 2012 at 6:57
  • I've just discovered there is a very brief Pandoc Issue requesting DokuWiki support. Mar 19, 2012 at 7:21
  • When I speak about pandoc integration, I have in mind "add additional writer", which, AFAICS, doesn't change core as MoinMoin reader shows - it's just additional Haskell script Mar 19, 2012 at 7:26

3 Answers 3


Stop-Press - August 2014

Since Pandoc 1.13, Pandoc now contains my implementation of DokuWiki writing - and many more features are implemented there than in this script. So this script is now pretty-much redundant.

Having originally said I didn't want to write a Python script to do the conversion, I ended up doing just that.

The real time-saving step was to use Pandoc to parse the Markdown text, and write out a JSON representation of the document. This JSON file was then mostly fairly easy to parse, and write out in DokuWiki format.

Below is the script, which implements the bits of Markdown and DokuWiki that I cared about - and a few more. (I've not uploaded the corresponding test suite that I wrote)

Requirements to use it:

  • Python (I was using 2.7 on Windows)
  • Pandoc installed, and pandoc.exe in your PATH (or edit the script to put in the full path to Pandoc instead)

I hope this saves someone else some time too...

Edit 2: 2013-06-26: I've now put this code into GitHub, at https://github.com/claremacrae/markdown_to_dokuwiki.py. Note that the code there adds support for more formats, and also contains a test suite.

Edit 1: adjusted to add code for parsing code samples in Markdown's backtick style:

# -*- coding: latin-1 -*-

import sys
import os
import json

__doc__ = """This script will read a text file in Markdown format,
and convert it to DokuWiki format.

The basic approach is to run pandoc to convert the markdown to JSON,
and then to parse the JSON output, and convert it to dokuwiki, which
is written to standard output

 - pandoc is in the user's PATH

# underlined, fixed-width
# Code quotes

list_depth = 0
list_depth_increment = 2

def process_list( list_marker, value ):
    global list_depth
    list_depth += list_depth_increment
    result = ""
    for item in value:
        result += '\n' + list_depth * unicode( ' ' ) + list_marker + process_container( item )
    list_depth -= list_depth_increment
    if list_depth == 0:
        result += '\n'
    return result

def process_container( container ):
    if isinstance( container, dict ):
        assert( len(container) == 1 )
        key = container.keys()[ 0 ]
        value = container.values()[ 0 ]
        if key == 'Para':
            return process_container( value ) + '\n\n'
        if key == 'Str':
            return value
        elif key == 'Header':
            level = value[0]
            marker = ( 7 - level ) * unicode( '=' )
            return marker + unicode(' ') + process_container( value[1] ) + unicode(' ') + marker + unicode('\n\n')
        elif key == 'Strong':
            return unicode('**') + process_container( value ) + unicode('**')
        elif key == 'Emph':
            return unicode('//') + process_container( value ) + unicode('//')
        elif key == 'Code':
            return unicode("''") + value[1] + unicode("''")
        elif key == "Link":
            url = value[1][0]
            return unicode('[[') + url + unicode('|') + process_container( value[0] ) + unicode(']]')
        elif key == "BulletList":
            return process_list( unicode( '* ' ), value)
        elif key == "OrderedList":
            return process_list( unicode( '- ' ), value[1])
        elif key == "Plain":
            return process_container( value )
        elif key == "BlockQuote":
            # There is no representation of blockquotes in DokuWiki - we'll just
            # have to spit out the unmodified text
            return '\n' + process_container( value ) + '\n'

        #elif key == 'Code':
        #    return unicode("''") + process_container( value ) + unicode("''")
            return unicode("unknown map key: ") + key + unicode( " value: " ) + str( value )

    if isinstance( container, list ):
        result = unicode("")
        for value in container:
            result += process_container( value )
        return result

    if isinstance( container, unicode ):
        if container == unicode( "Space" ):
            return unicode( " " )
        elif container == unicode( "HorizontalRule" ):
            return unicode( "----\n\n" )

    return unicode("unknown") + str( container )

def process_pandoc_jason( data ):
    assert( len(data) == 2 )
    result = unicode('')
    for values in data[1]:
        result += process_container( values )
    print result

def convert_file( filename ):
    # Use pandoc to parse the input file, and write it out as json
    tempfile = "temp_script_output.json"
    command = "pandoc --to=json \"%s\" --output=%s" % ( filename, tempfile )
    #print command
    os.system( command )

    input_file = open(tempfile, 'r' )
    input_text = input_file.readline()

    ## Parse the data
    data = json.loads( input_text )
    process_pandoc_jason( data )

def main( files ):
    for filename in files:
        convert_file( filename )

if __name__ == "__main__":
    files = sys.argv[1:]

    if len( files ) == 0:
        sys.stderr.write( "Supply one or more filenames to convert on the command line\n" )
        return_code = 1
        main( files )
        return_code = 0

    sys.exit( return_code )
  • @OliverSalzburg You're welcome. (BTW, I just noticed a cosmetic typo: s/jason/json/ in several places... :-) ) Apr 3, 2012 at 13:24

This is an alternative approach I've been using recently.

Its advantages are:

  • it converts a much wider range of MarkDown syntax than the Python script in my other answer
  • it doesn't require python to be installed
  • it doesn't require pandoc to be installed

The recipe:

  1. Open the Markdown file in MarkdownPad 2

    MarkdownPad 2 Screenshot

  2. Select Edit -> "Copy Document as HTML"

  3. Run Html2DokuWiki

    HTML to DokuWiki Screenshot

  4. Paste the HTML into the top "HTML Input" pane

  5. Select All, and Copy all the text in the bottom "DokuWiki Output" pane


Not ideal, but functional solution

Markdown -> HTML -> Dokuwiki

First conversion done by pandoc

Second - HTML-WikiConverter-DokuWiki Perl module

Hint: Reversing actions of existing code

silverstripe-doc-restructuring git-repo contain code (PHP) for converting from Dokuwiki to Markdown

  • I tried this out, but, not being familiar with Perl, I didn't come close to getting the module to work. Apr 2, 2012 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.