Skip to content
This repository
Browse code

RDoc::Markup::ToLabel now handles HARD_BREAK specials

  • Loading branch information...
commit 0d2f3c3ca711a2f94b674066325709a708993f29 1 parent 0bba7d1
Eric Hodel authored November 25, 2012
8  lib/rdoc/markup/formatter.rb
@@ -109,7 +109,11 @@ def convert_special special
109 109
       end
110 110
     end
111 111
 
112  
-    raise "Unhandled special: #{special}" unless handled
  112
+    unless handled then
  113
+      special_name = @attributes.as_string special.type
  114
+
  115
+      raise RDoc::Error, "Unhandled special #{special_name}: #{special}"
  116
+    end
113 117
 
114 118
     special.text
115 119
   end
@@ -129,7 +133,7 @@ def convert_string string
129 133
   #
130 134
   #   alias accept_raw ignore
131 135
 
132  
-  def ignore node
  136
+  def ignore *node
133 137
   end
134 138
 
135 139
   ##
13  lib/rdoc/markup/formatter_test_case.rb
@@ -244,6 +244,18 @@ def test_accept_paragraph_b
244 244
       end
245 245
 
246 246
       ##
  247
+      # Calls accept_paragraph_br with a RDoc::Markup::Paragraph containing
  248
+      # a \<br>
  249
+
  250
+      def test_accept_paragraph_br
  251
+        @to.start_accepting
  252
+
  253
+        @to.accept_paragraph para 'one<br>two'
  254
+
  255
+        accept_paragraph_br
  256
+      end
  257
+
  258
+      ##
247 259
       # Calls accept_paragraph with a Paragraph containing a hard break
248 260
 
249 261
       def test_accept_paragraph_break
@@ -748,7 +760,6 @@ def test_list_verbatim # HACK overblown
748 760
 
749 761
         list_verbatim
750 762
       end
751  
-
752 763
     end
753 764
   end
754 765
 
2  lib/rdoc/markup/special.rb
@@ -33,7 +33,7 @@ def inspect # :nodoc:
33 33
   end
34 34
 
35 35
   def to_s # :nodoc:
36  
-    "Special: type=#{type}, name=#{RDoc::Markup::Attribute.as_string type}, text=#{text.dump}"
  36
+    "Special: type=#{type} text=#{text.dump}"
37 37
   end
38 38
 
39 39
 end
4  lib/rdoc/markup/to_html.rb
@@ -99,10 +99,10 @@ def initialize options, markup = nil
99 99
   # These methods handle special markup added by RDoc::Markup#add_special.
100 100
 
101 101
   ##
102  
-  # +special+ is a <code><br></code> that is not converted.
  102
+  # +special+ is a <code><br></code>
103 103
 
104 104
   def handle_special_HARD_BREAK special
105  
-    special.text
  105
+    '<br>'
106 106
   end
107 107
 
108 108
   ##
8  lib/rdoc/markup/to_html_snippet.rb
@@ -129,6 +129,14 @@ def handle_special_CROSSREF special
129 129
   end
130 130
 
131 131
   ##
  132
+  # +special+ is a <code><br></code>
  133
+
  134
+  def handle_special_HARD_BREAK special
  135
+    @characters -= 4
  136
+    '<br>'
  137
+  end
  138
+
  139
+  ##
132 140
   # Lists are paragraphs, but notes and labels have a separator
133 141
 
134 142
   def list_item_start list_item, list_type
19  lib/rdoc/markup/to_label.rb
@@ -7,6 +7,8 @@
7 7
 
8 8
 class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
9 9
 
  10
+  attr_reader :res # :nodoc:
  11
+
10 12
   ##
11 13
   # Creates a new formatter that will output HTML-safe labels
12 14
 
@@ -19,6 +21,8 @@ def initialize markup = nil
19 21
     add_tag :BOLD, '', ''
20 22
     add_tag :TT,   '', ''
21 23
     add_tag :EM,   '', ''
  24
+
  25
+    @res = []
22 26
   end
23 27
 
24 28
   ##
@@ -51,5 +55,20 @@ def handle_special_TIDYLINK special
51 55
     $1
52 56
   end
53 57
 
  58
+  alias accept_blank_line         ignore
  59
+  alias accept_block_quote        ignore
  60
+  alias accept_heading            ignore
  61
+  alias accept_list_end           ignore
  62
+  alias accept_list_item_end      ignore
  63
+  alias accept_list_item_start    ignore
  64
+  alias accept_list_start         ignore
  65
+  alias accept_paragraph          ignore
  66
+  alias accept_raw                ignore
  67
+  alias accept_rule               ignore
  68
