I've recently been tinkering with KDE's wonderful mind mapper, KDissert, a concept organizer (for dissertations, presumably), and multi-format document generator.
I've been writing Wiki processors for a while now in PHP, and would love it if KDissert accepted some kind of Wiki markup. I don't have time to learn how to rewrite a KDE application at the moment, though, so a command-line hack will have to do the job.
So I wrote a ruby script wikify to transform a kdissert-generated HTML file, so that wiki markup was processed after-the-fact. It's a hack, but I'm finding it to be a very useful one.
Mostly a no-brainer. One caveat is that it doesn't handle Unicode characters in the HTML; if you cut and paste from word processing documents a lot, that may be an issue. I don't (much).
#!/usr/bin/ruby
if (f = ARGV[0])
if File.exist?(f)
# Read file
original = File.read(f)
str = original.clone
# Remove problem characters
str.gsub!(/'/, "'")
str.gsub!(/"/, '"')
str.gsub!(/type="disc">/, ">\n")
# Wikify characters
str.gsub!(/\\'a/, 'á')
str.gsub!(/\\`a/, 'à')
str.gsub!(/\\:a/, 'ä')
str.gsub!(/\\'e/, 'é')
str.gsub!(/\\`e/, 'è')
str.gsub!(/\\:e/, 'ë')
str.gsub!(/\\'i/, 'í')
str.gsub!(/\\`i/, 'ì')
str.gsub!(/\\:i/, 'ï')
str.gsub!(/\\~n/, 'ñ')
# Normal Wiki Markup
str.gsub!(/\/\/(\S[^\/]*\S)\/\//, '<i>\1</i>')
str.gsub!(/\*\*(\S[^\*]*\S)\*\*/, '<b>\1</b>')
str.gsub!(/\_\_(\S[^\_]*\S)\_\_/, '<u>\1</u>')
str.gsub!(/---/, '—')
str.gsub!(/--/, '–')
str.gsub!(/\(S\)/, '§')
str.gsub!(/\(C\)/, '©')
str.gsub!(/\(TM\)/, '™')
str.gsub!(/([\s\r\n])'/, '\1‘')
str.gsub!(/([\s\r\n])"/, '\1“')
str.gsub!(/'/, '’')
str.gsub!(/"/, '”')
# Rewrite Headers
str.gsub!(/<hr>/, '')
str.gsub!(/<p>>>\s*(.*)<\/p>/, '<address>\1</address>')
str.gsub!(/<p>>\s*(.*)<\/p>/, '<blockquote>\1</blockquote>')
str.gsub!(/<p>\^\s*(.*)<\/p>/, '<p class="indent">\1</p>')
# File management
str.gsub!(/<meta .*>/, '')
str.gsub!(/<link .*>/, '')
str.gsub!(/<\/head>/, "<link rel=\"STYLESHEET\" media=\"screen\" href=\"screen.css\" />\n<link rel=\"STYLESHEET\" media=\"print\" href=\"print.css\" />\n</head>")
# Write file
if(str != original)
File.new(f,"w").write(str)
end
elsif
printf "File '%s' not found", f
end
elsif
print "Syntax: ./wikify <file>"
end
Copyright: ©2000-07, Nigel Chapman · License: Creative Commons (some rights reserved) · Generator: TopicTree 0.8 · Generated: 29 Aug 2008, 11:54 am AEST · Page maintained by Kalessin · Last modified: 29 March 2007, 08:35 PM AEST · 14 ms · Not to be served, but to serve...