diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-12-23 17:59:02 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-12-23 17:59:02 +0100 |
commit | bdbf03e0e69e09233aaaf8cc417e26aa823d59bc (patch) | |
tree | 313dd8251fb259fad45a61b1f45e98d64619582e | |
parent | 29478965e00964b97d30a121634b40b0d7c4a30c (diff) | |
download | notyet-bdbf03e0e69e09233aaaf8cc417e26aa823d59bc.tar.gz notyet-bdbf03e0e69e09233aaaf8cc417e26aa823d59bc.tar.xz notyet-bdbf03e0e69e09233aaaf8cc417e26aa823d59bc.zip |
add ny2html
-rwxr-xr-x | ny2html | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/ny2html b/ny2html new file mode 100755 index 0000000..8bf7279 --- /dev/null +++ b/ny2html @@ -0,0 +1,54 @@ +#!/usr/bin/env ruby + +require 'date' +TODAY = Date.today + +class Entry < Struct.new(:depth, :state, :desc, :children) +end + +def parse(io, filename=nil) + todos = [Entry.new(-1, "/", "", [])] + + while line = io.gets + if line =~ /\A(?:\s*(?:#|\/\/)\s)?(\s*)([-xX?])\s+(.*)/ + i, state, desc = $1.size, $2, $3 + while i <= todos.last.depth + todos.pop + end + + e = Entry.new(i, state, desc, []) + todos.last.children << e + todos << e + end + end + + todos.first +end + +def render(e) + puts "<dl><dt>" + case e.state + when "-"; puts "☐" + when "x"; puts "☑" + when "X"; puts "☒" + when "?"; puts "?" # or 2370 + end + puts e.desc.sub(/(^\s*)\(([A-Z])\)/) { $1 + "<b>" + [$2.ord + 9333].pack("U") + "</b>" }. + gsub(/(?<=\s)@\w+/, '<i>\&</i>') + puts "</dt>" + unless e.children.empty? + puts "<dd>" + e.children.each { |c| + render(c) + } + puts "</dd>" + end + puts "</dl>" +end + +puts <<EOF +<!doctype html> +<meta charset=utf-8> +EOF +render(parse(STDIN)) + |