voloko-sdoc 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/rdoc/History.txt +254 -0
- data/rdoc/Manifest.txt +126 -0
- data/rdoc/README.txt +47 -0
- data/rdoc/RI.txt +58 -0
- data/rdoc/Rakefile +70 -0
- data/rdoc/bin/rdoc +35 -0
- data/rdoc/bin/ri +5 -0
- data/rdoc/lib/rdoc/alias.rb +54 -0
- data/rdoc/lib/rdoc/anon_class.rb +10 -0
- data/rdoc/lib/rdoc/any_method.rb +190 -0
- data/rdoc/lib/rdoc/attr.rb +79 -0
- data/rdoc/lib/rdoc/cache.rb +41 -0
- data/rdoc/lib/rdoc/class_module.rb +87 -0
- data/rdoc/lib/rdoc/code_object.rb +152 -0
- data/rdoc/lib/rdoc/code_objects.rb +23 -0
- data/rdoc/lib/rdoc/constant.rb +36 -0
- data/rdoc/lib/rdoc/context.rb +712 -0
- data/rdoc/lib/rdoc/diagram.rb +340 -0
- data/rdoc/lib/rdoc/dot.rb +249 -0
- data/rdoc/lib/rdoc/generator/darkfish.rb +455 -0
- data/rdoc/lib/rdoc/generator/markup.rb +194 -0
- data/rdoc/lib/rdoc/generator/ri.rb +230 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/classpage.rhtml +281 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/filepage.rhtml +112 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/brick.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/brick_link.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/bug.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/bullet_black.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/bullet_toggle_minus.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/bullet_toggle_plus.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/date.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/find.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/loadingAnimation.gif +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/macFFBgHack.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/package.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/page_green.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/page_white_text.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/page_white_width.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/plugin.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/ruby.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/tag_green.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/wrench.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/wrench_orange.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/images/zoom.png +0 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/index.rhtml +64 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/js/darkfish.js +116 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/js/jquery.js +32 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/js/quicksearch.js +114 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/js/thickbox-compressed.js +10 -0
- data/rdoc/lib/rdoc/generator/template/darkfish/rdoc.css +696 -0
- data/rdoc/lib/rdoc/generator.rb +8 -0
- data/rdoc/lib/rdoc/ghost_method.rb +8 -0
- data/rdoc/lib/rdoc/include.rb +39 -0
- data/rdoc/lib/rdoc/known_classes.rb +68 -0
- data/rdoc/lib/rdoc/markup/attribute_manager.rb +311 -0
- data/rdoc/lib/rdoc/markup/formatter.rb +25 -0
- data/rdoc/lib/rdoc/markup/fragments.rb +377 -0
- data/rdoc/lib/rdoc/markup/inline.rb +126 -0
- data/rdoc/lib/rdoc/markup/lines.rb +156 -0
- data/rdoc/lib/rdoc/markup/preprocess.rb +80 -0
- data/rdoc/lib/rdoc/markup/to_flow.rb +211 -0
- data/rdoc/lib/rdoc/markup/to_html.rb +406 -0
- data/rdoc/lib/rdoc/markup/to_html_crossref.rb +140 -0
- data/rdoc/lib/rdoc/markup/to_latex.rb +328 -0
- data/rdoc/lib/rdoc/markup/to_test.rb +53 -0
- data/rdoc/lib/rdoc/markup/to_texinfo.rb +73 -0
- data/rdoc/lib/rdoc/markup.rb +378 -0
- data/rdoc/lib/rdoc/meta_method.rb +8 -0
- data/rdoc/lib/rdoc/normal_class.rb +18 -0
- data/rdoc/lib/rdoc/normal_module.rb +34 -0
- data/rdoc/lib/rdoc/options.rb +542 -0
- data/rdoc/lib/rdoc/parser/c.rb +678 -0
- data/rdoc/lib/rdoc/parser/perl.rb +165 -0
- data/rdoc/lib/rdoc/parser/ruby.rb +2904 -0
- data/rdoc/lib/rdoc/parser/simple.rb +39 -0
- data/rdoc/lib/rdoc/parser.rb +138 -0
- data/rdoc/lib/rdoc/rdoc.rb +375 -0
- data/rdoc/lib/rdoc/require.rb +32 -0
- data/rdoc/lib/rdoc/ri/cache.rb +187 -0
- data/rdoc/lib/rdoc/ri/descriptions.rb +156 -0
- data/rdoc/lib/rdoc/ri/display.rb +340 -0
- data/rdoc/lib/rdoc/ri/driver.rb +828 -0
- data/rdoc/lib/rdoc/ri/formatter.rb +654 -0
- data/rdoc/lib/rdoc/ri/paths.rb +93 -0
- data/rdoc/lib/rdoc/ri/reader.rb +106 -0
- data/rdoc/lib/rdoc/ri/util.rb +79 -0
- data/rdoc/lib/rdoc/ri/writer.rb +68 -0
- data/rdoc/lib/rdoc/ri.rb +8 -0
- data/rdoc/lib/rdoc/single_class.rb +8 -0
- data/rdoc/lib/rdoc/stats.rb +178 -0
- data/rdoc/lib/rdoc/task.rb +276 -0
- data/rdoc/lib/rdoc/tokenstream.rb +33 -0
- data/rdoc/lib/rdoc/top_level.rb +242 -0
- data/rdoc/lib/rdoc.rb +398 -0
- metadata +1 -1
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'rdoc/markup/to_html'
|
2
|
+
|
3
|
+
##
|
4
|
+
# Subclass of the RDoc::Markup::ToHtml class that supports looking up words
|
5
|
+
# from a context. Those that are found will be hyperlinked.
|
6
|
+
|
7
|
+
class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
|
8
|
+
|
9
|
+
##
|
10
|
+
# Regular expressions to match class and method references.
|
11
|
+
#
|
12
|
+
# 1) There can be a '\' in front of text to suppress any cross-references
|
13
|
+
# 2) There can be a '::' in front of class names to reference from the
|
14
|
+
# top-level namespace.
|
15
|
+
# 3) The method can be followed by parenthesis which may
|
16
|
+
|
17
|
+
CLASS_REGEXP_STR = '\\\\?((?:\:{2})?[A-Z]\w*(?:\:\:\w+)*)'
|
18
|
+
METHOD_REGEXP_STR = '(\w+[!?=]?)(?:\([\.\w+\*\/\+\-\=\<\>]*\))?'
|
19
|
+
|
20
|
+
##
|
21
|
+
# Regular expressions matching text that should potentially have
|
22
|
+
# cross-reference links generated are passed to add_special. Note that
|
23
|
+
# these expressions are meant to pick up text for which cross-references
|
24
|
+
# have been suppressed, since the suppression characters are removed by the
|
25
|
+
# code that is triggered.
|
26
|
+
|
27
|
+
CROSSREF_REGEXP = /(
|
28
|
+
# A::B::C.meth
|
29
|
+
#{CLASS_REGEXP_STR}[\.\#]#{METHOD_REGEXP_STR}
|
30
|
+
|
31
|
+
# Stand-alone method (proceeded by a #)
|
32
|
+
| \\?\##{METHOD_REGEXP_STR}
|
33
|
+
|
34
|
+
# A::B::C
|
35
|
+
# The stuff after CLASS_REGEXP_STR is a
|
36
|
+
# nasty hack. CLASS_REGEXP_STR unfortunately matches
|
37
|
+
# words like dog and cat (these are legal "class"
|
38
|
+
# names in Fortran 95). When a word is flagged as a
|
39
|
+
# potential cross-reference, limitations in the markup
|
40
|
+
# engine suppress other processing, such as typesetting.
|
41
|
+
# This is particularly noticeable for contractions.
|
42
|
+
# In order that words like "can't" not
|
43
|
+
# be flagged as potential cross-references, only
|
44
|
+
# flag potential class cross-references if the character
|
45
|
+
# after the cross-referece is a space or sentence
|
46
|
+
# punctuation.
|
47
|
+
| #{CLASS_REGEXP_STR}(?=[\s\)\.\?\!\,\;]|\z)
|
48
|
+
|
49
|
+
# Things that look like filenames
|
50
|
+
# The key thing is that there must be at least
|
51
|
+
# one special character (period, slash, or
|
52
|
+
# underscore).
|
53
|
+
| [\/\w]+[_\/\.][\w\/\.]+
|
54
|
+
|
55
|
+
# Things that have markup suppressed
|
56
|
+
| \\[^\s]
|
57
|
+
)/x
|
58
|
+
|
59
|
+
##
|
60
|
+
# RDoc::CodeObject for generating references
|
61
|
+
|
62
|
+
attr_accessor :context
|
63
|
+
|
64
|
+
##
|
65
|
+
# Creates a new crossref resolver that generates links relative to +context+
|
66
|
+
# which lives at +from_path+ in the generated files. '#' characters on
|
67
|
+
# references are removed unless +show_hash+ is true.
|
68
|
+
|
69
|
+
def initialize(from_path, context, show_hash)
|
70
|
+
raise ArgumentError, 'from_path cannot be nil' if from_path.nil?
|
71
|
+
super()
|
72
|
+
|
73
|
+
@markup.add_special(CROSSREF_REGEXP, :CROSSREF)
|
74
|
+
|
75
|
+
@from_path = from_path
|
76
|
+
@context = context
|
77
|
+
@show_hash = show_hash
|
78
|
+
|
79
|
+
@seen = {}
|
80
|
+
end
|
81
|
+
|
82
|
+
##
|
83
|
+
# We're invoked when any text matches the CROSSREF pattern (defined in
|
84
|
+
# MarkUp). If we find the corresponding reference, generate a hyperlink.
|
85
|
+
# If the name we're looking for contains no punctuation, we look for it up
|
86
|
+
# the module/class chain. For example, HyperlinkHtml is found, even without
|
87
|
+
# the Generator:: prefix, because we look for it in module Generator first.
|
88
|
+
|
89
|
+
def handle_special_CROSSREF(special)
|
90
|
+
name = special.text
|
91
|
+
|
92
|
+
# This ensures that words entirely consisting of lowercase letters will
|
93
|
+
# not have cross-references generated (to suppress lots of erroneous
|
94
|
+
# cross-references to "new" in text, for instance)
|
95
|
+
return name if name =~ /\A[a-z]*\z/
|
96
|
+
|
97
|
+
return @seen[name] if @seen.include? name
|
98
|
+
|
99
|
+
if name[0, 1] == '#' then
|
100
|
+
lookup = name[1..-1]
|
101
|
+
name = lookup unless @show_hash
|
102
|
+
else
|
103
|
+
lookup = name
|
104
|
+
end
|
105
|
+
|
106
|
+
# Find class, module, or method in class or module.
|
107
|
+
#
|
108
|
+
# Do not, however, use an if/elsif/else chain to do so. Instead, test
|
109
|
+
# each possible pattern until one matches. The reason for this is that a
|
110
|
+
# string like "YAML.txt" could be the txt() class method of class YAML (in
|
111
|
+
# which case it would match the first pattern, which splits the string
|
112
|
+
# into container and method components and looks up both) or a filename
|
113
|
+
# (in which case it would match the last pattern, which just checks
|
114
|
+
# whether the string as a whole is a known symbol).
|
115
|
+
|
116
|
+
if /#{CLASS_REGEXP_STR}[\.\#]#{METHOD_REGEXP_STR}/ =~ lookup then
|
117
|
+
container = $1
|
118
|
+
method = $2
|
119
|
+
ref = @context.find_symbol container, method
|
120
|
+
end
|
121
|
+
|
122
|
+
ref = @context.find_symbol lookup unless ref
|
123
|
+
|
124
|
+
out = if lookup == '\\' then
|
125
|
+
lookup
|
126
|
+
elsif lookup =~ /^\\/ then
|
127
|
+
$'
|
128
|
+
elsif ref and ref.document_self then
|
129
|
+
"<a href=\"#{ref.as_href(@from_path)}\">#{name}</a>"
|
130
|
+
else
|
131
|
+
name
|
132
|
+
end
|
133
|
+
|
134
|
+
@seen[name] = out
|
135
|
+
|
136
|
+
out
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
@@ -0,0 +1,328 @@
|
|
1
|
+
require 'rdoc/markup/formatter'
|
2
|
+
require 'rdoc/markup/fragments'
|
3
|
+
require 'rdoc/markup/inline'
|
4
|
+
|
5
|
+
require 'cgi'
|
6
|
+
|
7
|
+
##
|
8
|
+
# Convert SimpleMarkup to basic LaTeX report format.
|
9
|
+
|
10
|
+
class RDoc::Markup::ToLaTeX < RDoc::Markup::Formatter
|
11
|
+
|
12
|
+
BS = "\020" # \
|
13
|
+
OB = "\021" # {
|
14
|
+
CB = "\022" # }
|
15
|
+
DL = "\023" # Dollar
|
16
|
+
|
17
|
+
BACKSLASH = "#{BS}symbol#{OB}92#{CB}"
|
18
|
+
HAT = "#{BS}symbol#{OB}94#{CB}"
|
19
|
+
BACKQUOTE = "#{BS}symbol#{OB}0#{CB}"
|
20
|
+
TILDE = "#{DL}#{BS}sim#{DL}"
|
21
|
+
LESSTHAN = "#{DL}<#{DL}"
|
22
|
+
GREATERTHAN = "#{DL}>#{DL}"
|
23
|
+
|
24
|
+
def self.l(str)
|
25
|
+
str.tr('\\', BS).tr('{', OB).tr('}', CB).tr('$', DL)
|
26
|
+
end
|
27
|
+
|
28
|
+
def l(arg)
|
29
|
+
RDoc::Markup::ToLaTeX.l(arg)
|
30
|
+
end
|
31
|
+
|
32
|
+
LIST_TYPE_TO_LATEX = {
|
33
|
+
:BULLET => [ l("\\begin{itemize}"), l("\\end{itemize}") ],
|
34
|
+
:NUMBER => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\arabic" ],
|
35
|
+
:UPPERALPHA => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\Alph" ],
|
36
|
+
:LOWERALPHA => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\alph" ],
|
37
|
+
:LABELED => [ l("\\begin{description}"), l("\\end{description}") ],
|
38
|
+
:NOTE => [
|
39
|
+
l("\\begin{tabularx}{\\linewidth}{@{} l X @{}}"),
|
40
|
+
l("\\end{tabularx}") ],
|
41
|
+
}
|
42
|
+
|
43
|
+
InlineTag = Struct.new(:bit, :on, :off)
|
44
|
+
|
45
|
+
def initialize
|
46
|
+
init_tags
|
47
|
+
@list_depth = 0
|
48
|
+
@prev_list_types = []
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Set up the standard mapping of attributes to LaTeX
|
53
|
+
|
54
|
+
def init_tags
|
55
|
+
@attr_tags = [
|
56
|
+
InlineTag.new(RDoc::Markup::Attribute.bitmap_for(:BOLD), l("\\textbf{"), l("}")),
|
57
|
+
InlineTag.new(RDoc::Markup::Attribute.bitmap_for(:TT), l("\\texttt{"), l("}")),
|
58
|
+
InlineTag.new(RDoc::Markup::Attribute.bitmap_for(:EM), l("\\emph{"), l("}")),
|
59
|
+
]
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Escape a LaTeX string
|
64
|
+
|
65
|
+
def escape(str)
|
66
|
+
$stderr.print "FE: ", str if $DEBUG_RDOC
|
67
|
+
s = str.
|
68
|
+
sub(/\s+$/, '').
|
69
|
+
gsub(/([_\${}&%#])/, "#{BS}\\1").
|
70
|
+
gsub(/\\/, BACKSLASH).
|
71
|
+
gsub(/\^/, HAT).
|
72
|
+
gsub(/~/, TILDE).
|
73
|
+
gsub(/</, LESSTHAN).
|
74
|
+
gsub(/>/, GREATERTHAN).
|
75
|
+
gsub(/,,/, ",{},").
|
76
|
+
gsub(/\`/, BACKQUOTE)
|
77
|
+
$stderr.print "-> ", s, "\n" if $DEBUG_RDOC
|
78
|
+
s
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# Add a new set of LaTeX tags for an attribute. We allow
|
83
|
+
# separate start and end tags for flexibility
|
84
|
+
|
85
|
+
def add_tag(name, start, stop)
|
86
|
+
@attr_tags << InlineTag.new(RDoc::Markup::Attribute.bitmap_for(name), start, stop)
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# This is a higher speed (if messier) version of wrap
|
91
|
+
|
92
|
+
def wrap(txt, line_len = 76)
|
93
|
+
res = ""
|
94
|
+
sp = 0
|
95
|
+
ep = txt.length
|
96
|
+
while sp < ep
|
97
|
+
# scan back for a space
|
98
|
+
p = sp + line_len - 1
|
99
|
+
if p >= ep
|
100
|
+
p = ep
|
101
|
+
else
|
102
|
+
while p > sp and txt[p] != ?\s
|
103
|
+
p -= 1
|
104
|
+
end
|
105
|
+
if p <= sp
|
106
|
+
p = sp + line_len
|
107
|
+
while p < ep and txt[p] != ?\s
|
108
|
+
p += 1
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
res << txt[sp...p] << "\n"
|
113
|
+
sp = p
|
114
|
+
sp += 1 while sp < ep and txt[sp] == ?\s
|
115
|
+
end
|
116
|
+
res
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
# :section: Visitor
|
121
|
+
|
122
|
+
def start_accepting
|
123
|
+
@res = ""
|
124
|
+
@in_list_entry = []
|
125
|
+
end
|
126
|
+
|
127
|
+
def end_accepting
|
128
|
+
@res.tr(BS, '\\').tr(OB, '{').tr(CB, '}').tr(DL, '$')
|
129
|
+
end
|
130
|
+
|
131
|
+
def accept_paragraph(am, fragment)
|
132
|
+
@res << wrap(convert_flow(am.flow(fragment.txt)))
|
133
|
+
@res << "\n"
|
134
|
+
end
|
135
|
+
|
136
|
+
def accept_verbatim(am, fragment)
|
137
|
+
@res << "\n\\begin{code}\n"
|
138
|
+
@res << fragment.txt.sub(/[\n\s]+\Z/, '')
|
139
|
+
@res << "\n\\end{code}\n\n"
|
140
|
+
end
|
141
|
+
|
142
|
+
def accept_rule(am, fragment)
|
143
|
+
size = fragment.param
|
144
|
+
size = 10 if size > 10
|
145
|
+
@res << "\n\n\\rule{\\linewidth}{#{size}pt}\n\n"
|
146
|
+
end
|
147
|
+
|
148
|
+
def accept_list_start(am, fragment)
|
149
|
+
@res << list_name(fragment.type, true) << "\n"
|
150
|
+
@in_list_entry.push false
|
151
|
+
end
|
152
|
+
|
153
|
+
def accept_list_end(am, fragment)
|
154
|
+
if tag = @in_list_entry.pop
|
155
|
+
@res << tag << "\n"
|
156
|
+
end
|
157
|
+
@res << list_name(fragment.type, false) << "\n"
|
158
|
+
end
|
159
|
+
|
160
|
+
def accept_list_item(am, fragment)
|
161
|
+
if tag = @in_list_entry.last
|
162
|
+
@res << tag << "\n"
|
163
|
+
end
|
164
|
+
@res << list_item_start(am, fragment)
|
165
|
+
@res << wrap(convert_flow(am.flow(fragment.txt))) << "\n"
|
166
|
+
@in_list_entry[-1] = list_end_for(fragment.type)
|
167
|
+
end
|
168
|
+
|
169
|
+
def accept_blank_line(am, fragment)
|
170
|
+
# @res << "\n"
|
171
|
+
end
|
172
|
+
|
173
|
+
def accept_heading(am, fragment)
|
174
|
+
@res << convert_heading(fragment.head_level, am.flow(fragment.txt))
|
175
|
+
end
|
176
|
+
|
177
|
+
private
|
178
|
+
|
179
|
+
def on_tags(res, item)
|
180
|
+
attr_mask = item.turn_on
|
181
|
+
return if attr_mask.zero?
|
182
|
+
|
183
|
+
@attr_tags.each do |tag|
|
184
|
+
if attr_mask & tag.bit != 0
|
185
|
+
res << tag.on
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def off_tags(res, item)
|
191
|
+
attr_mask = item.turn_off
|
192
|
+
return if attr_mask.zero?
|
193
|
+
|
194
|
+
@attr_tags.reverse_each do |tag|
|
195
|
+
if attr_mask & tag.bit != 0
|
196
|
+
res << tag.off
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def convert_flow(flow)
|
202
|
+
res = ""
|
203
|
+
flow.each do |item|
|
204
|
+
case item
|
205
|
+
when String
|
206
|
+
$stderr.puts "Converting '#{item}'" if $DEBUG_RDOC
|
207
|
+
res << convert_string(item)
|
208
|
+
when AttrChanger
|
209
|
+
off_tags(res, item)
|
210
|
+
on_tags(res, item)
|
211
|
+
when Special
|
212
|
+
res << convert_special(item)
|
213
|
+
else
|
214
|
+
raise "Unknown flow element: #{item.inspect}"
|
215
|
+
end
|
216
|
+
end
|
217
|
+
res
|
218
|
+
end
|
219
|
+
|
220
|
+
##
|
221
|
+
# some of these patterns are taken from SmartyPants...
|
222
|
+
|
223
|
+
def convert_string(item)
|
224
|
+
escape(item).
|
225
|
+
|
226
|
+
# convert ... to elipsis (and make sure .... becomes .<elipsis>)
|
227
|
+
gsub(/\.\.\.\./, '.\ldots{}').gsub(/\.\.\./, '\ldots{}').
|
228
|
+
|
229
|
+
# convert single closing quote
|
230
|
+
gsub(%r{([^ \t\r\n\[\{\(])\'}, '\1\'').
|
231
|
+
gsub(%r{\'(?=\W|s\b)}, "'" ).
|
232
|
+
|
233
|
+
# convert single opening quote
|
234
|
+
gsub(/'/, '`').
|
235
|
+
|
236
|
+
# convert double closing quote
|
237
|
+
gsub(%r{([^ \t\r\n\[\{\(])\"(?=\W)}, "\\1''").
|
238
|
+
|
239
|
+
# convert double opening quote
|
240
|
+
gsub(/"/, "``").
|
241
|
+
|
242
|
+
# convert copyright
|
243
|
+
gsub(/\(c\)/, '\copyright{}')
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
def convert_special(special)
|
248
|
+
handled = false
|
249
|
+
Attribute.each_name_of(special.type) do |name|
|
250
|
+
method_name = "handle_special_#{name}"
|
251
|
+
if self.respond_to? method_name
|
252
|
+
special.text = send(method_name, special)
|
253
|
+
handled = true
|
254
|
+
end
|
255
|
+
end
|
256
|
+
raise "Unhandled special: #{special}" unless handled
|
257
|
+
special.text
|
258
|
+
end
|
259
|
+
|
260
|
+
def convert_heading(level, flow)
|
261
|
+
res =
|
262
|
+
case level
|
263
|
+
when 1 then "\\chapter{"
|
264
|
+
when 2 then "\\section{"
|
265
|
+
when 3 then "\\subsection{"
|
266
|
+
when 4 then "\\subsubsection{"
|
267
|
+
else "\\paragraph{"
|
268
|
+
end +
|
269
|
+
convert_flow(flow) +
|
270
|
+
"}\n"
|
271
|
+
end
|
272
|
+
|
273
|
+
def list_name(list_type, is_open_tag)
|
274
|
+
tags = LIST_TYPE_TO_LATEX[list_type] || raise("Invalid list type: #{list_type.inspect}")
|
275
|
+
if tags[2] # enumerate
|
276
|
+
if is_open_tag
|
277
|
+
@list_depth += 1
|
278
|
+
if @prev_list_types[@list_depth] != tags[2]
|
279
|
+
case @list_depth
|
280
|
+
when 1
|
281
|
+
roman = "i"
|
282
|
+
when 2
|
283
|
+
roman = "ii"
|
284
|
+
when 3
|
285
|
+
roman = "iii"
|
286
|
+
when 4
|
287
|
+
roman = "iv"
|
288
|
+
else
|
289
|
+
raise("Too deep list: level #{@list_depth}")
|
290
|
+
end
|
291
|
+
@prev_list_types[@list_depth] = tags[2]
|
292
|
+
return l("\\renewcommand{\\labelenum#{roman}}{#{tags[2]}{enum#{roman}}}") + "\n" + tags[0]
|
293
|
+
end
|
294
|
+
else
|
295
|
+
@list_depth -= 1
|
296
|
+
end
|
297
|
+
end
|
298
|
+
tags[ is_open_tag ? 0 : 1]
|
299
|
+
end
|
300
|
+
|
301
|
+
def list_item_start(am, fragment)
|
302
|
+
case fragment.type
|
303
|
+
when :BULLET, :NUMBER, :UPPERALPHA, :LOWERALPHA then
|
304
|
+
"\\item "
|
305
|
+
|
306
|
+
when :LABELED then
|
307
|
+
"\\item[" + convert_flow(am.flow(fragment.param)) + "] "
|
308
|
+
|
309
|
+
when :NOTE then
|
310
|
+
convert_flow(am.flow(fragment.param)) + " & "
|
311
|
+
else
|
312
|
+
raise "Invalid list type"
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
def list_end_for(fragment_type)
|
317
|
+
case fragment_type
|
318
|
+
when :BULLET, :NUMBER, :UPPERALPHA, :LOWERALPHA, :LABELED then
|
319
|
+
""
|
320
|
+
when :NOTE
|
321
|
+
"\\\\\n"
|
322
|
+
else
|
323
|
+
raise "Invalid list type"
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
end
|
328
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rdoc/markup'
|
2
|
+
require 'rdoc/markup/formatter'
|
3
|
+
|
4
|
+
##
|
5
|
+
# This Markup outputter is used for testing purposes.
|
6
|
+
|
7
|
+
class RDoc::Markup::ToTest < RDoc::Markup::Formatter
|
8
|
+
|
9
|
+
##
|
10
|
+
# :section: Visitor
|
11
|
+
|
12
|
+
def start_accepting
|
13
|
+
@res = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def end_accepting
|
17
|
+
@res
|
18
|
+
end
|
19
|
+
|
20
|
+
def accept_paragraph(am, fragment)
|
21
|
+
@res << fragment.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def accept_verbatim(am, fragment)
|
25
|
+
@res << fragment.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def accept_list_start(am, fragment)
|
29
|
+
@res << fragment.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def accept_list_end(am, fragment)
|
33
|
+
@res << fragment.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
def accept_list_item(am, fragment)
|
37
|
+
@res << fragment.to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
def accept_blank_line(am, fragment)
|
41
|
+
@res << fragment.to_s
|
42
|
+
end
|
43
|
+
|
44
|
+
def accept_heading(am, fragment)
|
45
|
+
@res << fragment.to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
def accept_rule(am, fragment)
|
49
|
+
@res << fragment.to_s
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'rdoc/markup/formatter'
|
2
|
+
require 'rdoc/markup/fragments'
|
3
|
+
require 'rdoc/markup/inline'
|
4
|
+
|
5
|
+
require 'rdoc/markup'
|
6
|
+
require 'rdoc/markup/formatter'
|
7
|
+
|
8
|
+
##
|
9
|
+
# Convert SimpleMarkup to basic TexInfo format
|
10
|
+
#
|
11
|
+
# TODO: WTF is AttributeManager for?
|
12
|
+
|
13
|
+
class RDoc::Markup::ToTexInfo < RDoc::Markup::Formatter
|
14
|
+
|
15
|
+
def format(text)
|
16
|
+
text.txt.
|
17
|
+
gsub(/@/, "@@").
|
18
|
+
gsub(/\{/, "@{").
|
19
|
+
gsub(/\}/, "@}").
|
20
|
+
# gsub(/,/, "@,"). # technically only required in cross-refs
|
21
|
+
gsub(/\+([\w]+)\+/, "@code{\\1}").
|
22
|
+
gsub(/\<tt\>([^<]+)\<\/tt\>/, "@code{\\1}").
|
23
|
+
gsub(/\*([\w]+)\*/, "@strong{\\1}").
|
24
|
+
gsub(/\<b\>([^<]+)\<\/b\>/, "@strong{\\1}").
|
25
|
+
gsub(/_([\w]+)_/, "@emph{\\1}").
|
26
|
+
gsub(/\<em\>([^<]+)\<\/em\>/, "@emph{\\1}")
|
27
|
+
end
|
28
|
+
|
29
|
+
# :section: Visitor
|
30
|
+
|
31
|
+
def start_accepting
|
32
|
+
@text = []
|
33
|
+
end
|
34
|
+
|
35
|
+
def end_accepting
|
36
|
+
@text.join("\n")
|
37
|
+
end
|
38
|
+
|
39
|
+
def accept_paragraph(attributes, text)
|
40
|
+
@text << format(text)
|
41
|
+
end
|
42
|
+
|
43
|
+
def accept_verbatim(attributes, text)
|
44
|
+
@text << "@verb{|#{format(text)}|}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def accept_heading(attributes, text)
|
48
|
+
heading = ['@majorheading', '@chapheading'][text.head_level - 1] || '@heading'
|
49
|
+
@text << "#{heading} #{format(text)}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def accept_list_start(attributes, text)
|
53
|
+
@text << '@itemize @bullet'
|
54
|
+
end
|
55
|
+
|
56
|
+
def accept_list_end(attributes, text)
|
57
|
+
@text << '@end itemize'
|
58
|
+
end
|
59
|
+
|
60
|
+
def accept_list_item(attributes, text)
|
61
|
+
@text << "@item\n#{format(text)}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def accept_blank_line(attributes, text)
|
65
|
+
@text << "\n"
|
66
|
+
end
|
67
|
+
|
68
|
+
def accept_rule(attributes, text)
|
69
|
+
@text << '-----'
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|