diff --git a/exe/yamd b/exe/yamd index 5376ed8..f46d622 100755 --- a/exe/yamd +++ b/exe/yamd @@ -20,6 +20,7 @@ require 'bundler/setup' require 'pathname' +require 'optparse' require 'yamd' require 'yamd/code' @@ -93,7 +94,12 @@ class HTMLRenderer < YAMD::Renderer def tag(name, **attrs) @buf << "<#{name}" attrs.each { |k, v| - @buf << " " << k << "=" << v.dump + @buf << " " + if k.kind_of? Symbol + k = k.to_s + end + @buf << k + @buf << "=" << v.dump } @buf << ">" yield @@ -120,7 +126,21 @@ class HTMLRenderer < YAMD::Renderer end end -File.open(ARGV[0]) { |f| +options = { + :in => nil, + :out => nil, +} + +OptionParser.new do |opts| + opts.on '--out=FILE', 'Output file' + opts.on '--in=FILE', 'Input file' + opts.on '--help' do + puts opts + exit false + end +end.parse!(into: options) + +File.open(options[:in]) { |f| state = YAMD::State.new f ctx = YAMD::Context.new 0 @@ -132,6 +152,6 @@ File.open(ARGV[0]) { |f| renderer = HTMLRenderer.new eval(code).(renderer) - puts renderer.finalize + Pathname.new(options[:out]).write(renderer.finalize) } diff --git a/lib/yamd.rb b/lib/yamd.rb index 8267989..0db38b0 100644 --- a/lib/yamd.rb +++ b/lib/yamd.rb @@ -243,6 +243,7 @@ module YAMD end if state.line.start_with?("#!") + flushStrBuf.() state.consume(2) state.output.add_code_nl("__renderer." + state.line.strip + " {") @@ -252,6 +253,7 @@ module YAMD next elsif state.line.start_with?('#$') + flushStrBuf.() state.consume(2) line = state.line.strip @@ -270,9 +272,9 @@ module YAMD state.nextLine next - elsif state.line.start_with?("#. ") + elsif state.line.start_with?("#. ") or state.line == "#." flushStrBuf.() - state.consume(3) + state.consume(2) state.output.add_code_nl("__renderer.list_item {") parseContent state, ctx.indented