TaskPaper to HTML applescript

Posted June 27, 2008 by jesse in applescript

Here's a quick (and messy) script that converts a taskpaper document to HTML unordered lists.

Updated Added some class attributes to list items based on entry type.


property html : ""

tell front document of application "TaskPaper"
    set html to html & "<ul>" & return
    repeat with eachProject in projects
        tell me to writeEntry(eachProject)
    end repeat
    set html to html & "</ul>" & return
    html
end tell

on writeEntry(eachEntry)
    using terms from application "TaskPaper"
        set t to entry type of eachEntry
        if t = task type then
            set html to html & "<li class='task'>" & text string of eachEntry & "</li>" & return
        else if t = note type then
            set html to html & "<li class='note'>" & text string of eachEntry & "</li>" & return
        else if t = project type then
            set html to html & "<li class='project'>" & text string of eachEntry & "</li>" & return
        end if

        tell eachEntry
            if (count of entries) > 0 then
                set html to html & "<ul>" & return
                repeat with eachChildEntry in entries
                    tell me to writeEntry(eachChildEntry)
                end repeat
                set html to html & "</ul>" & return
            end if
        end tell
    end using terms from
end writeEntry