Skip to content

Commit c2fb809

Browse files
authored
Asciidoctor: Handle snippets in definition lists (#680)
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: asciidoctor/asciidoctor#3133 That method had behavior that is a little too broad anyway so we implement what we need directly.
1 parent 1ef12cb commit c2fb809

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

resources/asciidoctor/lib/elastic_compat_tree_processor/extension.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ def process_subs(block)
6767
}.freeze
6868

6969
def process_lang_override(block)
70-
next_block = block.next_adjacent_block
70+
# Check if the next block is a marker for the language
71+
# We don't want block.next_adjacent_block because that'll go "too far"
72+
# and it has trouble with definition lists.
73+
my_index = block.parent.blocks.find_index block
74+
return unless my_index
75+
76+
next_block = block.parent.blocks[my_index + 1]
7177
return unless next_block && next_block.context == :paragraph
7278
return unless next_block.source =~ %r{pass:\[//\s*([^:\]]+)(?::\s*([^\]]+))?\]}
7379

resources/asciidoctor/spec/elastic_compat_tree_processor_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,27 @@
9696
expect(actual).to eq(expected.strip)
9797
end
9898
end
99+
100+
context 'a snippet is inside of a definition list' do
101+
let(:converted) do
102+
convert <<~ASCIIDOC
103+
== Example
104+
Term::
105+
Definition
106+
+
107+
--
108+
[source,js]
109+
----
110+
GET /
111+
----
112+
--
113+
ASCIIDOC
114+
end
115+
let(:has_original_language) do
116+
%r{<programlisting language="js" linenumbering="unnumbered">GET /</programlisting>}
117+
end
118+
it "doesn't break" do
119+
expect(converted).to match(has_original_language)
120+
end
121+
end
99122
end

0 commit comments

Comments
 (0)