Skip to content

Instantly share code, notes, and snippets.

@Vaguery
Forked from ttscoff/tp2md.rb
Last active January 3, 2016 21:59
Show Gist options
  • Save Vaguery/8525343 to your computer and use it in GitHub Desktop.
Save Vaguery/8525343 to your computer and use it in GitHub Desktop.
Trying to update for Ruby 1.9+
Test project 1:
- test task 2 @testTag
- test task 2
Test project 2:
- project 2 task 1
- project 2 task 3
Test sub project:
- sub project task 1 @testTag2
- sub project task 3
Test sub sub project:
- sub sub project task 1
- sub sub project task 3
Archive:
- test task 1 @testTag @testTag2 @done(2013-02-10) @project(Test project 1)
- sub project task 2 @testTag @done(2013-02-10) @project(Test project 2 / Test sub project)
- sub sub project task 2 @testTag2 @done(2013-02-10) @project(Test project 2 / Test sub project / Test sub sub project)
- project 2 task 2 @done(2013-02-04) @project(Test project 2)
# TaskPaper to Markdown converter
# Usage: tp2md.rb filename.taskpaper > output.md
# updated to use FileUtils lib instead of ftools
# removed explicit hashbang ruby library path (might need to replace, depending on your config)
require 'fileutils'
include FileUtils::Verbose
infile = ARGV[0]
title = File.basename(infile,'.taskpaper').upcase
output = "# #{title} #\n\n"
prevlevel = 0
begin
file = File.new(infile, "r")
while (line = file.gets)
if line =~ /^(\t+)?(.*?):(?:\s+)?$/
tabs = $1
project = $2
if tabs.nil?
output += "\n## #{project} ##\n\n"
prevlevel = 0
else
output += "#{tabs.gsub(/^\t/,'')}* **#{project}**\n"
prevlevel = tabs.length
end
elsif line =~ /^(\t+)?\- (.*)$/
task = $2
tabs = $1.nil? ? '' : $1
task = "*#{task}*" if task =~ /@done/
if tabs.length - prevlevel > 1
tabs = "\t"
prevlevel.times {|i| tabs += "\t"}
end
tabs = '' if prevlevel == 0 && tabs.length > 1
output += "#{tabs.gsub(/^\t/,'')}* #{task.strip}\n"
prevlevel = tabs.length
else
next if line =~ /^\s*$/
tabs = ""
prevlevel-1.times {|i| tabs += "\t"}
output += "#{tabs}> #{line.strip}\n\n"
end
end
file.close
rescue => err
puts "Exception: #{err}"
err
end
puts output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment