asciidoctor 0.1.4 → 1.5.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.
Potentially problematic release.
This version of asciidoctor might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +209 -25
- data/{LICENSE → LICENSE.adoc} +4 -3
- data/README.adoc +392 -395
- data/Rakefile +94 -137
- data/benchmark/benchmark.rb +127 -0
- data/benchmark/sample-data/mdbasics.adoc +334 -0
- data/bin/asciidoctor +5 -8
- data/bin/asciidoctor-safe +4 -8
- data/compat/asciidoc.conf +78 -11
- data/compat/font-awesome-3-compat.css +397 -0
- data/data/stylesheets/asciidoctor-default.css +399 -0
- data/data/stylesheets/coderay-asciidoctor.css +89 -0
- data/features/open_block.feature +92 -0
- data/features/pass_block.feature +66 -0
- data/features/step_definitions.rb +42 -0
- data/features/text_formatting.feature +55 -0
- data/features/xref.feature +116 -0
- data/lib/asciidoctor.rb +1155 -605
- data/lib/asciidoctor/abstract_block.rb +157 -71
- data/lib/asciidoctor/abstract_node.rb +150 -93
- data/lib/asciidoctor/attribute_list.rb +85 -90
- data/lib/asciidoctor/block.rb +51 -24
- data/lib/asciidoctor/callouts.rb +4 -7
- data/lib/asciidoctor/cli.rb +3 -0
- data/lib/asciidoctor/cli/invoker.rb +86 -76
- data/lib/asciidoctor/cli/options.rb +111 -61
- data/lib/asciidoctor/converter.rb +232 -0
- data/lib/asciidoctor/converter/base.rb +58 -0
- data/lib/asciidoctor/converter/composite.rb +66 -0
- data/lib/asciidoctor/converter/docbook45.rb +94 -0
- data/lib/asciidoctor/converter/docbook5.rb +684 -0
- data/lib/asciidoctor/converter/factory.rb +225 -0
- data/lib/asciidoctor/converter/html5.rb +1081 -0
- data/lib/asciidoctor/converter/template.rb +296 -0
- data/lib/asciidoctor/core_ext.rb +7 -0
- data/lib/asciidoctor/core_ext/object/nil_or_empty.rb +23 -0
- data/lib/asciidoctor/core_ext/string/chr.rb +6 -0
- data/lib/asciidoctor/core_ext/symbol/length.rb +6 -0
- data/lib/asciidoctor/document.rb +590 -304
- data/lib/asciidoctor/extensions.rb +1100 -308
- data/lib/asciidoctor/helpers.rb +109 -46
- data/lib/asciidoctor/inline.rb +16 -9
- data/lib/asciidoctor/list.rb +23 -15
- data/lib/asciidoctor/opal_ext.rb +4 -0
- data/lib/asciidoctor/opal_ext/comparable.rb +38 -0
- data/lib/asciidoctor/opal_ext/dir.rb +13 -0
- data/lib/asciidoctor/opal_ext/error.rb +2 -0
- data/lib/asciidoctor/opal_ext/file.rb +125 -0
- data/lib/asciidoctor/{lexer.rb → parser.rb} +646 -455
- data/lib/asciidoctor/path_resolver.rb +141 -77
- data/lib/asciidoctor/reader.rb +257 -187
- data/lib/asciidoctor/section.rb +12 -16
- data/lib/asciidoctor/stylesheets.rb +91 -0
- data/lib/asciidoctor/substitutors.rb +1548 -0
- data/lib/asciidoctor/table.rb +73 -57
- data/lib/asciidoctor/timings.rb +39 -0
- data/lib/asciidoctor/version.rb +1 -1
- data/man/asciidoctor.1 +22 -14
- data/man/asciidoctor.adoc +18 -10
- data/test/attributes_test.rb +314 -14
- data/test/blocks_test.rb +763 -118
- data/test/converter_test.rb +352 -0
- data/test/document_test.rb +518 -199
- data/test/extensions_test.rb +273 -103
- data/test/fixtures/asciidoc_index.txt +27 -13
- data/test/fixtures/basic-docinfo.xml +1 -1
- data/test/fixtures/chapter-a.adoc +3 -0
- data/test/fixtures/custom-backends/erb/html5/block_paragraph.html.erb +6 -0
- data/test/fixtures/docinfo.xml +1 -1
- data/test/fixtures/include-file.asciidoc +2 -0
- data/test/fixtures/master.adoc +5 -0
- data/test/invoker_test.rb +173 -61
- data/test/links_test.rb +97 -21
- data/test/lists_test.rb +181 -22
- data/test/options_test.rb +86 -2
- data/test/paragraphs_test.rb +47 -5
- data/test/{lexer_test.rb → parser_test.rb} +128 -57
- data/test/paths_test.rb +36 -1
- data/test/preamble_test.rb +25 -17
- data/test/reader_test.rb +404 -249
- data/test/sections_test.rb +623 -58
- data/test/substitutions_test.rb +609 -132
- data/test/tables_test.rb +198 -24
- data/test/test_helper.rb +101 -31
- data/test/text_test.rb +88 -31
- metadata +160 -64
- data/Gemfile +0 -12
- data/Guardfile +0 -18
- data/asciidoctor.gemspec +0 -143
- data/lib/asciidoctor/backends/_stylesheets.rb +0 -466
- data/lib/asciidoctor/backends/base_template.rb +0 -114
- data/lib/asciidoctor/backends/docbook45.rb +0 -774
- data/lib/asciidoctor/backends/docbook5.rb +0 -103
- data/lib/asciidoctor/backends/html5.rb +0 -1214
- data/lib/asciidoctor/renderer.rb +0 -259
- data/lib/asciidoctor/substituters.rb +0 -1083
- data/test/fixtures/asciidoc.txt +0 -105
- data/test/fixtures/ascshort.txt +0 -32
- data/test/fixtures/list_elements.asciidoc +0 -10
- data/test/renderer_test.rb +0 -162
    
        data/test/extensions_test.rb
    CHANGED
    
    | @@ -1,7 +1,14 @@ | |
