Next · Nethack Navigation · Home > Etcetera > Techology > Mindmaps

Wikifying KDissert Mindmaps

Page contents
1.  KDissert

I've recently been tinkering with KDE's wonderful mind mapper, KDissert, a concept organizer (for dissertations, presumably), and multi-format document generator.

Add a linkOne link in this section
KDissert Homepage
Also SemantiK, the anticipated KDE4 rewrite.
Add a link 2.  Wikify (Ruby)

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.

  • Control characters at the start of paragraphs transform the paragraph tags. e.g. '>' creates a blockquote, '>>' a reference line (using <address>), '^' a hanging indent suitable for bibliographies.
  • **bold**, //italic//, etc
  • Extended characters like é or ï are added LaTeX-style as \'e or \:i
  • Smart quotes are applied
  • It changes the headers to use by own screen/print stylesheets.
  • ... and so on

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).

wikify

#!/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!(/&apos;/, "'")
        str.gsub!(/&quot;/, '"')
        str.gsub!(/type="disc">/, ">\n")

        # Wikify characters
        str.gsub!(/\\'a/, '&aacute;')
        str.gsub!(/\\`a/, '&agrave;')
        str.gsub!(/\\:a/, '&auml;')
        str.gsub!(/\\'e/, '&eacute;')
        str.gsub!(/\\`e/, '&egrave;')
        str.gsub!(/\\:e/, '&euml;')
        str.gsub!(/\\'i/, '&iacute;')
        str.gsub!(/\\`i/, '&igrave;')
        str.gsub!(/\\:i/, '&iuml;')
        str.gsub!(/\\~n/, '&ntilde;')

        # 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!(/---/, '&mdash;')
        str.gsub!(/--/, '&ndash;')
        str.gsub!(/\(S\)/, '&sect;')
        str.gsub!(/\(C\)/, '&copy;')
        str.gsub!(/\(TM\)/, '&trade;')
        str.gsub!(/([\s\r\n])'/, '\1&lsquo;')
        str.gsub!(/([\s\r\n])"/, '\1&ldquo;')
        str.gsub!(/'/, '&rsquo;')
        str.gsub!(/"/, '&rdquo;')

        # Rewrite Headers
        str.gsub!(/<hr>/, '')
        str.gsub!(/<p>&gt;&gt;\s*(.*)<\/p>/, '<address>\1</address>')
        str.gsub!(/<p>&gt;\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
Email editors · Add feedback No feedback items for this page
Top of page About this page · Display