From bdbf03e0e69e09233aaaf8cc417e26aa823d59bc Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Sat, 23 Dec 2017 17:59:02 +0100 Subject: add ny2html --- ny2html | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 ny2html 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 "
" + case e.state + when "-"; puts "☐" + when "x"; puts "☑" + when "X"; puts "☒" + when "?"; puts "?" # or 2370 + end + puts e.desc.sub(/(^\s*)\(([A-Z])\)/) { $1 + "" + [$2.ord + 9333].pack("U") + "" }. + gsub(/(?<=\s)@\w+/, '\&') + puts "
" + unless e.children.empty? + puts "
" + e.children.each { |c| + render(c) + } + puts "
" + end + puts "
" +end + +puts < + +EOF +render(parse(STDIN)) + -- cgit 1.4.1