diff options
| author | Ryan Waldron <rwaldron@github.com> | 2012-12-17 06:59:18 -0800 |
|---|---|---|
| committer | Ryan Waldron <rwaldron@github.com> | 2012-12-17 06:59:18 -0800 |
| commit | 00d33fa51df754e9eea73341c35970abdd320eda (patch) | |
| tree | 55087ee10ab1c794f74cf437ffe48378782fdf8f | |
| parent | c266dacecc57f126dce38841409d78e5d35a64d2 (diff) | |
| parent | 142b1f281a0f18794969c7f774d0d45c73ca53a9 (diff) | |
Merge pull request #17 from mojavelinux/chomp-and-cleanup
Chomp non-semantic endlines and cleanups
| -rw-r--r-- | lib/asciidoctor/block.rb | 4 | ||||
| -rw-r--r-- | lib/asciidoctor/lexer.rb | 8 | ||||
| -rw-r--r-- | lib/asciidoctor/reader.rb | 4 | ||||
| -rw-r--r-- | lib/asciidoctor/render_templates.rb | 49 | ||||
| -rw-r--r-- | test/attributes_test.rb | 10 | ||||
| -rw-r--r-- | test/headers_test.rb | 33 | ||||
| -rw-r--r-- | test/paragraphs_test.rb | 6 | ||||
| -rw-r--r-- | test/test_helper.rb | 2 |
8 files changed, 58 insertions, 58 deletions
diff --git a/lib/asciidoctor/block.rb b/lib/asciidoctor/block.rb index 1bdf9695..3c5b8895 100644 --- a/lib/asciidoctor/block.rb +++ b/lib/asciidoctor/block.rb @@ -153,7 +153,7 @@ class Asciidoctor::Block #Asciidoctor.debug @buffer.inspect case @context - when :preamble, :oblock, :quote, :example, :sidebar + when :preamble, :oblock, :example, :sidebar blocks.map{|block| block.render}.join when :colist @buffer.map do |li| @@ -301,7 +301,7 @@ class Asciidoctor::Block end html.gsub!(Asciidoctor::REGEXP[:biblio], '<a name="\1">[\1]</a>') - html.gsub!(Asciidoctor::REGEXP[:ruler], '<hr>\n') + html.gsub!(Asciidoctor::REGEXP[:ruler], "<hr>\n") html.gsub!(/``([^`']*)''/m, '“\1”') html.gsub!(/(?:\s|^)`([^`']*)'/m, '‘\1’') diff --git a/lib/asciidoctor/lexer.rb b/lib/asciidoctor/lexer.rb index 68a6ea98..b1ff83a4 100644 --- a/lib/asciidoctor/lexer.rb +++ b/lib/asciidoctor/lexer.rb @@ -212,6 +212,7 @@ class Asciidoctor::Lexer elsif this_line.match(REGEXP[:listing]) rekey_positional_attributes(attributes, ['style', 'language', 'linenums']) buffer = reader.grab_lines_until {|line| line.match( REGEXP[:listing] )} + buffer.last.chomp! unless buffer.empty? block = Block.new(parent, :listing, buffer) elsif this_line.match(REGEXP[:quote]) @@ -236,6 +237,7 @@ class Asciidoctor::Lexer elsif this_line.match(REGEXP[:lit_blk]) # example is surrounded by '....' (4 or more '.' chars) lines buffer = reader.grab_lines_until {|line| line.match( REGEXP[:lit_blk] ) } + buffer.last.chomp! unless buffer.empty? block = Block.new(parent, :literal, buffer) elsif this_line.match(REGEXP[:lit_par]) @@ -252,6 +254,7 @@ class Asciidoctor::Lexer if !buffer.empty? && match = buffer.first.match(/^([[:blank:]]+)/) offset = match[1].length buffer = buffer.map {|l| l.slice(offset..-1)} + buffer.last.chomp! end block = Block.new(parent, :literal, buffer) @@ -262,6 +265,7 @@ class Asciidoctor::Lexer rekey_positional_attributes(attributes, ['style', 'language', 'linenums']) reader.unshift(this_line) buffer = reader.grab_lines_until(:break_on_blank_lines => true) + buffer.last.chomp! unless buffer.empty? block = Block.new(parent, :listing, buffer) elsif admonition_style = ADMONITION_STYLES.detect{|s| attributes[0] == s} @@ -300,6 +304,7 @@ class Asciidoctor::Lexer attributes['name'] = admonition[1].downcase attributes['caption'] ||= admonition[1].capitalize else + buffer.last.chomp! unless buffer.empty? Asciidoctor.debug "Proud parent #{parent} getting a new paragraph with buffer: #{buffer}" block = Block.new(parent, :paragraph, buffer) end @@ -601,7 +606,8 @@ class Asciidoctor::Lexer def self.is_two_line_section_heading?(line1, line2) !line1.nil? && !line2.nil? && line1.match(REGEXP[:name]) && line2.match(REGEXP[:line]) && - (line1.size - line2.size).abs <= 1 + # chomp so that a (non-visible) endline does not impact calculation + (line1.chomp.size - line2.chomp.size).abs <= 1 end def self.is_section_heading?(line1, line2 = nil) diff --git a/lib/asciidoctor/reader.rb b/lib/asciidoctor/reader.rb index 3f7df6b7..aa4d47a2 100644 --- a/lib/asciidoctor/reader.rb +++ b/lib/asciidoctor/reader.rb @@ -83,12 +83,12 @@ class Asciidoctor::Reader # Lines that start with whitespace and end with a '+' are # a continuation, so gobble them up into `value` if match = line.match(/\s+(.+)\s+\+\s*$/) - continuing_value += match[1] + continuing_value += ' ' + match[1] elsif match = line.match(/\s+(.+)/) # If this continued line doesn't end with a +, then this # is the end of the continuation, no matter what the next # line does. - continuing_value += match[1] + continuing_value += ' ' + match[1] close_continue = true else # If this line doesn't start with whitespace, then it's diff --git a/lib/asciidoctor/render_templates.rb b/lib/asciidoctor/render_templates.rb index 38962368..ea78eddb 100644 --- a/lib/asciidoctor/render_templates.rb +++ b/lib/asciidoctor/render_templates.rb @@ -242,9 +242,7 @@ class SectionVerseTemplate < BaseTemplate <% if !title.nil? %> <div class='title'><%= title %></div> <% end %> - <pre class='content'> - <%= content %> - </pre> + <pre class='content'><%= content %></pre> <div class='attribution'> <% if attr? :citetitle %> <em><%= attr :citetitle %></em> @@ -317,48 +315,3 @@ class SectionImageTemplate < BaseTemplate EOF end end - -=begin -../gitscm-next/templates/section_colist.html.erb -<div class='colist arabic'> - <ol> - <% content.each do |li| %> - <li><p><%= li %></p></li> - <% end %> - </ol> -</div> -../gitscm-next/templates/section_example.html.erb -<div class='exampleblock'> - <div class='content'> - <div class='literalblock'> - <div class='content'> - <pre><tt><%= content %></tt></pre> - </div> - </div> - </div> -</div> -../gitscm-next/templates/section_oblock.html.erb -<div class='openblock'> - <div class='content'> - <%= content %> - </div> -</div> -../gitscm-next/templates/section_olist.html.erb -<div class='olist arabic'> - <ol class='arabic'> - <% content.each do |li| %> - <li><p><%= li %></p></li> - <% end %> - </ol> -</div> -../gitscm-next/templates/section_quote.html.erb -<div class='quoteblock'> - <div class='content'> - <%= content %> - </div> -</div> -../gitscm-next/templates/section_verse.html.erb -<div class='verseblock'> - <pre class='content'><%= content %></pre> -</div> -=end diff --git a/test/attributes_test.rb b/test/attributes_test.rb index d118e763..3fd2ba3b 100644 --- a/test/attributes_test.rb +++ b/test/attributes_test.rb @@ -6,6 +6,16 @@ context "Attributes" do assert_equal doc.attributes['frog'], 'Tanglefoot' end + test "creates an attribute by fusing a multi-line value" do + str = <<-EOS +:description: This is the first + + Ruby implementation of + + AsciiDoc. + EOS + doc = document_from_string(str) + assert_equal doc.attributes['description'], 'This is the first Ruby implementation of AsciiDoc.' + end + test "deletes an attribute" do doc = document_from_string(":frog: Tanglefoot\n:frog!:") assert_equal nil, doc.attributes['frog'] diff --git a/test/headers_test.rb b/test/headers_test.rb index 4289b817..fcf98ab4 100644 --- a/test/headers_test.rb +++ b/test/headers_test.rb @@ -2,7 +2,38 @@ require 'test_helper' context "Headers" do test "document title with multiline syntax" do - assert_xpath "//h1[not(@id)][text() = 'My Title']", render_string("My Title\n=======") + title = "My Title" + chars = "=" * title.length + assert_xpath "//h1[not(@id)][text() = 'My Title']", render_string(title + "\n" + chars) + assert_xpath "//h1[not(@id)][text() = 'My Title']", render_string(title + "\n" + chars + "\n") + end + + test "document title with multiline syntax, give a char" do + title = "My Title" + chars = "=" * (title.length + 1) + assert_xpath "//h1[not(@id)][text() = 'My Title']", render_string(title + "\n" + chars) + assert_xpath "//h1[not(@id)][text() = 'My Title']", render_string(title + "\n" + chars + "\n") + end + + test "document title with multiline syntax, take a char" do + title = "My Title" + chars = "=" * (title.length - 1) + assert_xpath "//h1[not(@id)][text() = 'My Title']", render_string(title + "\n" + chars) + assert_xpath "//h1[not(@id)][text() = 'My Title']", render_string(title + "\n" + chars + "\n") + end + + test "not enough chars for a multiline document title" do + title = "My Title" + chars = "=" * (title.length - 2) + assert_xpath '//h1', render_string(title + "\n" + chars), 0 + assert_xpath '//h1', render_string(title + "\n" + chars + "\n"), 0 + end + + test "too many chars for a multiline document title" do + title = "My Title" + chars = "=" * (title.length + 2) + assert_xpath '//h1', render_string(title + "\n" + chars), 0 + assert_xpath '//h1', render_string(title + "\n" + chars + "\n"), 0 end test "document title with single-line syntax" do diff --git a/test/paragraphs_test.rb b/test/paragraphs_test.rb index 93f847b9..2f36c8f0 100644 --- a/test/paragraphs_test.rb +++ b/test/paragraphs_test.rb @@ -32,10 +32,9 @@ Install instructions: You're good to go! EOS - # TODO push this into the render_string helper, but need to update assertions to deal w/ endlines - output = Asciidoctor::Document.new(input.lines.entries).render + output = render_string(input) assert_xpath "//pre/tt", output, 1 - assert_match /^gem install asciidoctor/, output, "Indendation should be trimmed from literal block" + assert_match /^gem install asciidoctor/, output, "Indentation should be trimmed from literal block" end test "listing paragraph" do @@ -72,6 +71,7 @@ You're good to go! output = render_string("[quote]\nFamous quote.") assert_xpath '//*[@class = "quoteblock"]', output, 1 assert_xpath '//*[@class = "quoteblock"]//p', output, 0 + assert_xpath '//*[@class = "quoteblock"]//*[contains(text(), "Famous quote.")]', output, 1 end test "verse paragraph" do diff --git a/test/test_helper.rb b/test/test_helper.rb index 0e2f7b9d..a6577e8f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -63,7 +63,7 @@ class Test::Unit::TestCase end def document_from_string(src, opts = {}) - Asciidoctor::Document.new(src.split("\n"), opts) + Asciidoctor::Document.new(src.lines.entries, opts) end def render_string(src, opts = {}) |
