# tags.database.tml を texinfo 形式に変換する ruby スクリプト # environ/win32/kag3docs_in/tag/to_html.pl から移植 # # usage: # ruby -Ks to_texi.rb < tags.database.tml > kag-tag.texi def taganalysis(data, tag) contents = [] while data =~ Regexp.new("(<#{tag}[^>]+>)") taginfo = $1 $' =~ Regexp.new("") content = $` contents.push(taginfo + content) data = $' end contents end # extract text between tags # eg. text => text # # delete '', '' and zenkaku-space # substitute '
' => "\n" and '@' => '@@' def get_tag_text(data, tag) data =~ Regexp.new("<#{tag}>") $' =~ Regexp.new("") $` if $` $`.gsub(/|<\/ref>| /, '').gsub(/
/, "\n").gsub(/@/){'@@'} end end text = $<.readlines.map{|line| line.strip}.join tagdata = Hash.new() taganalysis(text, 'tag').each{|tagcontent| tagcontent =~ // tagname = $1 tagcontent = $' h = {} # get "shortinfo" h['shortinfo'] = get_tag_text(tagcontent, 'shortinfo') # get "group" h['group'] = get_tag_text(tagcontent, 'group') # get "remarks" h['remarks'] = get_tag_text(tagcontent, 'remarks') # get "example" example = get_tag_text(tagcontent, 'example') h['example'] = example if example # parse attrib if tagcontent =~ // $' =~ /<\/attribs>/ no = 0 attribs_data = [] taganalysis($`, 'attrib').each{|attribcontent| # get "attrib's name" attribcontent =~ /