Permalink
Browse files

RDoc::Markup::ToLabel now handles HARD_BREAK specials

  • Loading branch information...
1 parent 0bba7d1 commit 0d2f3c3ca711a2f94b674066325709a708993f29 @drbrain drbrain committed Nov 26, 2012
@@ -109,7 +109,11 @@ def convert_special special
end
end
- raise "Unhandled special: #{special}" unless handled
+ unless handled then
+ special_name = @attributes.as_string special.type
+
+ raise RDoc::Error, "Unhandled special #{special_name}: #{special}"
+ end
special.text
end
@@ -129,7 +133,7 @@ def convert_string string
#
# alias accept_raw ignore
- def ignore node
+ def ignore *node
end
##
@@ -244,6 +244,18 @@ def test_accept_paragraph_b
end
##
+ # Calls accept_paragraph_br with a RDoc::Markup::Paragraph containing
+ # a \<br>
+
+ def test_accept_paragraph_br
+ @to.start_accepting
+
+ @to.accept_paragraph para 'one<br>two'
+
+ accept_paragraph_br
+ end
+
+ ##
# Calls accept_paragraph with a Paragraph containing a hard break
def test_accept_paragraph_break
@@ -748,7 +760,6 @@ def test_list_verbatim # HACK overblown
list_verbatim
end
-
end
end
@@ -33,7 +33,7 @@ def inspect # :nodoc:
end
def to_s # :nodoc:
- "Special: type=#{type}, name=#{RDoc::Markup::Attribute.as_string type}, text=#{text.dump}"
+ "Special: type=#{type} text=#{text.dump}"
end
end
@@ -99,10 +99,10 @@ def initialize options, markup = nil
# These methods handle special markup added by RDoc::Markup#add_special.
##
- # +special+ is a <code><br></code> that is not converted.
+ # +special+ is a <code><br></code>
def handle_special_HARD_BREAK special
- special.text
+ '<br>'
end
##
@@ -129,6 +129,14 @@ def handle_special_CROSSREF special
end
##
+ # +special+ is a <code><br></code>
+
+ def handle_special_HARD_BREAK special
+ @characters -= 4
+ '<br>'
+ end
+
+ ##
# Lists are paragraphs, but notes and labels have a separator
def list_item_start list_item, list_type
@@ -7,6 +7,8 @@
class RDoc::Markup::ToLabel < RDoc::Markup::Formatter
+ attr_reader :res # :nodoc:
+
##
# Creates a new formatter that will output HTML-safe labels
@@ -19,6 +21,8 @@ def initialize markup = nil
add_tag :BOLD, '', ''
add_tag :TT, '', ''
add_tag :EM, '', ''
+
+ @res = []
end
##
@@ -51,5 +55,20 @@ def handle_special_TIDYLINK special
$1
end
+ alias accept_blank_line ignore
+ alias accept_block_quote ignore
+ alias accept_heading ignore
+ alias accept_list_end ignore
+ alias accept_list_item_end ignore
+ alias accept_list_item_start ignore
+ alias accept_list_start ignore
+ alias accept_paragraph ignore
+ alias accept_raw ignore
+ alias accept_rule ignore
+ alias accept_verbatim ignore
+ alias end_accepting ignore
+ alias handle_special_HARD_BREAK ignore
+ alias start_accepting ignore
+
end
@@ -31,6 +31,13 @@ def init_tags
end
##
+ # Adds a newline to the output
+
+ def handle_special_HARD_BREAK special
+ " \n"
+ end
+
+ ##
# Finishes consumption of `list`
def accept_list_end list
@@ -261,6 +261,13 @@ def handle_special_SUPPRESSED_CROSSREF special
end
##
+ # Adds a newline to the output
+
+ def handle_special_HARD_BREAK special
+ "\n"
+ end
+
+ ##
# Prepares the visitor for text generation
def start_accepting
@@ -260,6 +260,10 @@ def accept_paragraph_b
assert_equal "\e[0mreg \e[1mbold words\e[m reg\n", @to.end_accepting
end
+ def accept_paragraph_br
+ assert_equal "\e[0mone\ntwo\n", @to.end_accepting
+ end
+
def accept_paragraph_break
assert_equal "\e[0mhello\nworld\n", @to.end_accepting
end
@@ -268,6 +268,11 @@ def accept_paragraph_b
@to.end_accepting
end
+ def accept_paragraph_br
+ skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars
+ assert_equal "one\ntwo\n", @to.end_accepting
+ end
+
def accept_paragraph_break
skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars
assert_equal "hello\nworld\n",
@@ -241,6 +241,10 @@ def accept_paragraph_b
assert_equal "\n<p>reg <strong>bold words</strong> reg</p>\n", @to.res.join
end
+ def accept_paragraph_br
+ assert_equal "\n<p>one<br>two</p>\n", @to.res.join
+ end
+
def accept_paragraph_break
assert_equal "\n<p>hello<br>\nworld</p>\n", @to.res.join
end
@@ -262,10 +262,16 @@ def accept_paragraph_b
assert_equal 18, @to.characters
end
+ def accept_paragraph_br
+ assert_equal "<p>one<br>two\n", @to.res.join
+
+ assert_equal 6, @to.characters
+ end
+
def accept_paragraph_break
assert_equal "<p>hello<br>\nworld\n", @to.res.join
- assert_equal 15, @to.characters
+ assert_equal 11, @to.characters
end
def accept_paragraph_i
@@ -1,13 +1,75 @@
require 'rdoc/test_case'
-class TestRDocMarkupToLabel < RDoc::TestCase
+class TestRDocMarkupToLabel < RDoc::Markup::FormatterTestCase
+
+ add_visitor_tests
def setup
super
@to = RDoc::Markup::ToLabel.new
end
+ def empty
+ assert_empty @to.res
+ end
+
+ def end_accepting
+ assert_equal %w[hi], @to.res
+ end
+
+ alias accept_blank_line empty
+ alias accept_block_quote empty
+ alias accept_document empty
+ alias accept_heading empty
+ alias accept_heading_1 empty
+ alias accept_heading_2 empty
+ alias accept_heading_3 empty
+ alias accept_heading_4 empty
+ alias accept_heading_b empty
+ alias accept_heading_suppressed_crossref empty
+ alias accept_list_end_bullet empty
+ alias accept_list_end_label empty
+ alias accept_list_end_lalpha empty
+ alias accept_list_end_note empty
+ alias accept_list_end_number empty
+ alias accept_list_end_ualpha empty
+ alias accept_list_item_end_bullet empty
+ alias accept_list_item_end_label empty
+ alias accept_list_item_end_lalpha empty
+ alias accept_list_item_end_note empty
+ alias accept_list_item_end_number empty
+ alias accept_list_item_end_ualpha empty
+ alias accept_list_item_start_bullet empty
+ alias accept_list_item_start_label empty
+ alias accept_list_item_start_lalpha empty
+ alias accept_list_item_start_note empty
+ alias accept_list_item_start_note_2 empty
+ alias accept_list_item_start_note_multi_description empty
+ alias accept_list_item_start_note_multi_label empty
+ alias accept_list_item_start_number empty
+ alias accept_list_item_start_ualpha empty
+ alias accept_list_start_bullet empty
+ alias accept_list_start_label empty
+ alias accept_list_start_lalpha empty
+ alias accept_list_start_note empty
+ alias accept_list_start_number empty
+ alias accept_list_start_ualpha empty
+ alias accept_paragraph empty
+ alias accept_paragraph_b empty
+ alias accept_paragraph_br empty
+ alias accept_paragraph_break empty
+ alias accept_paragraph_i empty
+ alias accept_paragraph_plus empty
+ alias accept_paragraph_star empty
+ alias accept_paragraph_underscore empty
+ alias accept_raw empty
+ alias accept_rule empty
+ alias accept_verbatim empty
+ alias list_nested empty
+ alias list_verbatim empty
+ alias start_accepting empty
+
def test_convert_bold
assert_equal 'bold', @to.convert('<b>bold</b>')
assert_equal 'bold', @to.convert('*bold*')
@@ -258,6 +258,10 @@ def accept_paragraph_b
assert_equal "reg **bold words** reg\n", @to.end_accepting
end
+ def accept_paragraph_br
+ assert_equal "one \ntwo\n", @to.end_accepting
+ end
+
def accept_paragraph_break
assert_equal "hello \nworld\n", @to.end_accepting
end
@@ -258,6 +258,10 @@ def accept_paragraph_b
assert_equal "reg <b>bold words</b> reg\n", @to.end_accepting
end
+ def accept_paragraph_br
+ assert_equal "one\ntwo\n", @to.end_accepting
+ end
+
def accept_paragraph_break
assert_equal "hello\nworld\n", @to.end_accepting
end
@@ -78,6 +78,7 @@ def accept_heading_suppressed_crossref
alias accept_list_start_ualpha empty
alias accept_paragraph empty
alias accept_paragraph_b empty
+ alias accept_paragraph_br empty
alias accept_paragraph_break empty
alias accept_paragraph_i empty
alias accept_paragraph_plus empty
@@ -194,6 +194,10 @@ def accept_paragraph_b
assert_empty @to.end_accepting
end
+ def accept_paragraph_br
+ assert_empty @to.end_accepting
+ end
+
def accept_paragraph_i
assert_empty @to.end_accepting
end

0 comments on commit 0d2f3c3

Please sign in to comment.