+  alias accept_verbatim           ignore
  69
+  alias end_accepting             ignore
  70
+  alias handle_special_HARD_BREAK ignore
  71
+  alias start_accepting           ignore
  72
+
54 73
 end
55 74
 
7  lib/rdoc/markup/to_markdown.rb
@@ -31,6 +31,13 @@ def init_tags
31 31
   end
32 32
 
33 33
   ##
  34
+  # Adds a newline to the output
  35
+
  36
+  def handle_special_HARD_BREAK special
  37
+    "  \n"
  38
+  end
  39
+
  40
+  ##
34 41
   # Finishes consumption of `list`
35 42
 
36 43
   def accept_list_end list
7  lib/rdoc/markup/to_rdoc.rb
@@ -261,6 +261,13 @@ def handle_special_SUPPRESSED_CROSSREF special
261 261
   end
262 262
 
263 263
   ##
  264
+  # Adds a newline to the output
  265
+
  266
+  def handle_special_HARD_BREAK special
  267
+    "\n"
  268
+  end
  269
+
  270
+  ##
264 271
   # Prepares the visitor for text generation
265 272
 
266 273
   def start_accepting
4  test/test_rdoc_markup_to_ansi.rb
@@ -260,6 +260,10 @@ def accept_paragraph_b
260 260
     assert_equal "\e[0mreg \e[1mbold words\e[m reg\n", @to.end_accepting
261 261
   end
262 262
 
  263
+  def accept_paragraph_br
  264
+    assert_equal "\e[0mone\ntwo\n", @to.end_accepting
  265
+  end
  266
+
263 267
   def accept_paragraph_break
264 268
     assert_equal "\e[0mhello\nworld\n", @to.end_accepting
265 269
   end
5  test/test_rdoc_markup_to_bs.rb
@@ -268,6 +268,11 @@ def accept_paragraph_b
268 268
                  @to.end_accepting
269 269
   end
270 270
 
  271
+  def accept_paragraph_br
  272
+    skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars
  273
+    assert_equal "one\ntwo\n", @to.end_accepting
  274
+  end
  275
+
271 276
   def accept_paragraph_break
272 277
     skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars
273 278
     assert_equal "hello\nworld\n",
4  test/test_rdoc_markup_to_html.rb
@@ -241,6 +241,10 @@ def accept_paragraph_b
241 241
     assert_equal "\n<p>reg <strong>bold words</strong> reg</p>\n", @to.res.join
242 242
   end
243 243
 
  244
+  def accept_paragraph_br
  245
+    assert_equal "\n<p>one<br>two</p>\n", @to.res.join
  246
+  end
  247
+
244 248
   def accept_paragraph_break
245 249
     assert_equal "\n<p>hello<br>\nworld</p>\n", @to.res.join
246 250
   end
8  test/test_rdoc_markup_to_html_snippet.rb
@@ -262,10 +262,16 @@ def accept_paragraph_b
262 262
     assert_equal 18, @to.characters
263 263
   end
264 264
 
  265
+  def accept_paragraph_br
  266
+    assert_equal "<p>one<br>two\n", @to.res.join
  267
+
  268
+    assert_equal 6, @to.characters
  269
+  end
  270
+
265 271
   def accept_paragraph_break
266 272
     assert_equal "<p>hello<br>\nworld\n", @to.res.join
267 273
 
268  
-    assert_equal 15, @to.characters
  274
+    assert_equal 11, @to.characters
269 275
   end
270 276
 
271 277
   def accept_paragraph_i
64  test/test_rdoc_markup_to_label.rb
... ...
@@ -1,6 +1,8 @@
1 1
 require 'rdoc/test_case'
2 2
 
3  
-class TestRDocMarkupToLabel < RDoc::TestCase
  3
+class TestRDocMarkupToLabel < RDoc::Markup::FormatterTestCase
  4
+
  5
+  add_visitor_tests
4 6
 
5 7
   def setup
6 8
     super
@@ -8,6 +10,66 @@ def setup
8 10
     @to = RDoc::Markup::ToLabel.new
9 11
   end
10 12
 
  13
+  def empty
  14
+    assert_empty @to.res
  15
+  end
  16
+
  17
+  def end_accepting
  18
+    assert_equal %w[hi], @to.res
  19
+  end
  20
+
  21
+  alias accept_blank_line                             empty
  22
+  alias accept_block_quote                            empty
  23
+  alias accept_document                               empty
  24
+  alias accept_heading                                empty
  25
+  alias accept_heading_1                              empty
  26
+  alias accept_heading_2                              empty
  27
+  alias accept_heading_3                              empty
  28
+  alias accept_heading_4                              empty
  29