| 1 | 
            -
             | 
| 1 | 
            +
            # encoding: UTF-8
         | 
| 2 | 
            +
            unless defined? ASCIIDOCTOR_PROJECT_DIR
         | 
| 3 | 
            +
              $: << File.dirname(__FILE__); $:.uniq!
         | 
| 4 | 
            +
              require 'test_helper'
         | 
| 5 | 
            +
            end
         | 
| 2 6 | 
             
            require 'asciidoctor/extensions'
         | 
| 3 7 |  | 
| 4 8 | 
             
            class SamplePreprocessor < Asciidoctor::Extensions::Preprocessor
         | 
| 9 | 
            +
              def process doc, reader
         | 
| 10 | 
            +
                nil
         | 
| 11 | 
            +
              end
         | 
| 5 12 | 
             
            end
         | 
| 6 13 |  | 
| 7 14 | 
             
            class SampleIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor
         | 
| @@ -23,12 +30,14 @@ class SampleInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor | |
| 23 30 | 
             
            end
         | 
| 24 31 |  | 
| 25 32 | 
             
            class ScrubHeaderPreprocessor < Asciidoctor::Extensions::Preprocessor
         | 
| 26 | 
            -
              def process  | 
| 33 | 
            +
              def process doc, reader
         | 
| 34 | 
            +
                lines = reader.lines
         | 
| 35 | 
            +
                skipped = []
         | 
| 27 36 | 
             
                while !lines.empty? && !lines.first.start_with?('=')
         | 
| 28 | 
            -
                  lines.shift
         | 
| 37 | 
            +
                  skipped << lines.shift
         | 
| 29 38 | 
             
                  reader.advance
         | 
| 30 39 | 
             
                end
         | 
| 31 | 
            -
                 | 
| 40 | 
            +
                doc.set_attr 'skipped', (skipped * "\n")
         | 
| 32 41 | 
             
                reader
         | 
| 33 42 | 
             
              end
         | 
| 34 43 | 
             
            end
         | 
| @@ -38,7 +47,7 @@ class BoilerplateTextIncludeProcessor < Asciidoctor::Extensions::IncludeProcesso | |
| 38 47 | 
             
                target.end_with? '.txt'
         | 
| 39 48 | 
             
              end
         | 
| 40 49 |  | 
| 41 | 
            -
              def process reader, target, attributes
         | 
| 50 | 
            +
              def process document, reader, target, attributes
         | 
| 42 51 | 
             
                case target
         | 
| 43 52 | 
             
                when 'lorem-ipsum.txt'
         | 
| 44 53 | 
             
                  content = ["Lorem ipsum dolor sit amet...\n"]
         | 
| @@ -50,84 +59,109 @@ class BoilerplateTextIncludeProcessor < Asciidoctor::Extensions::IncludeProcesso | |
| 50 59 | 
             
            end
         | 
| 51 60 |  | 
| 52 61 | 
             
            class ReplaceAuthorTreeprocessor < Asciidoctor::Extensions::Treeprocessor
         | 
| 53 | 
            -
              def process
         | 
| 54 | 
            -
                 | 
| 55 | 
            -
                 | 
| 62 | 
            +
              def process document
         | 
| 63 | 
            +
                document.attributes['firstname'] = 'Ghost'
         | 
| 64 | 
            +
                document.attributes['author'] = 'Ghost Writer'
         | 
| 65 | 
            +
                document
         | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
            end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
            class ReplaceTreeTreeprocessor < Asciidoctor::Extensions::Treeprocessor
         | 
| 70 | 
            +
              def process document
         | 
| 71 | 
            +
                if document.doctitle == 'Original Document'
         | 
| 72 | 
            +
                  Asciidoctor.load %(== Replacement Document\nReplacement Author\n\ncontent)
         | 
| 73 | 
            +
                else
         | 
| 74 | 
            +
                  document
         | 
| 75 | 
            +
                end
         | 
| 56 76 | 
             
              end
         | 
| 57 77 | 
             
            end
         | 
| 58 78 |  | 
| 59 79 | 
             
            class StripAttributesPostprocessor < Asciidoctor::Extensions::Postprocessor
         | 
| 60 | 
            -
              def process output
         | 
| 80 | 
            +
              def process document, output
         | 
| 61 81 | 
             
                output.gsub(/<(\w+).*?>/m, "<\\1>")
         | 
| 62 82 | 
             
              end
         | 
| 63 83 | 
             
            end
         | 
| 64 84 |  | 
| 65 | 
            -
            class UppercaseBlock < Asciidoctor::Extensions::BlockProcessor
         | 
| 85 | 
            +
            class UppercaseBlock < Asciidoctor::Extensions::BlockProcessor; use_dsl
         | 
| 86 | 
            +
              match_name :yell
         | 
| 87 | 
            +
              on_contexts :paragraph
         | 
| 88 | 
            +
              parse_content_as :simple
         | 
| 66 89 | 
             
              def process parent, reader, attributes
         | 
| 67 | 
            -
                 | 
| 90 | 
            +
                create_paragraph parent, reader.lines.map(&:upcase), attributes
         | 
| 68 91 | 
             
              end
         | 
| 69 92 | 
             
            end
         | 
| 70 93 |  | 
| 71 94 | 
             
            class SnippetMacro < Asciidoctor::Extensions::BlockMacroProcessor
         | 
| 72 95 | 
             
              def process parent, target, attributes
         | 
| 73 | 
            -
                 | 
| 96 | 
            +
                create_pass_block parent, %(<script src="http://example.com/#{target}.js"></script>), {}, :content_model => :raw
         | 
| 74 97 | 
             
              end
         | 
| 75 98 | 
             
            end
         | 
| 76 99 |  | 
| 77 | 
            -
            class TemperatureMacro < Asciidoctor::Extensions::InlineMacroProcessor
         | 
| 100 | 
            +
            class TemperatureMacro < Asciidoctor::Extensions::InlineMacroProcessor; use_dsl
         | 
| 101 | 
            +
              named :degrees
         | 
