File: to_texinfo.rb

package info (click to toggle)
jruby 1.5.1-1%2Bdeb6u1
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze-lts
  • size: 47,024 kB
  • ctags: 74,144
  • sloc: ruby: 398,155; java: 169,506; yacc: 3,782; xml: 2,469; ansic: 415; sh: 279; makefile: 78; tcl: 40
file content (69 lines) | stat: -rw-r--r-- 1,550 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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