improve to integrate to website

This commit is contained in:
kp2pml30 2025-03-20 22:23:30 +04:00
parent 46af3c6fa9
commit b90362a6e8
2 changed files with 27 additions and 5 deletions

View file

@ -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)
}