diff options
| -rwxr-xr-x | lib/asciidoctor.rb | 5 | ||||
| -rw-r--r-- | lib/asciidoctor/backends/docbook45.rb | 9 | ||||
| -rw-r--r-- | lib/asciidoctor/backends/html5.rb | 9 | ||||
| -rw-r--r-- | lib/asciidoctor/block.rb | 2 | ||||
| -rw-r--r-- | lib/asciidoctor/lexer.rb | 9 | ||||
| -rw-r--r-- | lib/asciidoctor/reader.rb | 3 | ||||
| -rw-r--r-- | lib/asciidoctor/substituters.rb | 26 | ||||
| -rw-r--r-- | test/blocks_test.rb | 46 | ||||
| -rw-r--r-- | test/document_test.rb | 4 |
9 files changed, 102 insertions, 11 deletions
diff --git a/lib/asciidoctor.rb b/lib/asciidoctor.rb index 7b8a1112..64612bcf 100755 --- a/lib/asciidoctor.rb +++ b/lib/asciidoctor.rb @@ -205,7 +205,7 @@ module Asciidoctor :listing => /^\-{4,}\s*$/, # .... - :lit_blk => /^\.{4,}\s*$/, + :literal => /^\.{4,}\s*$/, # <TAB>Foo or one-or-more-spaces-or-tabs then whatever :lit_par => /^([[:blank:]]+.*)$/, @@ -221,6 +221,9 @@ module Asciidoctor # I. Foo (upperroman) :olist => /^\s*(\d+\.|[a-z]\.|[ivx]+\)|\.{1,5}) +(.*)$/i, + # ++++ + :pass => /^\+{4,}\s*$/, + # inline passthrough macros # +++text+++ # $$text$$ diff --git a/lib/asciidoctor/backends/docbook45.rb b/lib/asciidoctor/backends/docbook45.rb index 5553395b..7d26d835 100644 --- a/lib/asciidoctor/backends/docbook45.rb +++ b/lib/asciidoctor/backends/docbook45.rb @@ -341,6 +341,15 @@ class BlockVerseTemplate < ::Asciidoctor::BaseTemplate end end +class BlockPassTemplate < ::Asciidoctor::BaseTemplate + def template + @template ||= ERB.new <<-EOS +<%#encoding:UTF-8%> +<%= content %> + EOS + end +end + class BlockImageTemplate < ::Asciidoctor::BaseTemplate def template @template ||= ERB.new <<-EOF diff --git a/lib/asciidoctor/backends/html5.rb b/lib/asciidoctor/backends/html5.rb index c7397386..327d796c 100644 --- a/lib/asciidoctor/backends/html5.rb +++ b/lib/asciidoctor/backends/html5.rb @@ -366,6 +366,15 @@ class BlockColistTemplate < ::Asciidoctor::BaseTemplate end end +class BlockPassTemplate < ::Asciidoctor::BaseTemplate + def template + @template ||= ERB.new <<-EOS +<%#encoding:UTF-8%> +<%= content %> + EOS + end +end + class BlockImageTemplate < ::Asciidoctor::BaseTemplate def template @template ||= ERB.new <<-EOS diff --git a/lib/asciidoctor/block.rb b/lib/asciidoctor/block.rb index e27b7fb4..35e9906e 100644 --- a/lib/asciidoctor/block.rb +++ b/lib/asciidoctor/block.rb @@ -111,6 +111,8 @@ class Asciidoctor::Block < Asciidoctor::AbstractBlock @buffer when :listing, :literal apply_literal_subs(@buffer) + when :pass + apply_passthrough_subs(@buffer) when :quote, :verse, :admonition if !@buffer.nil? apply_normal_subs(@buffer) diff --git a/lib/asciidoctor/lexer.rb b/lib/asciidoctor/lexer.rb index 8a611d7e..5411aa6c 100644 --- a/lib/asciidoctor/lexer.rb +++ b/lib/asciidoctor/lexer.rb @@ -267,11 +267,12 @@ class Asciidoctor::Lexer block = Block.new(parent, quote_context, block_reader.lines) end - 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] ) } + elsif blk_ctx = [:literal, :pass].detect{|blk_ctx| this_line.match(REGEXP[blk_ctx])} + # literal is surrounded by '....' (4 or more '.' chars) lines + # pass is surrounded by '++++' (4 or more '+' chars) lines + buffer = reader.grab_lines_until {|line| line.match( REGEXP[blk_ctx] ) } buffer.last.chomp! unless buffer.empty? - block = Block.new(parent, :literal, buffer) + block = Block.new(parent, blk_ctx, buffer) elsif this_line.match(REGEXP[:lit_par]) # literal paragraph is contiguous lines starting with diff --git a/lib/asciidoctor/reader.rb b/lib/asciidoctor/reader.rb index c248aff5..2c94423a 100644 --- a/lib/asciidoctor/reader.rb +++ b/lib/asciidoctor/reader.rb @@ -379,8 +379,7 @@ class Asciidoctor::Reader m = $~ subs = [] if !m[1].empty? - sub_options = Asciidoctor::Substituters::COMPOSITE_SUBS.keys + Asciidoctor::Substituters::COMPOSITE_SUBS[:normal] - subs = m[1].split(',').map {|sub| sub.to_sym} & sub_options + subs = @document.resolve_subs(m[1]) end if !subs.empty? @document.apply_subs(m[2], subs) diff --git a/lib/asciidoctor/substituters.rb b/lib/asciidoctor/substituters.rb index 95c6c0c5..d74c265e 100644 --- a/lib/asciidoctor/substituters.rb +++ b/lib/asciidoctor/substituters.rb @@ -10,6 +10,8 @@ module Asciidoctor :verbatim => [:specialcharacters, :callouts] } + SUB_OPTIONS = COMPOSITE_SUBS.keys + COMPOSITE_SUBS[:normal] + # Internal: A String Array of passthough (unprocessed) text captured from this block attr_reader :passthroughs @@ -108,7 +110,12 @@ module Asciidoctor # # returns - A String Array with passthrough substitutions performed def apply_passthrough_subs(lines) - apply_subs(lines, [:attributes, :macros]) + if attr? 'subs' + subs = resolve_subs(attr('subs')) + else + subs = [:attributes, :macros] + end + apply_subs(lines.join, subs) end # Internal: Extract the passthrough text from the document for reinsertion after processing. @@ -131,7 +138,8 @@ module Asciidoctor if m[1] == '$$' subs = [:specialcharacters] elsif !m[3].nil? && !m[3].empty? - subs = m[3].split(',').map {|sub| sub.to_sym} + #subs = m[3].split(',').map {|sub| sub.to_sym} + subs = resolve_subs(m[3]) else subs = [] end @@ -415,5 +423,19 @@ module Asciidoctor AttributeList.new(attrline, self).parse(posattrs) end + + # Internal: Resolve the list of comma-delimited subs against the possible options. + # + # subs - A comma-delimited String of substitution aliases + # + # returns An Array of Symbols representing the substitution operation + def resolve_subs(subs) + candidates = subs.split(',').map {|sub| sub.strip.to_sym} + resolved = candidates & SUB_OPTIONS + if (invalid = candidates - resolved).size > 0 + puts "asciidoctor: WARNING: invalid passthrough macro substitution operation#{invalid.size > 1 ? 's' : ''}: #{invalid * ', '}" + end + resolved + end end end diff --git a/test/blocks_test.rb b/test/blocks_test.rb index 6a1460ea..6d28dd74 100644 --- a/test/blocks_test.rb +++ b/test/blocks_test.rb @@ -151,6 +151,52 @@ ____ end end + context 'Passthrough Blocks' do + test 'can parse a passthrough block' do + input = <<-EOS +++++ +This is a passthrough block. +++++ + EOS + + block = block_from_string input + assert !block.nil? + assert_equal 1, block.buffer.size + assert_equal 'This is a passthrough block.', block.buffer.first + end + + test 'performs passthrough subs on a passthrough block' do + input = <<-EOS +:type: passthrough + +++++ +This is a '{type}' block. +http://asciidoc.org +++++ + EOS + + expected = %(This is a 'passthrough' block.\n<a href="http://asciidoc.org">http://asciidoc.org</a>\n) + output = render_embedded_string input + assert_equal expected, output + end + + test 'passthrough block honors explicit subs list' do + input = <<-EOS +:type: passthrough + +[subs="attributes, quotes"] +++++ +This is a '{type}' block. +http://asciidoc.org +++++ + EOS + + expected = %(This is a <em>passthrough</em> block.\nhttp://asciidoc.org\n) + output = render_embedded_string input + assert_equal expected, output + end + end + context "Images" do test "can render block image with alt text" do input = <<-EOS diff --git a/test/document_test.rb b/test/document_test.rb index ecd33b22..729f905b 100644 --- a/test/document_test.rb +++ b/test/document_test.rb @@ -24,7 +24,7 @@ context 'Document' do assert !renderer.nil? views = renderer.views assert !views.nil? - assert_equal 24, views.size + assert_equal 25, views.size assert views.has_key? 'document' assert views['document'].is_a?(Asciidoctor::HTML5::DocumentTemplate) end @@ -39,7 +39,7 @@ context 'Document' do assert !renderer.nil? views = renderer.views assert !views.nil? - assert_equal 24, views.size + assert_equal 25, views.size assert views.has_key? 'document' assert views['document'].is_a?(Asciidoctor::DocBook45::DocumentTemplate) end |
