improve to integrate to website
This commit is contained in:
parent
46af3c6fa9
commit
b90362a6e8
2 changed files with 27 additions and 5 deletions
26
exe/yamd
26
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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue