diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2017-04-27 23:50:02 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2017-04-28 00:34:12 -0600 |
| commit | 8389ffad07df9b0151839f97a6033564b5dc7dfc (patch) | |
| tree | 6acf2a301330686b92afbcec2bd4b956fb688944 | |
| parent | 9405dad013762bd404ed46b94cd3d8585ee5aa38 (diff) | |
allow normalize option to be set on PreprocessorReader; change default to false
| -rw-r--r-- | lib/asciidoctor/document.rb | 6 | ||||
| -rw-r--r-- | lib/asciidoctor/reader.rb | 4 | ||||
| -rw-r--r-- | lib/asciidoctor/table.rb | 2 | ||||
| -rw-r--r-- | test/extensions_test.rb | 2 | ||||
| -rw-r--r-- | test/reader_test.rb | 20 | ||||
| -rw-r--r-- | test/text_test.rb | 4 |
6 files changed, 20 insertions, 18 deletions
diff --git a/lib/asciidoctor/document.rb b/lib/asciidoctor/document.rb index 72785c79..7732e882 100644 --- a/lib/asciidoctor/document.rb +++ b/lib/asciidoctor/document.rb @@ -442,7 +442,7 @@ class Document < AbstractBlock @extensions = ext_registry.activate self end - @reader = PreprocessorReader.new self, data, Reader::Cursor.new(attrs['docfile'], @base_dir) + @reader = PreprocessorReader.new self, data, (Reader::Cursor.new attrs['docfile'], @base_dir), :normalize => true end end @@ -463,7 +463,9 @@ class Document < AbstractBlock else doc = self # create reader if data is provided (used when data is not known at the time the Document object is created) - @reader = PreprocessorReader.new doc, data, Reader::Cursor.new(@attributes['docfile'], @base_dir) if data + if data + @reader = PreprocessorReader.new doc, data, (Reader::Cursor.new @attributes['docfile'], @base_dir), :normalize => true + end if (exts = @parent_document ? nil : @extensions) && exts.preprocessors? exts.preprocessors.each do |ext| diff --git a/lib/asciidoctor/reader.rb b/lib/asciidoctor/reader.rb index c5dfbc61..03ad0e69 100644 --- a/lib/asciidoctor/reader.rb +++ b/lib/asciidoctor/reader.rb @@ -568,9 +568,9 @@ class PreprocessorReader < Reader attr_reader :includes # Public: Initialize the PreprocessorReader object - def initialize document, data = nil, cursor = nil + def initialize document, data = nil, cursor = nil, opts = {} @document = document - super data, cursor, :normalize => true + super data, cursor, opts include_depth_default = document.attributes.fetch('max-include-depth', 64).to_i include_depth_default = 0 if include_depth_default < 0 # track both absolute depth for comparing to size of include stack and relative depth for reporting diff --git a/lib/asciidoctor/table.rb b/lib/asciidoctor/table.rb index 5e1087bd..0414fee0 100644 --- a/lib/asciidoctor/table.rb +++ b/lib/asciidoctor/table.rb @@ -267,7 +267,7 @@ class Table::Cell < AbstractNode inner_document_lines = cell_text.split EOL, -1 unless inner_document_lines.empty? || !inner_document_lines[0].include?('::') unprocessed_lines = inner_document_lines[0] - processed_lines = PreprocessorReader.new(@document, unprocessed_lines).readlines + processed_lines = (PreprocessorReader.new @document, unprocessed_lines).readlines if processed_lines != unprocessed_lines inner_document_lines.shift inner_document_lines.unshift(*processed_lines) diff --git a/test/extensions_test.rb b/test/extensions_test.rb index 595ac761..dbb4a270 100644 --- a/test/extensions_test.rb +++ b/test/extensions_test.rb @@ -531,7 +531,7 @@ last line reader.push_include content, target, target, 1, attributes end end - reader = Asciidoctor::PreprocessorReader.new document, input + reader = Asciidoctor::PreprocessorReader.new document, input, nil, :normalize => true lines = [] lines << reader.read_line lines << reader.read_line diff --git a/test/reader_test.rb b/test/reader_test.rb index e1bd190d..a92293ba 100644 --- a/test/reader_test.rb +++ b/test/reader_test.rb @@ -557,7 +557,7 @@ include::fixtures/parent-include.adoc[] grandchild_include_docfile = File.join fixtures_dir, 'grandchild-include.adoc' doc = empty_safe_document :base_dir => DIRNAME - reader = Asciidoctor::PreprocessorReader.new doc, input, pseudo_docfile + reader = Asciidoctor::PreprocessorReader.new doc, input, pseudo_docfile, :normalize => true assert_equal pseudo_docfile, reader.file assert_equal DIRNAME, reader.dir @@ -840,7 +840,7 @@ include::fixtures/include-file.asciidoc[] } document = empty_safe_document :base_dir => DIRNAME - reader = Asciidoctor::PreprocessorReader.new document, input + reader = Asciidoctor::PreprocessorReader.new document, input, nil, :normalize => true reader.instance_variable_set '@include_processors', [include_processor.new(document)] lines = reader.read_lines source = lines * ::Asciidoctor::EOL @@ -889,7 +889,7 @@ include::{foodir}/include-file.asciidoc[] EOS doc = empty_safe_document :base_dir => DIRNAME - reader = Asciidoctor::PreprocessorReader.new doc, input + reader = Asciidoctor::PreprocessorReader.new doc, input, nil, :normalize => true assert_equal 'Unresolved directive in <stdin> - include::{foodir}/include-file.asciidoc[]', reader.read_line end @@ -899,7 +899,7 @@ include::{foodir}/include-file.asciidoc[] EOS doc = empty_safe_document :base_dir => DIRNAME, :attributes => {'attribute-missing' => 'drop'} - reader = Asciidoctor::PreprocessorReader.new doc, input + reader = Asciidoctor::PreprocessorReader.new doc, input, nil, :normalize => true assert_nil reader.read_line end @@ -910,7 +910,7 @@ yo EOS doc = empty_safe_document :base_dir => DIRNAME, :attributes => {'attribute-missing' => 'drop'} - reader = Asciidoctor::PreprocessorReader.new doc, input + reader = Asciidoctor::PreprocessorReader.new doc, input, nil, :normalize => true assert_equal 'yo', reader.read_line end @@ -920,7 +920,7 @@ yo \\escape preserved here EOS doc = empty_safe_document :base_dir => DIRNAME - reader = Asciidoctor::PreprocessorReader.new doc, input + reader = Asciidoctor::PreprocessorReader.new doc, input, nil, :normalize => true # we should be able to peek it multiple times and still have the backslash preserved # this is the test for @unescape_next_line assert_equal 'include::fixtures/include-file.asciidoc[]', reader.peek_line @@ -968,7 +968,7 @@ include::fixtures/parent-include.adoc[depth=1] pseudo_docfile = File.join DIRNAME, 'include-master.adoc' doc = empty_safe_document :base_dir => DIRNAME - reader = Asciidoctor::PreprocessorReader.new doc, input, Asciidoctor::Reader::Cursor.new(pseudo_docfile) + reader = Asciidoctor::PreprocessorReader.new doc, input, Asciidoctor::Reader::Cursor.new(pseudo_docfile), :normalize => true lines = reader.readlines assert lines.include?('include::child-include.adoc[]') @@ -982,7 +982,7 @@ include::fixtures/parent-include-restricted.adoc[depth=3] pseudo_docfile = File.join DIRNAME, 'include-master.adoc' doc = empty_safe_document :base_dir => DIRNAME - reader = Asciidoctor::PreprocessorReader.new doc, input, Asciidoctor::Reader::Cursor.new(pseudo_docfile) + reader = Asciidoctor::PreprocessorReader.new doc, input, Asciidoctor::Reader::Cursor.new(pseudo_docfile), :normalize => true lines = reader.readlines assert lines.include?('first line of child') @@ -997,7 +997,7 @@ include::fixtures/no-such-file.adoc[] EOS doc = empty_safe_document :base_dir => DIRNAME - reader = Asciidoctor::PreprocessorReader.new doc, lines + reader = Asciidoctor::PreprocessorReader.new doc, lines, nil, :normalize => true reader.read_line result = reader.read_lines_until(:terminator => '////', :skip_processing => true) assert_equal lines.map {|l| l.chomp}[1..1], result @@ -1011,7 +1011,7 @@ include::fixtures/no-such-file.adoc[] EOS doc = empty_safe_document :base_dir => DIRNAME - reader = Asciidoctor::PreprocessorReader.new doc, lines + reader = Asciidoctor::PreprocessorReader.new doc, lines, nil, :normalize => true result = reader.skip_comment_lines assert_equal lines.map {|l| l.chomp}, result end diff --git a/test/text_test.rb b/test/text_test.rb index faf7d857..bdf151db 100644 --- a/test/text_test.rb +++ b/test/text_test.rb @@ -35,7 +35,7 @@ context "Text" do input << "[verse]\n" input.concat(File.readlines(sample_doc_path(:encoding))) doc = empty_document - reader = Asciidoctor::PreprocessorReader.new doc, input + reader = Asciidoctor::PreprocessorReader.new doc, input, nil, :normalize => true block = Asciidoctor::Parser.next_block(reader, doc) assert_xpath '//pre', block.render.gsub(/^\s*\n/, ''), 1 end @@ -45,7 +45,7 @@ context "Text" do include::fixtures/encoding.asciidoc[tags=romé] EOS doc = empty_safe_document :base_dir => File.expand_path(File.dirname(__FILE__)) - reader = Asciidoctor::PreprocessorReader.new doc, input + reader = Asciidoctor::PreprocessorReader.new doc, input, nil, :normalize => true block = Asciidoctor::Parser.next_block(reader, doc) output = block.render assert_css '.paragraph', output, 1 |