| 102 | 
            +
              name_attributes 'units'
         | 
| 78 103 | 
             
              def process parent, target, attributes
         | 
| 79 | 
            -
                 | 
| 104 | 
            +
                units = attributes['units'] || (parent.document.attr 'temperature-unit', 'C')
         | 
| 80 105 | 
             
                c = target.to_f
         | 
| 81 | 
            -
                 | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
                   | 
| 106 | 
            +
                case units
         | 
| 107 | 
            +
                when 'C'
         | 
| 108 | 
            +
                  %(#{c} °C)
         | 
| 109 | 
            +
                when 'F'
         | 
| 110 | 
            +
                  %(#{c * 1.8 + 32 } °F)
         | 
| 86 111 | 
             
                else
         | 
| 87 | 
            -
                   | 
| 112 | 
            +
                  c
         | 
| 88 113 | 
             
                end
         | 
| 89 | 
            -
             | 
| 90 | 
            -
                text
         | 
| 91 114 | 
             
              end
         | 
| 92 115 | 
             
            end
         | 
| 93 116 |  | 
| 94 | 
            -
            class  | 
| 95 | 
            -
              def  | 
| 96 | 
            -
                document.attributes['activate-method-called'] = ''
         | 
| 117 | 
            +
            class SampleExtensionGroup < Asciidoctor::Extensions::Group
         | 
| 118 | 
            +
              def activate registry
         | 
| 119 | 
            +
                registry.document.attributes['activate-method-called'] = ''
         | 
| 97 120 | 
             
                registry.preprocessor SamplePreprocessor
         | 
| 98 121 | 
             
              end
         | 
| 99 122 | 
             
            end
         | 
| 100 123 |  | 
| 101 124 | 
             
            context 'Extensions' do
         | 
| 102 125 | 
             
              context 'Register' do
         | 
| 103 | 
            -
                test 'should register extension class' do
         | 
| 126 | 
            +
                test 'should register extension group class' do
         | 
| 104 127 | 
             
                  begin
         | 
| 105 | 
            -
                    Asciidoctor::Extensions.register  | 
| 106 | 
            -
                     | 
| 107 | 
            -
                    assert_equal 1, Asciidoctor::Extensions. | 
| 108 | 
            -
                    assert_equal  | 
| 128 | 
            +
                    Asciidoctor::Extensions.register :sample, SampleExtensionGroup
         | 
| 129 | 
            +
                    refute_nil Asciidoctor::Extensions.groups
         | 
| 130 | 
            +
                    assert_equal 1, Asciidoctor::Extensions.groups.size
         | 
| 131 | 
            +
                    assert_equal SampleExtensionGroup, Asciidoctor::Extensions.groups[:sample]
         | 
| 109 132 | 
             
                  ensure
         | 
| 110 133 | 
             
                    Asciidoctor::Extensions.unregister_all
         | 
| 111 134 | 
             
                  end
         | 
| 112 135 | 
             
                end
         | 
| 113 136 |  | 
| 114 | 
            -
                test 'should  | 
| 137 | 
            +
                test 'should self register extension group class' do
         | 
| 115 138 | 
             
                  begin
         | 
| 116 | 
            -
                     | 
| 117 | 
            -
                     | 
| 118 | 
            -
                    assert_equal 1, Asciidoctor::Extensions. | 
| 119 | 
            -
                    assert_equal  | 
| 139 | 
            +
                    SampleExtensionGroup.register :sample
         | 
| 140 | 
            +
                    refute_nil Asciidoctor::Extensions.groups
         | 
| 141 | 
            +
                    assert_equal 1, Asciidoctor::Extensions.groups.size
         | 
| 142 | 
            +
                    assert_equal SampleExtensionGroup, Asciidoctor::Extensions.groups[:sample]
         | 
| 120 143 | 
             
                  ensure
         | 
| 121 144 | 
             
                    Asciidoctor::Extensions.unregister_all
         | 
| 122 145 | 
             
                  end
         | 
| 123 146 | 
             
                end
         | 
| 124 147 |  | 
| 125 | 
            -
                test 'should register extension  | 
| 148 | 
            +
                test 'should register extension group from class name' do
         | 
| 126 149 | 
             
                  begin
         | 
| 127 | 
            -
                    Asciidoctor::Extensions.register ' | 
| 128 | 
            -
                     | 
| 129 | 
            -
                    assert_equal 1, Asciidoctor::Extensions. | 
| 130 | 
            -
                    assert_equal  | 
| 150 | 
            +
                    Asciidoctor::Extensions.register :sample, 'SampleExtensionGroup'
         | 
| 151 | 
            +
                    refute_nil Asciidoctor::Extensions.groups
         | 
| 152 | 
            +
                    assert_equal 1, Asciidoctor::Extensions.groups.size
         | 
| 153 | 
            +
                    assert_equal SampleExtensionGroup, Asciidoctor::Extensions.groups[:sample]
         | 
| 154 | 
            +
                  ensure
         | 
| 155 | 
            +
                    Asciidoctor::Extensions.unregister_all
         | 
| 156 | 
            +
                  end
         | 
| 157 | 
            +
                end
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                test 'should register extension group from instance' do
         | 
| 160 | 
            +
                  begin
         | 
| 161 | 
            +
                    Asciidoctor::Extensions.register :sample, SampleExtensionGroup.new
         | 
| 162 | 
            +
                    refute_nil Asciidoctor::Extensions.groups
         | 
| 163 | 
            +
                    assert_equal 1, Asciidoctor::Extensions.groups.size
         | 
| 164 | 
            +
                    assert Asciidoctor::Extensions.groups[:sample].is_a? SampleExtensionGroup
         | 
| 131 165 | 
             
                  ensure
         | 
| 132 166 | 
             
                    Asciidoctor::Extensions.unregister_all
         | 
| 133 167 | 
             
                  end
         | 
| @@ -135,11 +169,11 @@ context 'Extensions' do | |
| 135 169 |  | 
| 136 170 | 
             
                test 'should register extension block' do
         | 
| 137 171 | 
             
                  begin
         | 
| 138 | 
            -
                    Asciidoctor::Extensions.register do | 
| 172 | 
            +
                    Asciidoctor::Extensions.register(:sample) do
         | 
| 139 173 | 
             
                    end
         | 
| 140 | 
            -
                     | 
| 141 | 
            -
                    assert_equal 1, Asciidoctor::Extensions. | 
| 142 | 
            -
                    assert Asciidoctor::Extensions. | 
| 174 | 
            +
                    refute_nil Asciidoctor::Extensions.groups
         | 
| 175 | 
            +
                    assert_equal 1, Asciidoctor::Extensions.groups.size
         | 
| 176 | 
            +
                    assert Asciidoctor::Extensions.groups[:sample].is_a? Proc
         | 
| 143 177 | 
             
                  ensure
         | 
| 144 178 | 
             
                    Asciidoctor::Extensions.unregister_all
         | 
| 145 179 | 
             
                  end
         | 
| @@ -147,26 +181,26 @@ context 'Extensions' do | |
| 147 181 |  | 
| 148 182 | 
             
                test 'should get class for top-level class name' do
         | 
| 149 183 | 
             
                  clazz = Asciidoctor::Extensions.class_for_name('Asciidoctor')
         | 
| 150 | 
            -
                   | 
| 184 | 
            +
                  refute_nil clazz
         | 
| 151 185 | 
             
                  assert_equal Asciidoctor, clazz
         | 
| 152 186 | 
             
                end
         | 
| 153 187 |  | 
| 154 188 | 
             
                test 'should get class for class name in module' do
         | 
| 155 189 | 
             
                  clazz = Asciidoctor::Extensions.class_for_name('Asciidoctor::Extensions')
         | 
| 156 | 
            -
                   | 
| 190 | 
            +
                  refute_nil clazz
         | 
| 157 191 | 
             
                  assert_equal Asciidoctor::Extensions, clazz
         | 
| 158 192 | 
             
                end
         | 
| 159 193 |  | 
| 160 194 | 
             
                test 'should get class for class name resolved from root' do
         | 
| 161 195 | 
             
                  clazz = Asciidoctor::Extensions.class_for_name('::Asciidoctor::Extensions')
         | 
| 162 | 
            -
                   | 
| 196 | 
            +
                  refute_nil clazz
         | 
| 163 197 | 
             
                  assert_equal Asciidoctor::Extensions, clazz
         | 
| 164 198 | 
             
                end
         | 
| 165 199 |  | 
| 166 200 | 
             
                test 'should raise exception if cannot find class for name' do
         | 
| 167 201 | 
             
                  begin
         | 
| 168 | 
            -
             | 
| 169 | 
            -
             | 
| 202 | 
            +
                    Asciidoctor::Extensions.class_for_name('InvalidModule::InvalidClass')
         | 
| 203 | 
            +
                    flunk 'Expecting RuntimeError to be raised'
         | 
| 170 204 | 
             
                  rescue RuntimeError => e
         | 
| 171 205 | 
             
                    assert_equal 'Could not resolve class for name: InvalidModule::InvalidClass', e.message
         | 
| 172 206 | 
             
                  end
         | 
| @@ -174,23 +208,24 @@ context 'Extensions' do | |
| 174 208 |  | 
| 175 209 | 
             
                test 'should resolve class if class is given' do
         | 
| 176 210 | 
             
                  clazz = Asciidoctor::Extensions.resolve_class(Asciidoctor::Extensions)
         | 
| 177 | 
            -
                   | 
| 211 | 
            +
                  refute_nil clazz
         | 
| 178 212 | 
             
                  assert_equal Asciidoctor::Extensions, clazz
         | 
| 179 213 | 
             
                end
         | 
| 180 214 |  | 
| 181 215 | 
             
                test 'should resolve class if class from string' do
         | 
| 182 216 | 
             
                  clazz = Asciidoctor::Extensions.resolve_class('Asciidoctor::Extensions')
         | 
| 183 | 
            -
                   | 
| 217 | 
            +
                  refute_nil clazz
         | 
| 184 218 | 
             
                  assert_equal Asciidoctor::Extensions, clazz
         | 
| 185 219 | 
             
                end
         | 
| 186 220 | 
             
              end
         | 
| 187 221 |  | 
| 188 222 | 
             
              context 'Activate' do
         | 
| 189 | 
            -
                test 'should call activate on extension class' do
         | 
| 223 | 
            +
                test 'should call activate on extension group class' do
         | 
| 190 224 | 
             
                  begin
         | 
| 191 225 | 
             
                    doc = Asciidoctor::Document.new
         | 
| 192 | 
            -
                    Asciidoctor::Extensions.register  | 
| 193 | 
            -
                    registry = Asciidoctor::Extensions::Registry.new | 
| 226 | 
            +
                    Asciidoctor::Extensions.register :sample, SampleExtensionGroup
         | 
| 227 | 
            +
                    registry = Asciidoctor::Extensions::Registry.new
         | 
| 228 | 
            +
                    registry.activate doc
         | 
| 194 229 | 
             
                    assert doc.attr? 'activate-method-called'
         | 
| 195 230 | 
             
                    assert registry.preprocessors?
         | 
| 196 231 | 
             
                  ensure
         | 
| @@ -201,11 +236,12 @@ context 'Extensions' do | |
| 201 236 | 
             
                test 'should invoke extension block' do
         | 
| 202 237 | 
             
                  begin
         | 
| 203 238 | 
             
                    doc = Asciidoctor::Document.new
         | 
| 204 | 
            -
                    Asciidoctor::Extensions.register do | 
| 205 | 
            -
                      document.attributes['block-called'] = ''
         | 
| 239 | 
            +
                    Asciidoctor::Extensions.register do
         | 
| 240 | 
            +
                      @document.attributes['block-called'] = ''
         | 
| 206 241 | 
             
                      preprocessor SamplePreprocessor
         | 
| 207 242 | 
             
                    end
         | 
| 208 | 
            -
                    registry = Asciidoctor::Extensions::Registry.new | 
| 243 | 
            +
                    registry = Asciidoctor::Extensions::Registry.new
         | 
| 244 | 
            +
                    registry.activate doc
         | 
| 209 245 | 
             
                    assert doc.attr? 'block-called'
         | 
| 210 246 | 
             
                    assert registry.preprocessors?
         | 
| 211 247 | 
             
                  ensure
         | 
| @@ -215,7 +251,7 @@ context 'Extensions' do | |
| 215 251 |  | 
| 216 252 | 
             
                test 'should create registry in Document if extensions are loaded' do
         | 
| 217 253 | 
             
                  begin
         | 
| 218 | 
            -
                     | 
| 254 | 
            +
                    SampleExtensionGroup.register
         | 
| 219 255 | 
             
                    doc = Asciidoctor::Document.new
         | 
| 220 256 | 
             
                    assert doc.extensions?
         | 
| 221 257 | 
             
                    assert doc.extensions.is_a? Asciidoctor::Extensions::Registry
         | 
| @@ -230,79 +266,102 @@ context 'Extensions' do | |
| 230 266 | 
             
                test 'should instantiate preprocessors' do
         | 
| 231 267 | 
             
                  registry = Asciidoctor::Extensions::Registry.new
         | 
| 232 268 | 
             
                  registry.preprocessor SamplePreprocessor
         | 
| 269 | 
            +
                  registry.activate Asciidoctor::Document.new
         | 
| 233 270 | 
             
                  assert registry.preprocessors?
         | 
| 234 | 
            -
                   | 
| 235 | 
            -
                  assert_equal 1,  | 
| 236 | 
            -
                  assert  | 
| 271 | 
            +
                  extensions = registry.preprocessors
         | 
| 272 | 
            +
                  assert_equal 1, extensions.size
         | 
| 273 | 
            +
                  assert extensions.first.is_a? Asciidoctor::Extensions::ProcessorExtension
         | 
| 274 | 
            +
                  assert extensions.first.instance.is_a? SamplePreprocessor
         | 
| 275 | 
            +
                  assert extensions.first.process_method.is_a? ::Method
         | 
| 237 276 | 
             
                end
         | 
| 238 277 |  | 
| 239 278 | 
             
                test 'should instantiate include processors' do
         | 
| 240 279 | 
             
                  registry = Asciidoctor::Extensions::Registry.new
         | 
| 241 280 | 
             
                  registry.include_processor SampleIncludeProcessor
         | 
| 281 | 
            +
                  registry.activate Asciidoctor::Document.new
         | 
| 242 282 | 
             
                  assert registry.include_processors?
         | 
| 243 | 
            -
                   | 
| 244 | 
            -
                  assert_equal 1,  | 
| 245 | 
            -
                  assert  | 
| 283 | 
            +
                  extensions = registry.include_processors
         | 
| 284 | 
            +
                  assert_equal 1, extensions.size
         | 
| 285 | 
            +
                  assert extensions.first.is_a? Asciidoctor::Extensions::ProcessorExtension
         | 
| 286 | 
            +
                  assert extensions.first.instance.is_a? SampleIncludeProcessor
         | 
| 287 | 
            +
                  assert extensions.first.process_method.is_a? ::Method
         | 
| 246 288 | 
             
                end
         | 
| 247 289 |  | 
| 248 290 | 
             
                test 'should instantiate treeprocessors' do
         | 
| 249 291 | 
             
                  registry = Asciidoctor::Extensions::Registry.new
         | 
| 250 292 | 
             
                  registry.treeprocessor SampleTreeprocessor
         | 
| 293 | 
            +
                  registry.activate Asciidoctor::Document.new
         | 
| 251 294 | 
             
                  assert registry.treeprocessors?
         | 
| 252 | 
            -
                   | 
| 253 | 
            -
                  assert_equal 1,  | 
| 254 | 
            -
                  assert  | 
| 295 | 
            +
                  extensions = registry.treeprocessors
         | 
| 296 | 
            +
                  assert_equal 1, extensions.size
         | 
| 297 | 
            +
                  assert extensions.first.is_a? Asciidoctor::Extensions::ProcessorExtension
         | 
| 298 | 
            +
                  assert extensions.first.instance.is_a? SampleTreeprocessor
         | 
| 299 | 
            +
                  assert extensions.first.process_method.is_a? ::Method
         | 
| 255 300 | 
             
                end
         | 
| 256 301 |  | 
| 257 302 | 
             
                test 'should instantiate postprocessors' do
         | 
| 258 303 | 
             
                  registry = Asciidoctor::Extensions::Registry.new
         | 
| 259 304 | 
             
                  registry.postprocessor SamplePostprocessor
         | 
| 305 | 
            +
                  registry.activate Asciidoctor::Document.new
         | 
| 260 306 | 
             
                  assert registry.postprocessors?
         | 
| 261 | 
            -
                   | 
| 262 | 
            -
                  assert_equal 1,  | 
| 263 | 
            -
                  assert  | 
| 307 | 
            +
                  extensions = registry.postprocessors
         | 
| 308 | 
            +
                  assert_equal 1, extensions.size
         | 
| 309 | 
            +
                  assert extensions.first.is_a? Asciidoctor::Extensions::ProcessorExtension
         | 
| 310 | 
            +
                  assert extensions.first.instance.is_a? SamplePostprocessor
         | 
| 311 | 
            +
                  assert extensions.first.process_method.is_a? ::Method
         | 
| 264 312 | 
             
                end
         | 
| 265 313 |  | 
| 266 314 | 
             
                test 'should instantiate block processor' do
         | 
| 267 315 | 
             
                  registry = Asciidoctor::Extensions::Registry.new
         | 
| 268 | 
            -
                  registry.block :sample | 
| 316 | 
            +
                  registry.block SampleBlock, :sample
         | 
| 317 | 
            +
                  registry.activate Asciidoctor::Document.new
         | 
| 269 318 | 
             
                  assert registry.blocks?
         | 
| 270 | 
            -
                  assert registry. | 
| 271 | 
            -
                   | 
| 272 | 
            -
                  assert  | 
| 319 | 
            +
                  assert registry.registered_for_block? :sample, :paragraph
         | 
| 320 | 
            +
                  extension = registry.find_block_extension :sample
         | 
| 321 | 
            +
                  assert extension.is_a? Asciidoctor::Extensions::ProcessorExtension
         | 
| 322 | 
            +
                  assert extension.instance.is_a? SampleBlock
         | 
| 323 | 
            +
                  assert extension.process_method.is_a? ::Method
         | 
| 273 324 | 
             
                end
         | 
| 274 325 |  | 
| 275 326 | 
             
                test 'should not match block processor for unsupported context' do
         | 
| 276 327 | 
             
                  registry = Asciidoctor::Extensions::Registry.new
         | 
| 277 | 
            -
                  registry.block :sample | 
| 278 | 
            -
                   | 
| 328 | 
            +
                  registry.block SampleBlock, :sample
         | 
| 329 | 
            +
                  registry.activate Asciidoctor::Document.new
         | 
| 330 | 
            +
                  assert !(registry.registered_for_block? :sample, :sidebar)
         | 
| 279 331 | 
             
                end
         | 
| 280 332 |  | 
| 281 333 | 
             
                test 'should instantiate block macro processor' do
         | 
| 282 334 | 
             
                  registry = Asciidoctor::Extensions::Registry.new
         | 
| 283 | 
            -
                  registry.block_macro 'sample' | 
| 335 | 
            +
                  registry.block_macro SampleBlockMacro, 'sample'
         | 
| 336 | 
            +
                  registry.activate Asciidoctor::Document.new
         | 
| 284 337 | 
             
                  assert registry.block_macros?
         | 
| 285 | 
            -
                  assert registry. | 
| 286 | 
            -
                   | 
| 287 | 
            -
                  assert  | 
| 338 | 
            +
                  assert registry.registered_for_block_macro? 'sample'
         | 
| 339 | 
            +
                  extension = registry.find_block_macro_extension 'sample'
         | 
| 340 | 
            +
                  assert extension.is_a? Asciidoctor::Extensions::ProcessorExtension
         | 
| 341 | 
            +
                  assert extension.instance.is_a? SampleBlockMacro
         | 
| 342 | 
            +
                  assert extension.process_method.is_a? ::Method
         | 
| 288 343 | 
             
                end
         | 
| 289 344 |  | 
| 290 345 | 
             
                test 'should instantiate inline macro processor' do
         | 
| 291 346 | 
             
                  registry = Asciidoctor::Extensions::Registry.new
         | 
| 292 | 
            -
                  registry.inline_macro 'sample' | 
| 347 | 
            +
                  registry.inline_macro SampleInlineMacro, 'sample'
         | 
| 348 | 
            +
                  registry.activate Asciidoctor::Document.new
         | 
| 293 349 | 
             
                  assert registry.inline_macros?
         | 
| 294 | 
            -
                  assert registry. | 
| 295 | 
            -
                   | 
| 296 | 
            -
                  assert  | 
| 350 | 
            +
                  assert registry.registered_for_inline_macro? 'sample'
         | 
| 351 | 
            +
                  extension = registry.find_inline_macro_extension 'sample'
         | 
| 352 | 
            +
                  assert extension.is_a? Asciidoctor::Extensions::ProcessorExtension
         | 
| 353 | 
            +
                  assert extension.instance.is_a? SampleInlineMacro
         | 
| 354 | 
            +
                  assert extension.process_method.is_a? ::Method
         | 
| 297 355 | 
             
                end
         | 
| 298 356 |  | 
| 299 357 | 
             
                test 'should allow processors to be registered by a string name' do
         | 
| 300 358 | 
             
                  registry = Asciidoctor::Extensions::Registry.new
         | 
| 301 359 | 
             
                  registry.preprocessor 'SamplePreprocessor'
         | 
| 360 | 
            +
                  registry.activate Asciidoctor::Document.new
         | 
| 302 361 | 
             
                  assert registry.preprocessors?
         | 
| 303 | 
            -
                   | 
| 304 | 
            -
                  assert_equal 1,  | 
| 305 | 
            -
                  assert  | 
| 362 | 
            +
                  extensions = registry.preprocessors
         | 
| 363 | 
            +
                  assert_equal 1, extensions.size
         | 
| 364 | 
            +
                  assert extensions.first.is_a? Asciidoctor::Extensions::ProcessorExtension
         | 
| 306 365 | 
             
                end
         | 
| 307 366 | 
             
              end
         | 
| 308 367 |  | 
| @@ -317,11 +376,13 @@ sample content | |
| 317 376 | 
             
                  EOS
         | 
| 318 377 |  | 
| 319 378 | 
             
                  begin
         | 
| 320 | 
            -
                    Asciidoctor::Extensions.register do | 
| 379 | 
            +
                    Asciidoctor::Extensions.register do
         | 
| 321 380 | 
             
                      preprocessor ScrubHeaderPreprocessor
         | 
| 322 381 | 
             
                    end
         | 
| 323 382 |  | 
| 324 383 | 
             
                    doc = document_from_string input
         | 
| 384 | 
            +
                    assert doc.attr? 'skipped'
         | 
| 385 | 
            +
                    assert_equal 'junk line', (doc.attr 'skipped').strip
         | 
| 325 386 | 
             
                    assert doc.has_header?
         | 
| 326 387 | 
             
                    assert_equal 'Document Title', doc.doctitle
         | 
| 327 388 | 
             
                  ensure
         | 
| @@ -339,7 +400,7 @@ after | |
| 339 400 | 
             
                  EOS
         | 
| 340 401 |  | 
| 341 402 | 
             
                  begin
         | 
| 342 | 
            -
                    Asciidoctor::Extensions.register do | 
| 403 | 
            +
                    Asciidoctor::Extensions.register do
         | 
| 343 404 | 
             
                      include_processor BoilerplateTextIncludeProcessor
         | 
| 344 405 | 
             
                    end
         | 
| 345 406 |  | 
| @@ -352,6 +413,39 @@ after | |
| 352 413 | 
             
                    Asciidoctor::Extensions.unregister_all
         | 
| 353 414 | 
             
                  end
         | 
| 354 415 | 
             
                end
         | 
| 416 | 
            +
              
         | 
| 417 | 
            +
                test 'should call include processor to process include directive' do
         | 
| 418 | 
            +
                  input = <<-EOS
         | 
| 419 | 
            +
            first line
         | 
| 420 | 
            +
             | 
| 421 | 
            +
            include::include-file.asciidoc[]
         | 
| 422 | 
            +
             | 
| 423 | 
            +
            last line
         | 
| 424 | 
            +
                  EOS
         | 
| 425 | 
            +
             | 
| 426 | 
            +
                  # Safe Mode is not required here
         | 
| 427 | 
            +
                  document = empty_document :base_dir => File.expand_path(File.dirname(__FILE__))
         | 
| 428 | 
            +
                  document.extensions.include_processor do
         | 
| 429 | 
            +
                    process do |doc, reader, target, attributes|
         | 
| 430 | 
            +
                      # demonstrate that push_include normalizes endlines
         | 
| 431 | 
            +
                      content = ["include target:: #{target}\n", "\n", "middle line\n"]
         | 
| 432 | 
            +
                      reader.push_include content, target, target, 1, attributes
         | 
| 433 | 
            +
                    end
         | 
| 434 | 
            +
                  end
         | 
| 435 | 
            +
                  reader = Asciidoctor::PreprocessorReader.new document, input
         | 
| 436 | 
            +
                  lines = []
         | 
| 437 | 
            +
                  lines << reader.read_line
         | 
| 438 | 
            +
                  lines << reader.read_line
         | 
| 439 | 
            +
                  lines << reader.read_line
         | 
| 440 | 
            +
                  assert_equal 'include target:: include-file.asciidoc', lines.last
         | 
| 441 | 
            +
                  assert_equal 'include-file.asciidoc: line 2', reader.line_info
         | 
| 442 | 
            +
                  while reader.has_more_lines?
         | 
| 443 | 
            +
                    lines << reader.read_line
         | 
| 444 | 
            +
                  end
         | 
| 445 | 
            +
                  source = lines * ::Asciidoctor::EOL
         | 
| 446 | 
            +
                  assert_match(/^include target:: include-file.asciidoc$/, source)
         | 
| 447 | 
            +
                  assert_match(/^middle line$/, source)
         | 
| 448 | 
            +
                end
         | 
| 355 449 |  | 
| 356 450 | 
             
                test 'should invoke treeprocessors after parsing document' do
         | 
| 357 451 | 
             
                  input = <<-EOS
         | 
| @@ -362,7 +456,7 @@ content | |
| 362 456 | 
             
                  EOS
         | 
| 363 457 |  | 
| 364 458 | 
             
                  begin
         | 
| 365 | 
            -
                    Asciidoctor::Extensions.register do | 
| 459 | 
            +
                    Asciidoctor::Extensions.register do
         | 
| 366 460 | 
             
                      treeprocessor ReplaceAuthorTreeprocessor
         | 
| 367 461 | 
             
                    end
         | 
| 368 462 |  | 
| @@ -373,6 +467,26 @@ content | |
| 373 467 | 
             
                  end
         | 
| 374 468 | 
             
                end
         | 
| 375 469 |  | 
| 470 | 
            +
                test 'should allow treeprocessor to replace tree' do
         | 
| 471 | 
            +
                  input = <<-EOS
         | 
| 472 | 
            +
            = Original Document
         | 
| 473 | 
            +
            Doc Writer
         | 
| 474 | 
            +
             | 
| 475 | 
            +
            content
         | 
| 476 | 
            +
                  EOS
         | 
| 477 | 
            +
             | 
| 478 | 
            +
                  begin
         | 
| 479 | 
            +
                    Asciidoctor::Extensions.register do
         | 
| 480 | 
            +
                      treeprocessor ReplaceTreeTreeprocessor
         | 
| 481 | 
            +
                    end
         | 
| 482 | 
            +
             | 
| 483 | 
            +
                    doc = document_from_string input
         | 
| 484 | 
            +
                    assert_equal 'Replacement Document', doc.doctitle
         | 
| 485 | 
            +
                  ensure
         | 
| 486 | 
            +
                    Asciidoctor::Extensions.unregister_all
         | 
| 487 | 
            +
                  end
         | 
| 488 | 
            +
                end
         | 
| 489 | 
            +
             | 
| 376 490 | 
             
                test 'should invoke postprocessors after rendering document' do
         | 
| 377 491 | 
             
                  input = <<-EOS
         | 
| 378 492 | 
             
            * one
         | 
| @@ -381,12 +495,12 @@ content | |
| 381 495 | 
             
                  EOS
         | 
| 382 496 |  | 
| 383 497 | 
             
                  begin
         | 
| 384 | 
            -
                    Asciidoctor::Extensions.register do | 
| 498 | 
            +
                    Asciidoctor::Extensions.register do
         | 
| 385 499 | 
             
                      postprocessor StripAttributesPostprocessor
         | 
| 386 500 | 
             
                    end
         | 
| 387 501 |  | 
| 388 502 | 
             
                    output = render_string input
         | 
| 389 | 
            -
                     | 
| 503 | 
            +
                    refute_match(/<div class="ulist">/, output)
         | 
| 390 504 | 
             
                  ensure
         | 
| 391 505 | 
             
                    Asciidoctor::Extensions.unregister_all
         | 
| 392 506 | 
             
                  end
         | 
| @@ -399,8 +513,8 @@ Hi there! | |
| 399 513 | 
             
                  EOS
         | 
| 400 514 |  | 
| 401 515 | 
             
                  begin
         | 
| 402 | 
            -
                    Asciidoctor::Extensions.register do | 
| 403 | 
            -
                      block  | 
| 516 | 
            +
                    Asciidoctor::Extensions.register do
         | 
| 517 | 
            +
                      block UppercaseBlock
         | 
| 404 518 | 
             
                    end
         | 
| 405 519 |  | 
| 406 520 | 
             
                    output = render_embedded_string input
         | 
| @@ -417,8 +531,8 @@ snippet::12345[] | |
| 417 531 | 
             
                  EOS
         | 
| 418 532 |  | 
| 419 533 | 
             
                  begin
         | 
| 420 | 
            -
                    Asciidoctor::Extensions.register do | 
| 421 | 
            -
                      block_macro :snippet | 
| 534 | 
            +
                    Asciidoctor::Extensions.register do
         | 
| 535 | 
            +
                      block_macro SnippetMacro, :snippet
         | 
| 422 536 | 
             
                    end
         | 
| 423 537 |  | 
| 424 538 | 
             
                    output = render_embedded_string input
         | 
| @@ -429,20 +543,76 @@ snippet::12345[] | |
| 429 543 | 
             
                end
         | 
| 430 544 |  | 
| 431 545 | 
             
                test 'should invoke processor for custom inline macro' do
         | 
| 432 | 
            -
                  input = <<-EOS
         | 
| 433 | 
            -
            Room temperature is degrees:25[].
         | 
| 434 | 
            -
                  EOS
         | 
| 435 | 
            -
             | 
| 436 546 | 
             
                  begin
         | 
| 437 | 
            -
                    Asciidoctor::Extensions.register do | 
| 438 | 
            -
                      inline_macro :degrees | 
| 547 | 
            +
                    Asciidoctor::Extensions.register do
         | 
| 548 | 
            +
                      inline_macro TemperatureMacro, :degrees
         | 
| 439 549 | 
             
                    end
         | 
| 440 550 |  | 
| 441 | 
            -
                    output = render_embedded_string  | 
| 551 | 
            +
                    output = render_embedded_string 'Room temperature is degrees:25[C].', :attributes => {'temperature-unit' => 'F'}
         | 
| 552 | 
            +
                    assert output.include?('Room temperature is 25.0 °C.')
         | 
| 553 | 
            +
             | 
| 554 | 
            +
                    output = render_embedded_string 'Room temperature is degrees:25[].', :attributes => {'temperature-unit' => 'F'}
         | 
| 442 555 | 
             
                    assert output.include?('Room temperature is 77.0 °F.')
         | 
| 443 556 | 
             
                  ensure
         | 
| 444 557 | 
             
                    Asciidoctor::Extensions.unregister_all
         | 
| 445 558 | 
             
                  end
         | 
| 446 559 | 
             
                end
         | 
| 560 | 
            +
             | 
| 561 | 
            +
                test 'should not carry over attributes if block processor returns nil' do
         | 
| 562 | 
            +
                  begin
         | 
| 563 | 
            +
                    Asciidoctor::Extensions.register do
         | 
| 564 | 
            +
                      block do
         | 
| 565 | 
            +
                        named :skip
         | 
| 566 | 
            +
                        on_context :paragraph
         | 
| 567 | 
            +
                        parse_content_as :raw
         | 
| 568 | 
            +
                        process do |parent, reader, attrs|
         | 
| 569 | 
            +
                          nil
         | 
| 570 | 
            +
                        end
         | 
| 571 | 
            +
                      end
         | 
| 572 | 
            +
                    end
         | 
| 573 | 
            +
                    input = <<-EOS
         | 
| 574 | 
            +
            .unused title
         | 
| 575 | 
            +
            [skip]
         | 
| 576 | 
            +
            not rendered
         | 
| 577 | 
            +
             | 
| 578 | 
            +
            --
         | 
| 579 | 
            +
            rendered
         | 
| 580 | 
            +
            --
         | 
| 581 | 
            +
                    EOS
         | 
| 582 | 
            +
                    doc = document_from_string input
         | 
| 583 | 
            +
                    assert_equal 1, doc.blocks.size
         | 
| 584 | 
            +
                    assert_nil doc.blocks[0].attributes['title']
         | 
| 585 | 
            +
                  ensure
         | 
| 586 | 
            +
                    Asciidoctor::Extensions.unregister_all
         | 
| 587 | 
            +
                  end
         | 
| 588 | 
            +
                end
         | 
| 589 | 
            +
             | 
| 590 | 
            +
                test 'should pass attributes by value to block processor' do
         | 
| 591 | 
            +
                  begin
         | 
| 592 | 
            +
                    Asciidoctor::Extensions.register do
         | 
| 593 | 
            +
                      block do
         | 
| 594 | 
            +
                        named :foo
         | 
| 595 | 
            +
                        on_context :paragraph
         | 
| 596 | 
            +
                        parse_content_as :raw
         | 
| 597 | 
            +
                        process do |parent, reader, attrs|
         | 
| 598 | 
            +
                          original_attrs = attrs.dup
         | 
| 599 | 
            +
                          attrs.delete('title')
         | 
| 600 | 
            +
                          create_paragraph parent, reader.read_lines, original_attrs.merge('id' => 'value')
         | 
| 601 | 
            +
                        end
         | 
| 602 | 
            +
                      end
         | 
| 603 | 
            +
                    end
         | 
| 604 | 
            +
                    input = <<-EOS
         | 
| 605 | 
            +
            .title
         | 
| 606 | 
            +
            [foo]
         | 
| 607 | 
            +
            content
         | 
| 608 | 
            +
                    EOS
         | 
| 609 | 
            +
                    doc = document_from_string input
         | 
| 610 | 
            +
                    assert_equal 1, doc.blocks.size
         | 
| 611 | 
            +
                    assert_equal 'title', doc.blocks[0].attributes['title']
         | 
| 612 | 
            +
                    assert_equal 'value', doc.blocks[0].id
         | 
| 613 | 
            +
                  ensure
         | 
| 614 | 
            +
                    Asciidoctor::Extensions.unregister_all
         | 
| 615 | 
            +
                  end
         | 
| 616 | 
            +
                end
         | 
| 447 617 | 
             
              end
         | 
| 448 618 | 
             
            end
         |