+  alias accept_heading_b                              empty
  30
+  alias accept_heading_suppressed_crossref            empty
  31
+  alias accept_list_end_bullet                        empty
  32
+  alias accept_list_end_label                         empty
  33
+  alias accept_list_end_lalpha                        empty
  34
+  alias accept_list_end_note                          empty
  35
+  alias accept_list_end_number                        empty
  36
+  alias accept_list_end_ualpha                        empty
  37
+  alias accept_list_item_end_bullet                   empty
  38
+  alias accept_list_item_end_label                    empty
  39
+  alias accept_list_item_end_lalpha                   empty
  40
+  alias accept_list_item_end_note                     empty
  41
+  alias accept_list_item_end_number                   empty
  42
+  alias accept_list_item_end_ualpha                   empty
  43
+  alias accept_list_item_start_bullet                 empty
  44
+  alias accept_list_item_start_label                  empty
  45
+  alias accept_list_item_start_lalpha                 empty
  46
+  alias accept_list_item_start_note                   empty
  47
+  alias accept_list_item_start_note_2                 empty
  48
+  alias accept_list_item_start_note_multi_description empty
  49
+  alias accept_list_item_start_note_multi_label       empty
  50
+  alias accept_list_item_start_number                 empty
  51
+  alias accept_list_item_start_ualpha                 empty
  52
+  alias accept_list_start_bullet                      empty
  53
+  alias accept_list_start_label                       empty
  54
+  alias accept_list_start_lalpha                      empty
  55
+  alias accept_list_start_note                        empty
  56
+  alias accept_list_start_number                      empty
  57
+  alias accept_list_start_ualpha                      empty
  58
+  alias accept_paragraph                              empty
  59
+  alias accept_paragraph_b                            empty
  60
+  alias accept_paragraph_br                           empty
  61
+  alias accept_paragraph_break                        empty
  62
+  alias accept_paragraph_i                            empty
  63
+  alias accept_paragraph_plus                         empty
  64
+  alias accept_paragraph_star                         empty
  65
+  alias accept_paragraph_underscore                   empty
  66
+  alias accept_raw                                    empty
  67
+  alias accept_rule                                   empty
  68
+  alias accept_verbatim                               empty
  69
+  alias list_nested                                   empty
  70
+  alias list_verbatim                                 empty
  71
+  alias start_accepting                               empty
  72
+
11 73
   def test_convert_bold
12 74
     assert_equal 'bold', @to.convert('<b>bold</b>')
13 75
     assert_equal 'bold', @to.convert('*bold*')
4  test/test_rdoc_markup_to_markdown.rb
@@ -258,6 +258,10 @@ def accept_paragraph_b
258 258
     assert_equal "reg **bold words** reg\n", @to.end_accepting
259 259
   end
260 260
 
  261
+  def accept_paragraph_br
  262
+    assert_equal "one  \ntwo\n", @to.end_accepting
  263
+  end
  264
+
261 265
   def accept_paragraph_break
262 266
     assert_equal "hello  \nworld\n", @to.end_accepting
263 267
   end
4  test/test_rdoc_markup_to_rdoc.rb
@@ -258,6 +258,10 @@ def accept_paragraph_b
258 258
     assert_equal "reg <b>bold words</b> reg\n", @to.end_accepting
259 259
   end
260 260
 
  261
+  def accept_paragraph_br
  262
+    assert_equal "one\ntwo\n", @to.end_accepting
  263
+  end
  264
+
261 265
   def accept_paragraph_break
262 266
     assert_equal "hello\nworld\n", @to.end_accepting
263 267
   end
1  test/test_rdoc_markup_to_table_of_contents.rb
@@ -78,6 +78,7 @@ def accept_heading_suppressed_crossref
78 78
   alias accept_list_start_ualpha                      empty
79 79
   alias accept_paragraph                              empty
80 80
   alias accept_paragraph_b                            empty
  81
+  alias accept_paragraph_br                           empty
81 82
   alias accept_paragraph_break                        empty
82 83
   alias accept_paragraph_i                            empty
83 84
   alias accept_paragraph_plus                         empty
4  test/test_rdoc_markup_to_tt_only.rb
@@ -194,6 +194,10 @@ def accept_paragraph_b
194 194
     assert_empty @to.end_accepting
195 195
   end
196 196
 
  197
+  def accept_paragraph_br
  198
+    assert_empty @to.end_accepting
  199
+  end
  200
+
197 201
   def accept_paragraph_i
198 202
     assert_empty @to.end_accepting
199 203
   end

0 notes on commit 0d2f3c3

Please sign in to comment.
Something went wrong with that request. Please try again.