From: "Shirai,Kaoru" Date: 2003-03-24T10:18:55+09:00 Subject: [ruby-list:37403] rd2plain-lib ----Next_Part(Mon_Mar_24_10:18:39_2003_520)-- Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit  白井です。  RD をプレインテキストに変換する rd2plain-lib を作成しました。 RD は ブロック要素だけならソースそのままでも十分読みやすいのですが、 (()) といったインライン要素が入ると読みにくい気がします。  README の生成用などに使っています。 使い方: # cp rd2plain-lib.rb \ `ruby -r rbconfig -e 'print Config::CONFIG["sitelibdir"]'`/rd/ $ rd2 -r rd/rd2plain-lib RDFILE -- shirai@korinkan.co.jp Shirai,Kaoru Korinkan Ltd. ----Next_Part(Mon_Mar_24_10:18:39_2003_520)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="rd2plain-lib.rb" require "rd/rdvisitor" module RD class RD2PLAINVisitor < RDVisitor include MethodParse SYSTEM_NAME = "RDtool -- Rd2plainVisitor" SYSTEM_VERSION = "$Version: 0.6.10$" #" VERSION = Version.new_from_version_string(SYSTEM_NAME, SYSTEM_VERSION) def self.version VERSION end # must-have constants OUTPUT_SUFFIX = "1" INCLUDE_SUFFIX = ["1"] def initialize end def apply_to_DocumentElement(element, content) content.join end def apply_to_Headline(element, title) title = title.join title_len = title.length line = case element.level when 1; "*" * (title_len + 16) when 2; "=" * (title_len + 8) when 3; "-" * (title_len + 4) else; "" end "#{title}\n#{line}\n\n" end # RDVisitor#apply_to_Include def apply_to_TextBlock(element, content) content.join << "\n" end def apply_to_Verbatim(element) element.content.join.gsub(/^/, " ") << "\n" end def apply_to_ItemList(element, items) content = "" items.each { |item| content << "* #{item}\n" } content << "\n" end def apply_to_EnumList(element, items) content = "" items.each_with_index { |item, index| num = sprintf("%2d.", index + 1) content << "#{num}. #{item}\n" } content << "\n" end def apply_to_ItemListItem(element, content) content.join("\n").gsub(/\n */, "\n ").strip end def apply_to_EnumListItem(element, content) content.join("\n").gsub(/\n */, "\n ").strip end def apply_to_DescList(element, items) items.join("\n") end def apply_to_MethodList(element, items) items.join("\n") end def apply_to_DescListItem(element, term, description) desc = description.join if desc.empty? "#{term}" else desc.gsub!(/^/, " ") "#{term}\n#{desc}" end end alias apply_to_MethodListItem apply_to_DescListItem def apply_to_Reference_with_RDLabel(element, content) content.join end def apply_to_Reference_with_URL(element, content) content.join end def apply_to_RefToElement(element, content) content.join end def apply_to_RefToOtherFile(element, content) content.join end def apply_to_Footnote(element, content) "" end def apply_to_String(element) element end def apply_to_StringElement(element, content = nil) content ||= element.content apply_to_String(content) end alias apply_to_Verb apply_to_StringElement alias apply_to_Emphasis apply_to_StringElement alias apply_to_Code apply_to_StringElement alias apply_to_Var apply_to_StringElement alias apply_to_Keyboard apply_to_StringElement alias apply_to_Index apply_to_StringElement end # RD2PLAINVisitor end # RD $Visitor_Class = RD::RD2PLAINVisitor ----Next_Part(Mon_Mar_24_10:18:39_2003_520)----