rdoc 7.0.3 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +70 -4
- data/doc/markup_reference/markdown.md +558 -0
- data/doc/markup_reference/rdoc.rdoc +1169 -0
- data/lib/rdoc/code_object/attr.rb +2 -1
- data/lib/rdoc/code_object/class_module.rb +24 -3
- data/lib/rdoc/code_object/context/section.rb +46 -9
- data/lib/rdoc/code_object/context.rb +15 -4
- data/lib/rdoc/code_object/mixin.rb +3 -0
- data/lib/rdoc/code_object/top_level.rb +2 -0
- data/lib/rdoc/comment.rb +1 -1
- data/lib/rdoc/cross_reference.rb +31 -24
- data/lib/rdoc/generator/template/aliki/_head.rhtml +5 -0
- data/lib/rdoc/generator/template/aliki/class.rhtml +8 -6
- data/lib/rdoc/generator/template/aliki/css/rdoc.css +48 -36
- data/lib/rdoc/generator/template/aliki/js/aliki.js +8 -2
- data/lib/rdoc/generator/template/aliki/js/bash_highlighter.js +167 -0
- data/lib/rdoc/generator/template/aliki/js/c_highlighter.js +1 -1
- data/lib/rdoc/generator/template/aliki/js/search_controller.js +1 -1
- data/lib/rdoc/generator/template/darkfish/class.rhtml +2 -0
- data/lib/rdoc/generator/template/darkfish/css/rdoc.css +19 -0
- data/lib/rdoc/markdown.kpeg +22 -12
- data/lib/rdoc/markdown.rb +36 -26
- data/lib/rdoc/markup/formatter.rb +129 -106
- data/lib/rdoc/markup/heading.rb +101 -29
- data/lib/rdoc/markup/inline_parser.rb +312 -0
- data/lib/rdoc/markup/parser.rb +1 -1
- data/lib/rdoc/markup/to_ansi.rb +51 -4
- data/lib/rdoc/markup/to_bs.rb +22 -42
- data/lib/rdoc/markup/to_html.rb +178 -183
- data/lib/rdoc/markup/to_html_crossref.rb +58 -79
- data/lib/rdoc/markup/to_html_snippet.rb +62 -62
- data/lib/rdoc/markup/to_label.rb +29 -20
- data/lib/rdoc/markup/to_markdown.rb +61 -37
- data/lib/rdoc/markup/to_rdoc.rb +86 -26
- data/lib/rdoc/markup/to_test.rb +9 -1
- data/lib/rdoc/markup/to_tt_only.rb +10 -16
- data/lib/rdoc/markup/verbatim.rb +1 -1
- data/lib/rdoc/markup.rb +10 -32
- data/lib/rdoc/parser/changelog.rb +29 -0
- data/lib/rdoc/parser/prism_ruby.rb +44 -32
- data/lib/rdoc/parser/ruby.rb +1 -1
- data/lib/rdoc/text.rb +44 -5
- data/lib/rdoc/token_stream.rb +4 -8
- data/lib/rdoc/version.rb +1 -1
- data/rdoc.gemspec +2 -2
- metadata +7 -12
- data/ExampleMarkdown.md +0 -39
- data/ExampleRDoc.rdoc +0 -210
- data/lib/rdoc/markup/attr_changer.rb +0 -22
- data/lib/rdoc/markup/attr_span.rb +0 -35
- data/lib/rdoc/markup/attribute_manager.rb +0 -405
- data/lib/rdoc/markup/attributes.rb +0 -70
- data/lib/rdoc/markup/regexp_handling.rb +0 -40
data/ExampleRDoc.rdoc
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
= Example \RDoc
|
|
2
|
-
|
|
3
|
-
This document contains example output to show RDoc styling. This file was
|
|
4
|
-
created from a RDoc Markup file.
|
|
5
|
-
|
|
6
|
-
== Headings
|
|
7
|
-
|
|
8
|
-
You should not use headings beyond level 3, it is a sign of poor organization
|
|
9
|
-
of your code or documentation. It also becomes difficult for the user to
|
|
10
|
-
figure out what you are attempting to explain to them as they have to track
|
|
11
|
-
the multiple layers of nesting.
|
|
12
|
-
|
|
13
|
-
= Heading level 1
|
|
14
|
-
|
|
15
|
-
Above is a level one heading.
|
|
16
|
-
|
|
17
|
-
These paragraphs are filler that exist so you can see how the heading
|
|
18
|
-
interacts with paragraphs before and after the heading. As you can see each
|
|
19
|
-
different heading has a different amount of margin above and below.
|
|
20
|
-
|
|
21
|
-
This should be sufficient to give you a proper picture of how it will appear in
|
|
22
|
-
your documentation.
|
|
23
|
-
|
|
24
|
-
== Heading level 2
|
|
25
|
-
|
|
26
|
-
Above is a level two heading.
|
|
27
|
-
|
|
28
|
-
These paragraphs are filler that exist so you can see how the heading
|
|
29
|
-
interacts with paragraphs before and after the heading. As you can see each
|
|
30
|
-
different heading has a different amount of margin above and below.
|
|
31
|
-
|
|
32
|
-
This should be sufficient to give you a proper picture of how it will appear in
|
|
33
|
-
your documentation.
|
|
34
|
-
|
|
35
|
-
=== Heading level 3
|
|
36
|
-
|
|
37
|
-
Above is a level three heading.
|
|
38
|
-
|
|
39
|
-
These paragraphs are filler that exist so you can see how the heading
|
|
40
|
-
interacts with paragraphs before and after the heading. As you can see each
|
|
41
|
-
different heading has a different amount of margin above and below.
|
|
42
|
-
|
|
43
|
-
This should be sufficient to give you a proper picture of how it will appear in
|
|
44
|
-
your documentation.
|
|
45
|
-
|
|
46
|
-
==== Heading level 4
|
|
47
|
-
|
|
48
|
-
Above is a level four heading.
|
|
49
|
-
|
|
50
|
-
These paragraphs are filler that exist so you can see how the heading
|
|
51
|
-
interacts with paragraphs before and after the heading. As you can see each
|
|
52
|
-
different heading has a different amount of margin above and below.
|
|
53
|
-
|
|
54
|
-
This should be sufficient to give you a proper picture of how it will appear in
|
|
55
|
-
your documentation.
|
|
56
|
-
|
|
57
|
-
===== Heading level 5
|
|
58
|
-
|
|
59
|
-
Above is a level five heading.
|
|
60
|
-
|
|
61
|
-
These paragraphs are filler that exist so you can see how the heading
|
|
62
|
-
interacts with paragraphs before and after the heading. As you can see each
|
|
63
|
-
different heading has a different amount of margin above and below.
|
|
64
|
-
|
|
65
|
-
This should be sufficient to give you a proper picture of how it will appear in
|
|
66
|
-
your documentation.
|
|
67
|
-
|
|
68
|
-
====== Heading level 6
|
|
69
|
-
|
|
70
|
-
Above is a level six heading.
|
|
71
|
-
|
|
72
|
-
These paragraphs are filler that exist so you can see how the heading
|
|
73
|
-
interacts with paragraphs before and after the heading. As you can see each
|
|
74
|
-
different heading has a different amount of margin above and below.
|
|
75
|
-
|
|
76
|
-
This should be sufficient to give you a proper picture of how it will appear in
|
|
77
|
-
your documentation.
|
|
78
|
-
|
|
79
|
-
== Paragraphs
|
|
80
|
-
|
|
81
|
-
This is how a paragraph looks. Since it is difficult to generate good content
|
|
82
|
-
for paragraphs I have chosen to use {Riker Ipsum}[http://rikeripsum.com] for
|
|
83
|
-
nonsense filler content. In the previous sentence you can see how a link is
|
|
84
|
-
formatted.
|
|
85
|
-
|
|
86
|
-
Here is an example of *bold* and _emphasis_ styling. Try not to combine the
|
|
87
|
-
two or use them too often. Here is an example of <code>inline verbatim
|
|
88
|
-
text</code>. That should be enough of a taste of inline markup in paragraphs.
|
|
89
|
-
The Riker Ipsum filler follows:
|
|
90
|
-
|
|
91
|
-
Shields up! Rrrrred alert! Well, I'll say this for him - he's sure of himself.
|
|
92
|
-
and attack the Romulans. Worf, It's better than music. It's jazz. This should
|
|
93
|
-
be interesting. When has justice ever been as simple as a rule book? Flair is
|
|
94
|
-
what marks the difference between artistry and mere competence.
|
|
95
|
-
|
|
96
|
-
Sorry, Data. I think you've let your personal feelings cloud your judgement. We
|
|
97
|
-
finished our first sensor sweep of the neutral zone. Yes, absolutely, I do
|
|
98
|
-
indeed concur, wholeheartedly! Mr. Worf, you do remember how to fire phasers? A
|
|
99
|
-
lot of things can change in twelve years, Admiral. Your shields were failing,
|
|
100
|
-
sir.
|
|
101
|
-
|
|
102
|
-
== Verbatim sections
|
|
103
|
-
|
|
104
|
-
A verbatim section typically contains source code or example output. This is
|
|
105
|
-
how verbatim blocks of code looks:
|
|
106
|
-
|
|
107
|
-
def local responder
|
|
108
|
-
responder.ping do |value|
|
|
109
|
-
return value
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def ping uri
|
|
114
|
-
@uri = uri
|
|
115
|
-
@remote = DRb::DRbObject.new_with_uri @uri
|
|
116
|
-
|
|
117
|
-
@remote.ping do |value|
|
|
118
|
-
return value
|
|
119
|
-
end
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
This is a paragraph following the verbatim block so you can see how leading and trailing paragraphs interact with it.
|
|
123
|
-
|
|
124
|
-
== Unordered lists
|
|
125
|
-
|
|
126
|
-
Here is an unordered list. As you can see it uses non-numeral markers for each list item:
|
|
127
|
-
|
|
128
|
-
* This is the top-most item in the list.
|
|
129
|
-
* This is a second item in the list.
|
|
130
|
-
|
|
131
|
-
Unlike the first item, this item has more than one paragraph so you can see
|
|
132
|
-
how they interact.
|
|
133
|
-
* This is a third item in the list. Like the item before it, this item has a
|
|
134
|
-
second paragraph.
|
|
135
|
-
|
|
136
|
-
Here is the second paragraph in the list item.
|
|
137
|
-
* A final list item.
|
|
138
|
-
|
|
139
|
-
== Ordered lists
|
|
140
|
-
|
|
141
|
-
Here is an ordered list. As you can see it uses numeral markers for each list
|
|
142
|
-
item:
|
|
143
|
-
|
|
144
|
-
1. This is the first item in the list.
|
|
145
|
-
1. This is the second item in the list.
|
|
146
|
-
|
|
147
|
-
Unlike the first item, this item has more than one paragraph so you can see
|
|
148
|
-
how they interact.
|
|
149
|
-
1. This is the third item in the list. Like the item before it, this item has
|
|
150
|
-
a second paragraph.
|
|
151
|
-
|
|
152
|
-
Here is the second paragraph in the third list item.
|
|
153
|
-
1. The fourth and final list item.
|
|
154
|
-
|
|
155
|
-
== Definition lists
|
|
156
|
-
|
|
157
|
-
=== "Note" list
|
|
158
|
-
|
|
159
|
-
The "note" syntax can be used to create a definition list:
|
|
160
|
-
|
|
161
|
-
note::
|
|
162
|
-
description
|
|
163
|
-
|
|
164
|
-
Here is such a definition list:
|
|
165
|
-
|
|
166
|
-
cat::
|
|
167
|
-
A cat is a small mammal that is commonly kept as a pet.
|
|
168
|
-
|
|
169
|
-
dog::
|
|
170
|
-
A dog is a mammal that is also kept as a pet. A dog may range in size from
|
|
171
|
-
smaller than a cat to larger than a human.
|
|
172
|
-
|
|
173
|
-
Typically dogs are easier to train to respond to commands than cats.
|
|
174
|
-
|
|
175
|
-
rabbit::
|
|
176
|
-
Rabbits are also mammals, but are infrequently kept as pets. Most rabbits
|
|
177
|
-
are wild.
|
|
178
|
-
|
|
179
|
-
=== "Label" list
|
|
180
|
-
|
|
181
|
-
The "label" syntax can be used to create a definition list:
|
|
182
|
-
|
|
183
|
-
[label]
|
|
184
|
-
description
|
|
185
|
-
|
|
186
|
-
Here is such a definition list:
|
|
187
|
-
|
|
188
|
-
[cat]
|
|
189
|
-
A cat is a small mammal that is commonly kept as a pet.
|
|
190
|
-
|
|
191
|
-
[dog]
|
|
192
|
-
A dog is a mammal that is also kept as a pet. A dog may range in size from
|
|
193
|
-
smaller than a cat to larger than a human.
|
|
194
|
-
|
|
195
|
-
Typically dogs are easier to train to respond to commands than cats.
|
|
196
|
-
|
|
197
|
-
[rabbit]
|
|
198
|
-
Rabbits are also mammals, but are infrequently kept as pets. Most rabbits
|
|
199
|
-
are wild.
|
|
200
|
-
|
|
201
|
-
== Rule
|
|
202
|
-
|
|
203
|
-
A rule is a horizontal divider between two paragraphs. Following this
|
|
204
|
-
paragraph is a rule.
|
|
205
|
-
|
|
206
|
-
---
|
|
207
|
-
|
|
208
|
-
In historic versions of RDoc you could control the height of the rule in HTML
|
|
209
|
-
output. This is no longer true as HTML 5 does not support this.
|
|
210
|
-
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
class RDoc::Markup
|
|
3
|
-
|
|
4
|
-
AttrChanger = Struct.new :turn_on, :turn_off # :nodoc:
|
|
5
|
-
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
##
|
|
9
|
-
# An AttrChanger records a change in attributes. It contains a bitmap of the
|
|
10
|
-
# attributes to turn on, and a bitmap of those to turn off.
|
|
11
|
-
|
|
12
|
-
class RDoc::Markup::AttrChanger
|
|
13
|
-
|
|
14
|
-
def to_s # :nodoc:
|
|
15
|
-
"Attr: +#{turn_on}/-#{turn_off}"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def inspect # :nodoc:
|
|
19
|
-
'+%d/-%d' % [turn_on, turn_off]
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
end
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
##
|
|
3
|
-
# An array of attributes which parallels the characters in a string.
|
|
4
|
-
|
|
5
|
-
class RDoc::Markup::AttrSpan
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
# Creates a new AttrSpan for +length+ characters
|
|
9
|
-
|
|
10
|
-
def initialize(length, exclusive)
|
|
11
|
-
@attrs = Array.new(length, 0)
|
|
12
|
-
@exclusive = exclusive
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
##
|
|
16
|
-
# Toggles +bits+ from +start+ to +length+
|
|
17
|
-
def set_attrs(start, length, bits)
|
|
18
|
-
updated = false
|
|
19
|
-
for i in start ... (start+length)
|
|
20
|
-
if (@exclusive & @attrs[i]) == 0 || (@exclusive & bits) != 0
|
|
21
|
-
@attrs[i] |= bits
|
|
22
|
-
updated = true
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
updated
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
##
|
|
29
|
-
# Accesses flags for character +n+
|
|
30
|
-
|
|
31
|
-
def [](n)
|
|
32
|
-
@attrs[n]
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
end
|
|
@@ -1,405 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
##
|
|
4
|
-
# Manages changes of attributes in a block of text
|
|
5
|
-
|
|
6
|
-
class RDoc::Markup::AttributeManager
|
|
7
|
-
unless ::MatchData.method_defined?(:match_length)
|
|
8
|
-
using ::Module.new {
|
|
9
|
-
refine(::MatchData) {
|
|
10
|
-
def match_length(nth) # :nodoc:
|
|
11
|
-
b, e = offset(nth)
|
|
12
|
-
e - b if b
|
|
13
|
-
end
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
##
|
|
19
|
-
# The NUL character
|
|
20
|
-
|
|
21
|
-
NULL = "\000".freeze
|
|
22
|
-
|
|
23
|
-
#--
|
|
24
|
-
# We work by substituting non-printing characters in to the text. For now
|
|
25
|
-
# I'm assuming that I can substitute a character in the range 0..8 for a 7
|
|
26
|
-
# bit character without damaging the encoded string, but this might be
|
|
27
|
-
# optimistic
|
|
28
|
-
#++
|
|
29
|
-
|
|
30
|
-
A_PROTECT = 004 # :nodoc:
|
|
31
|
-
|
|
32
|
-
##
|
|
33
|
-
# Special mask character to prevent inline markup handling
|
|
34
|
-
|
|
35
|
-
PROTECT_ATTR = A_PROTECT.chr # :nodoc:
|
|
36
|
-
|
|
37
|
-
##
|
|
38
|
-
# The attributes enabled for this markup object.
|
|
39
|
-
|
|
40
|
-
attr_reader :attributes
|
|
41
|
-
|
|
42
|
-
##
|
|
43
|
-
# This maps delimiters that occur around words (such as *bold* or +tt+)
|
|
44
|
-
# where the start and end delimiters and the same. This lets us optimize
|
|
45
|
-
# the regexp
|
|
46
|
-
|
|
47
|
-
attr_reader :matching_word_pairs
|
|
48
|
-
|
|
49
|
-
##
|
|
50
|
-
# And this is used when the delimiters aren't the same. In this case the
|
|
51
|
-
# hash maps a pattern to the attribute character
|
|
52
|
-
|
|
53
|
-
attr_reader :word_pair_map
|
|
54
|
-
|
|
55
|
-
##
|
|
56
|
-
# This maps HTML tags to the corresponding attribute char
|
|
57
|
-
|
|
58
|
-
attr_reader :html_tags
|
|
59
|
-
|
|
60
|
-
##
|
|
61
|
-
# A \ in front of a character that would normally be processed turns off
|
|
62
|
-
# processing. We do this by turning \< into <#{PROTECT}
|
|
63
|
-
|
|
64
|
-
attr_reader :protectable
|
|
65
|
-
|
|
66
|
-
##
|
|
67
|
-
# And this maps _regexp handling_ sequences to a name. A regexp handling
|
|
68
|
-
# sequence is something like a WikiWord
|
|
69
|
-
|
|
70
|
-
attr_reader :regexp_handlings
|
|
71
|
-
|
|
72
|
-
##
|
|
73
|
-
# A bits of exclusive maps
|
|
74
|
-
attr_reader :exclusive_bitmap
|
|
75
|
-
|
|
76
|
-
##
|
|
77
|
-
# Creates a new attribute manager that understands bold, emphasized and
|
|
78
|
-
# teletype text.
|
|
79
|
-
|
|
80
|
-
def initialize
|
|
81
|
-
@html_tags = {}
|
|
82
|
-
@matching_word_pairs = {}
|
|
83
|
-
@protectable = %w[<]
|
|
84
|
-
@regexp_handlings = []
|
|
85
|
-
@word_pair_map = {}
|
|
86
|
-
@exclusive_bitmap = 0
|
|
87
|
-
@attributes = RDoc::Markup::Attributes.new
|
|
88
|
-
|
|
89
|
-
add_word_pair "*", "*", :BOLD, true
|
|
90
|
-
add_word_pair "_", "_", :EM, true
|
|
91
|
-
add_word_pair "+", "+", :TT, true
|
|
92
|
-
|
|
93
|
-
add_html "em", :EM, true
|
|
94
|
-
add_html "i", :EM, true
|
|
95
|
-
add_html "b", :BOLD, true
|
|
96
|
-
add_html "tt", :TT, true
|
|
97
|
-
add_html "code", :TT, true
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
##
|
|
101
|
-
# Return an attribute object with the given turn_on and turn_off bits set
|
|
102
|
-
|
|
103
|
-
def attribute(turn_on, turn_off)
|
|
104
|
-
RDoc::Markup::AttrChanger.new turn_on, turn_off
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
##
|
|
108
|
-
# Changes the current attribute from +current+ to +new+
|
|
109
|
-
|
|
110
|
-
def change_attribute(current, new)
|
|
111
|
-
diff = current ^ new
|
|
112
|
-
attribute(new & diff, current & diff)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
##
|
|
116
|
-
# Used by the tests to change attributes by name from +current_set+ to
|
|
117
|
-
# +new_set+
|
|
118
|
-
|
|
119
|
-
def changed_attribute_by_name(current_set, new_set)
|
|
120
|
-
current = new = 0
|
|
121
|
-
current_set.each do |name|
|
|
122
|
-
current |= @attributes.bitmap_for(name)
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
new_set.each do |name|
|
|
126
|
-
new |= @attributes.bitmap_for(name)
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
change_attribute(current, new)
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
##
|
|
133
|
-
# Copies +start_pos+ to +end_pos+ from the current string
|
|
134
|
-
|
|
135
|
-
def copy_string(start_pos, end_pos)
|
|
136
|
-
res = @str[start_pos...end_pos]
|
|
137
|
-
res.gsub!(/\000/, '')
|
|
138
|
-
res
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
# :nodoc:
|
|
142
|
-
def exclusive?(attr)
|
|
143
|
-
(attr & @exclusive_bitmap) != 0
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
NON_PRINTING_START = "\1" # :nodoc:
|
|
147
|
-
NON_PRINTING_END = "\2" # :nodoc:
|
|
148
|
-
|
|
149
|
-
##
|
|
150
|
-
# Map attributes like <b>text</b>to the sequence
|
|
151
|
-
# \001\002<char>\001\003<char>, where <char> is a per-attribute specific
|
|
152
|
-
# character
|
|
153
|
-
|
|
154
|
-
def convert_attrs(str, attrs, exclusive = false)
|
|
155
|
-
convert_attrs_matching_word_pairs(str, attrs, exclusive)
|
|
156
|
-
convert_attrs_word_pair_map(str, attrs, exclusive)
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
# :nodoc:
|
|
160
|
-
def convert_attrs_matching_word_pairs(str, attrs, exclusive)
|
|
161
|
-
# first do matching ones
|
|
162
|
-
tags = @matching_word_pairs.select { |start, bitmap|
|
|
163
|
-
exclusive == exclusive?(bitmap)
|
|
164
|
-
}.keys
|
|
165
|
-
return if tags.empty?
|
|
166
|
-
tags = "[#{tags.join("")}](?!#{PROTECT_ATTR})"
|
|
167
|
-
all_tags = "[#{@matching_word_pairs.keys.join("")}](?!#{PROTECT_ATTR})"
|
|
168
|
-
|
|
169
|
-
re = /(?:^|\W|#{all_tags})\K(#{tags})(\1*[#\\]?[\w:#{PROTECT_ATTR}.\/\[\]-]+?\S?)\1(?!\1)(?=#{all_tags}|\W|$)/
|
|
170
|
-
|
|
171
|
-
1 while str.gsub!(re) { |orig|
|
|
172
|
-
a, w = (m = $~).values_at(1, 2)
|
|
173
|
-
attr = @matching_word_pairs[a]
|
|
174
|
-
if attrs.set_attrs(m.begin(2), w.length, attr)
|
|
175
|
-
a = NULL * a.length
|
|
176
|
-
else
|
|
177
|
-
a = NON_PRINTING_START + a + NON_PRINTING_END
|
|
178
|
-
end
|
|
179
|
-
a + w + a
|
|
180
|
-
}
|
|
181
|
-
str.delete!(NON_PRINTING_START + NON_PRINTING_END)
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
# :nodoc:
|
|
185
|
-
def convert_attrs_word_pair_map(str, attrs, exclusive)
|
|
186
|
-
# then non-matching
|
|
187
|
-
unless @word_pair_map.empty? then
|
|
188
|
-
@word_pair_map.each do |regexp, attr|
|
|
189
|
-
next unless exclusive == exclusive?(attr)
|
|
190
|
-
1 while str.gsub!(regexp) { |orig|
|
|
191
|
-
w = (m = ($~))[2]
|
|
192
|
-
updated = attrs.set_attrs(m.begin(2), w.length, attr)
|
|
193
|
-
if updated
|
|
194
|
-
NULL * m.match_length(1) + w + NULL * m.match_length(3)
|
|
195
|
-
else
|
|
196
|
-
orig
|
|
197
|
-
end
|
|
198
|
-
}
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
##
|
|
204
|
-
# Converts HTML tags to RDoc attributes
|
|
205
|
-
|
|
206
|
-
def convert_html(str, attrs, exclusive = false)
|
|
207
|
-
tags = @html_tags.select { |start, bitmap|
|
|
208
|
-
exclusive == exclusive?(bitmap)
|
|
209
|
-
}.keys.join '|'
|
|
210
|
-
|
|
211
|
-
1 while str.gsub!(/<(#{tags})>(.*?)<\/\1>/i) { |orig|
|
|
212
|
-
attr = @html_tags[$1.downcase]
|
|
213
|
-
html_length = $~.match_length(1) + 2 # "<>".length
|
|
214
|
-
seq = NULL * html_length
|
|
215
|
-
attrs.set_attrs($~.begin(2), $~.match_length(2), attr)
|
|
216
|
-
seq + $2 + seq + NULL
|
|
217
|
-
}
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
##
|
|
221
|
-
# Converts regexp handling sequences to RDoc attributes
|
|
222
|
-
|
|
223
|
-
def convert_regexp_handlings(str, attrs, exclusive = false)
|
|
224
|
-
@regexp_handlings.each do |regexp, attribute|
|
|
225
|
-
next unless exclusive == exclusive?(attribute)
|
|
226
|
-
str.scan(regexp) do
|
|
227
|
-
capture = $~.size == 1 ? 0 : 1
|
|
228
|
-
|
|
229
|
-
s, e = $~.offset capture
|
|
230
|
-
|
|
231
|
-
attrs.set_attrs s, e - s, attribute | @attributes.regexp_handling
|
|
232
|
-
end
|
|
233
|
-
end
|
|
234
|
-
end
|
|
235
|
-
|
|
236
|
-
##
|
|
237
|
-
# Escapes regexp handling sequences of text to prevent conversion to RDoc
|
|
238
|
-
|
|
239
|
-
def mask_protected_sequences
|
|
240
|
-
# protect __send__, __FILE__, etc.
|
|
241
|
-
@str.gsub!(/__([a-z]+)__/i,
|
|
242
|
-
"_#{PROTECT_ATTR}_#{PROTECT_ATTR}\\1_#{PROTECT_ATTR}_#{PROTECT_ATTR}")
|
|
243
|
-
@str.gsub!(/(\A|[^\\])\\([#{Regexp.escape @protectable.join}])/m,
|
|
244
|
-
"\\1\\2#{PROTECT_ATTR}")
|
|
245
|
-
@str.gsub!(/\\(\\[#{Regexp.escape @protectable.join}])/m, "\\1")
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
##
|
|
249
|
-
# Unescapes regexp handling sequences of text
|
|
250
|
-
|
|
251
|
-
def unmask_protected_sequences
|
|
252
|
-
@str.gsub!(/(.)#{PROTECT_ATTR}/, "\\1\000")
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
##
|
|
256
|
-
# Adds a markup class with +name+ for words wrapped in the +start+ and
|
|
257
|
-
# +stop+ character. To make words wrapped with "*" bold:
|
|
258
|
-
#
|
|
259
|
-
# am.add_word_pair '*', '*', :BOLD
|
|
260
|
-
|
|
261
|
-
def add_word_pair(start, stop, name, exclusive = false)
|
|
262
|
-
raise ArgumentError, "Word flags may not start with '<'" if
|
|
263
|
-
start[0, 1] == '<'
|
|
264
|
-
|
|
265
|
-
bitmap = @attributes.bitmap_for name
|
|
266
|
-
|
|
267
|
-
if start == stop then
|
|
268
|
-
@matching_word_pairs[start] = bitmap
|
|
269
|
-
else
|
|
270
|
-
pattern = /(#{Regexp.escape start})(\S+)(#{Regexp.escape stop})/
|
|
271
|
-
@word_pair_map[pattern] = bitmap
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
@protectable << start[0, 1]
|
|
275
|
-
@protectable.uniq!
|
|
276
|
-
|
|
277
|
-
@exclusive_bitmap |= bitmap if exclusive
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
##
|
|
281
|
-
# Adds a markup class with +name+ for words surrounded by HTML tag +tag+.
|
|
282
|
-
# To process emphasis tags:
|
|
283
|
-
#
|
|
284
|
-
# am.add_html 'em', :EM
|
|
285
|
-
|
|
286
|
-
def add_html(tag, name, exclusive = false)
|
|
287
|
-
bitmap = @attributes.bitmap_for name
|
|
288
|
-
@html_tags[tag.downcase] = bitmap
|
|
289
|
-
@exclusive_bitmap |= bitmap if exclusive
|
|
290
|
-
end
|
|
291
|
-
|
|
292
|
-
##
|
|
293
|
-
# Adds a regexp handling for +pattern+ with +name+. A simple URL handler
|
|
294
|
-
# would be:
|
|
295
|
-
#
|
|
296
|
-
# @am.add_regexp_handling(/((https?:)\S+\w)/, :HYPERLINK)
|
|
297
|
-
|
|
298
|
-
def add_regexp_handling(pattern, name, exclusive = false)
|
|
299
|
-
bitmap = @attributes.bitmap_for(name)
|
|
300
|
-
@regexp_handlings << [pattern, bitmap]
|
|
301
|
-
@exclusive_bitmap |= bitmap if exclusive
|
|
302
|
-
end
|
|
303
|
-
|
|
304
|
-
##
|
|
305
|
-
# Processes +str+ converting attributes, HTML and regexp handlings
|
|
306
|
-
|
|
307
|
-
def flow(str)
|
|
308
|
-
@str = str.dup
|
|
309
|
-
|
|
310
|
-
mask_protected_sequences
|
|
311
|
-
|
|
312
|
-
@attrs = RDoc::Markup::AttrSpan.new @str.length, @exclusive_bitmap
|
|
313
|
-
|
|
314
|
-
convert_attrs @str, @attrs, true
|
|
315
|
-
convert_html @str, @attrs, true
|
|
316
|
-
convert_regexp_handlings @str, @attrs, true
|
|
317
|
-
convert_attrs @str, @attrs
|
|
318
|
-
convert_html @str, @attrs
|
|
319
|
-
convert_regexp_handlings @str, @attrs
|
|
320
|
-
|
|
321
|
-
unmask_protected_sequences
|
|
322
|
-
|
|
323
|
-
split_into_flow
|
|
324
|
-
end
|
|
325
|
-
|
|
326
|
-
##
|
|
327
|
-
# Debug method that prints a string along with its attributes
|
|
328
|
-
|
|
329
|
-
def display_attributes
|
|
330
|
-
puts
|
|
331
|
-
puts @str.tr(NULL, "!")
|
|
332
|
-
bit = 1
|
|
333
|
-
16.times do |bno|
|
|
334
|
-
line = ""
|
|
335
|
-
@str.length.times do |i|
|
|
336
|
-
if (@attrs[i] & bit) == 0
|
|
337
|
-
line << " "
|
|
338
|
-
else
|
|
339
|
-
if bno.zero?
|
|
340
|
-
line << "S"
|
|
341
|
-
else
|
|
342
|
-
line << ("%d" % (bno+1))
|
|
343
|
-
end
|
|
344
|
-
end
|
|
345
|
-
end
|
|
346
|
-
puts(line) unless line =~ /^ *$/
|
|
347
|
-
bit <<= 1
|
|
348
|
-
end
|
|
349
|
-
end
|
|
350
|
-
|
|
351
|
-
##
|
|
352
|
-
# Splits the string into chunks by attribute change
|
|
353
|
-
|
|
354
|
-
def split_into_flow
|
|
355
|
-
res = []
|
|
356
|
-
current_attr = 0
|
|
357
|
-
|
|
358
|
-
str_len = @str.length
|
|
359
|
-
|
|
360
|
-
# skip leading invisible text
|
|
361
|
-
i = 0
|
|
362
|
-
i += 1 while i < str_len and @str[i].chr == "\0"
|
|
363
|
-
start_pos = i
|
|
364
|
-
|
|
365
|
-
# then scan the string, chunking it on attribute changes
|
|
366
|
-
while i < str_len
|
|
367
|
-
new_attr = @attrs[i]
|
|
368
|
-
if new_attr != current_attr
|
|
369
|
-
if i > start_pos
|
|
370
|
-
res << copy_string(start_pos, i)
|
|
371
|
-
start_pos = i
|
|
372
|
-
end
|
|
373
|
-
|
|
374
|
-
res << change_attribute(current_attr, new_attr)
|
|
375
|
-
current_attr = new_attr
|
|
376
|
-
|
|
377
|
-
if (current_attr & @attributes.regexp_handling) != 0 then
|
|
378
|
-
i += 1 while
|
|
379
|
-
i < str_len and (@attrs[i] & @attributes.regexp_handling) != 0
|
|
380
|
-
|
|
381
|
-
res << RDoc::Markup::RegexpHandling.new(current_attr,
|
|
382
|
-
copy_string(start_pos, i))
|
|
383
|
-
start_pos = i
|
|
384
|
-
next
|
|
385
|
-
end
|
|
386
|
-
end
|
|
387
|
-
|
|
388
|
-
# move on, skipping any invisible characters
|
|
389
|
-
begin
|
|
390
|
-
i += 1
|
|
391
|
-
end while i < str_len and @str[i].chr == "\0"
|
|
392
|
-
end
|
|
393
|
-
|
|
394
|
-
# tidy up trailing text
|
|
395
|
-
if start_pos < str_len
|
|
396
|
-
res << copy_string(start_pos, str_len)
|
|
397
|
-
end
|
|
398
|
-
|
|
399
|
-
# and reset to all attributes off
|
|
400
|
-
res << change_attribute(current_attr, 0) if current_attr != 0
|
|
401
|
-
|
|
402
|
-
res
|
|
403
|
-
end
|
|
404
|
-
|
|
405
|
-
end
|