From bd32de2430afbe977db75a34e6ec2ce1093ca10a Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 7 Mar 2019 14:30:43 -0500 Subject: [PATCH 1/5] Asciidoctor: Handle snippets in definition lists Our lang override processor had trouble with snippets inside of definition lists because a method provided by Asciidoctor doesn't quite behave well inside definition lists: https://github.com/asciidoctor/asciidoctor/issues/3133 That method had behavior that is a little too broad anyway so we implement what we need directly. --- .../elastic_compat_tree_processor/extension.rb | 8 +++++++- .../spec/elastic_compat_tree_processor_spec.rb | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/resources/asciidoctor/lib/elastic_compat_tree_processor/extension.rb b/resources/asciidoctor/lib/elastic_compat_tree_processor/extension.rb index 70c3017b53880..68825dcffd13d 100644 --- a/resources/asciidoctor/lib/elastic_compat_tree_processor/extension.rb +++ b/resources/asciidoctor/lib/elastic_compat_tree_processor/extension.rb @@ -67,7 +67,13 @@ def process_subs(block) }.freeze def process_lang_override(block) - next_block = block.next_adjacent_block + # Check if the next block is a marker for the language + # We don't want block.next_adjacent_block because that'll go "too far" + # and it has trouble with definition lists. + next_block_index = block.parent.blocks.find_index block + return if next_block_index.nil? + + next_block = block.parent.blocks[next_block_index + 1] return unless next_block && next_block.context == :paragraph return unless next_block.source =~ %r{pass:\[//\s*([^:\]]+)(?::\s*([^\]]+))?\]} diff --git a/resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb b/resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb index 04ba3a3d23b6c..7497a583ca398 100644 --- a/resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb +++ b/resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb @@ -96,4 +96,20 @@ expect(actual).to eq(expected.strip) end end + + it "doesn't mind when the snippet inside a definition list" do + actual = convert <<~ASCIIDOC + == Example + Term:: + Definition + + + -- + [source,js] + ---- + GET / + ---- + -- + ASCIIDOC + expect(actual).to match(%r{GET /}) + end end From 6ff1d7de9f5ae9a044d3078f1b47ababae8fa6d7 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 12 Mar 2019 14:30:33 -0400 Subject: [PATCH 2/5] Style --- .../lib/elastic_compat_tree_processor/extension.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/asciidoctor/lib/elastic_compat_tree_processor/extension.rb b/resources/asciidoctor/lib/elastic_compat_tree_processor/extension.rb index 68825dcffd13d..4f5848c681455 100644 --- a/resources/asciidoctor/lib/elastic_compat_tree_processor/extension.rb +++ b/resources/asciidoctor/lib/elastic_compat_tree_processor/extension.rb @@ -70,10 +70,10 @@ def process_lang_override(block) # Check if the next block is a marker for the language # We don't want block.next_adjacent_block because that'll go "too far" # and it has trouble with definition lists. - next_block_index = block.parent.blocks.find_index block - return if next_block_index.nil? + my_index = block.parent.blocks.find_index block + return unless my_index - next_block = block.parent.blocks[next_block_index + 1] + next_block = block.parent.blocks[my_index + 1] return unless next_block && next_block.context == :paragraph return unless next_block.source =~ %r{pass:\[//\s*([^:\]]+)(?::\s*([^\]]+))?\]} From d410a5cfd78dc2d1a40c2dbe1a0b1766c1f65876 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 12 Mar 2019 14:44:47 -0400 Subject: [PATCH 3/5] Context --- .../elastic_compat_tree_processor_spec.rb | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb b/resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb index 7497a583ca398..622cfacbb3ea7 100644 --- a/resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb +++ b/resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb @@ -97,19 +97,26 @@ end end - it "doesn't mind when the snippet inside a definition list" do - actual = convert <<~ASCIIDOC - == Example - Term:: - Definition - + - -- - [source,js] - ---- - GET / - ---- - -- - ASCIIDOC - expect(actual).to match(%r{GET /}) + context 'a snippet is inside of a definition list' do + let(:result) do + convert <<~ASCIIDOC + == Example + Term:: + Definition + + + -- + [source,js] + ---- + GET / + ---- + -- + ASCIIDOC + end + let(:has_original_language) do + match %r{GET /} + end + it "doesn't break" do + expect(result).to has_original_language + end end end From 40ed7565a8a9d1ebd9e57ed6b609a9f84bb265a3 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Tue, 12 Mar 2019 14:47:52 -0400 Subject: [PATCH 4/5] Subject --- .../asciidoctor/spec/elastic_compat_tree_processor_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb b/resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb index 622cfacbb3ea7..9fd0fa4c9b83f 100644 --- a/resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb +++ b/resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb @@ -98,7 +98,7 @@ end context 'a snippet is inside of a definition list' do - let(:result) do + subject do convert <<~ASCIIDOC == Example Term:: @@ -116,7 +116,7 @@ match %r{GET /} end it "doesn't break" do - expect(result).to has_original_language + is_expected.to has_original_language end end end From 0ed1da8df13a8c9541bd4efddde8079e60bd3465 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 13 Mar 2019 13:25:54 -0400 Subject: [PATCH 5/5] Different rspec --- .../asciidoctor/spec/elastic_compat_tree_processor_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb b/resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb index 9fd0fa4c9b83f..98efeb0a9c5fc 100644 --- a/resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb +++ b/resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb @@ -98,7 +98,7 @@ end context 'a snippet is inside of a definition list' do - subject do + let(:converted) do convert <<~ASCIIDOC == Example Term:: @@ -113,10 +113,10 @@ ASCIIDOC end let(:has_original_language) do - match %r{GET /} + %r{GET /} end it "doesn't break" do - is_expected.to has_original_language + expect(converted).to match(has_original_language) end end end