convert HTML to Dokuwiki (ruby)

This is an alpha script to convert HTML to Dokuwiki. I use this to cross-post from various sites.

It is completely unsupported and probably buggy. Please let me know if you have any improvements.


#!/usr/bin/ruby
# 20091015 Nic Suzor
# Available under CC BY-SA 2.5 (AU) http://creativecommons.org/licenses/by-sa/2.5/au/
#
# Alternatively, permission is granted to exercise any of the rights comprised
# in the copyright in this code, as long as the user agrees that it is provided with
# no warranty, express or implied, to the extent permissible by applicable law.

puts "this script will convert HTML to dokuwiki."
puts "\n"
puts "enter HTML. finish with '.'"

body = ''
read = gets
while read.chomp! != '.'
body = body + read
read = gets
end

# working: reformat links
body = body.gsub(/\[(.*?)\]\((.*?)\)/, '[[\2|\1]]')

# get rid of hard breaks
body = body.gsub(//,'')

# convert ... style footnotes
body = body.gsub(//,'((')
body = body.gsub(/<\/fn>/,'))')
body = body.gsub(/\)\)\)/, ').))')

# convert links to dokuwiki links
body = body.gsub(/
/, '[[\1|')
body = body.gsub(/<\/a>/,']]')

# convert to /emphasis/
body = body.gsub(//,'/')
body = body.gsub(/<\/em>/,'/')

# this is a hack. I couldn't be bothered extracting the ALT tag.
# convert links
body = body.gsub(//,'{{\2|\1}}')

# convert

and
to whitespace
body = body.gsub(/

/,"\n")
body = body.gsub(/<\/p>/,"\n")
body = body.gsub(/
/,"\n")
body = body.gsub(/
/,"\n")
# change
to '>'
body = body.gsub(/

/,'>')

# create lists
body = body.gsub(/

  • /, ' * ')

    # remove remaining tags
    body = body.gsub(/<(.*?)>/, '')

    puts "\n\nOutput:\n\n"
    puts body

    1. No comments yet.

    1. No trackbacks yet.