diff options
| author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-18 00:46:16 +0000 |
|---|---|---|
| committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-18 00:46:16 +0000 |
| commit | 6db079b0e7bfb3014f32bfb4e9ca5ddeed5b3bcf (patch) | |
| tree | 40585659bf4b9665ad0d258c415a6765a056d35d /lib/rdoc/markup/to_texinfo.rb | |
| parent | 7fe62665b40521438e9ea361b8b728ed4fa6c746 (diff) | |
| download | ruby-6db079b0e7bfb3014f32bfb4e9ca5ddeed5b3bcf.tar.gz ruby-6db079b0e7bfb3014f32bfb4e9ca5ddeed5b3bcf.tar.xz ruby-6db079b0e7bfb3014f32bfb4e9ca5ddeed5b3bcf.zip | |
Import RDoc r101.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc/markup/to_texinfo.rb')
| -rw-r--r-- | lib/rdoc/markup/to_texinfo.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/rdoc/markup/to_texinfo.rb b/lib/rdoc/markup/to_texinfo.rb new file mode 100644 index 000000000..533d3e34a --- /dev/null +++ b/lib/rdoc/markup/to_texinfo.rb @@ -0,0 +1,69 @@ +require 'rdoc/markup/formatter' +require 'rdoc/markup/fragments' +require 'rdoc/markup/inline' + +require 'rdoc/markup' +require 'rdoc/markup/formatter' + +## +# Convert SimpleMarkup to basic TexInfo format +# +# TODO: WTF is AttributeManager for? +# +class RDoc::Markup::ToTexInfo < RDoc::Markup::Formatter + + def start_accepting + @text = [] + end + + def end_accepting + @text.join("\n") + end + + def accept_paragraph(attributes, text) + @text << format(text) + end + + def accept_verbatim(attributes, text) + @text << "@verb{|#{format(text)}|}" + end + + def accept_heading(attributes, text) + heading = ['@majorheading', '@chapheading'][text.head_level - 1] || '@heading' + @text << "#{heading}{#{format(text)}}" + end + + def accept_list_start(attributes, text) + @text << '@itemize @bullet' + end + + def accept_list_end(attributes, text) + @text << '@end itemize' + end + + def accept_list_item(attributes, text) + @text << "@item\n#{format(text)}" + end + + def accept_blank_line(attributes, text) + @text << "\n" + end + + def accept_rule(attributes, text) + @text << '-----' + end + + def format(text) + text.txt. + gsub(/@/, "@@"). + gsub(/\{/, "@{"). + gsub(/\}/, "@}"). + # gsub(/,/, "@,"). # technically only required in cross-refs + gsub(/\+([\w]+)\+/, "@code{\\1}"). + gsub(/\<tt\>([^<]+)\<\/tt\>/, "@code{\\1}"). + gsub(/\*([\w]+)\*/, "@strong{\\1}"). + gsub(/\<b\>([^<]+)\<\/b\>/, "@strong{\\1}"). + gsub(/_([\w]+)_/, "@emph{\\1}"). + gsub(/\<em\>([^<]+)\<\/em\>/, "@emph{\\1}") + end +end |
