diff --git a/resources/asciidoctor/lib/elastic_compat_preprocessor/extension.rb b/resources/asciidoctor/lib/elastic_compat_preprocessor/extension.rb
index 779b3dc489ae..9311c5ad96e3 100644
--- a/resources/asciidoctor/lib/elastic_compat_preprocessor/extension.rb
+++ b/resources/asciidoctor/lib/elastic_compat_preprocessor/extension.rb
@@ -115,8 +115,8 @@ class ElasticCompatPreprocessor < Asciidoctor::Extensions::Preprocessor
CODE_BLOCK_RX = /^-----*$/
SNIPPET_RX = %r{^//\s*(AUTOSENSE|KIBANA|CONSOLE|SENSE:[^\n<]+)$}
LEGACY_MACROS = 'added|beta|coming|deprecated|experimental'
- LEGACY_BLOCK_MACRO_RX = /^(#{LEGACY_MACROS})\[([^\]]*)\]/
- LEGACY_INLINE_MACRO_RX = /(#{LEGACY_MACROS})\[([^\]]*)\]/
+ LEGACY_BLOCK_MACRO_RX = /^\s*(#{LEGACY_MACROS})\[(.*)\]\s*$/
+ LEGACY_INLINE_MACRO_RX = /(#{LEGACY_MACROS})\[(.*)\]/
def process(_document, reader)
reader.instance_variable_set :@in_attribute_only_block, false
@@ -175,7 +175,7 @@ def reader.process_line(line)
end
# First convert the "block" version of these macros. We convert them
- # to block macros because they are at the start of the line....
+ # to block macros because they are alone on a line
line&.gsub!(LEGACY_BLOCK_MACRO_RX, '\1::[\2]')
# Then convert the "inline" version of these macros. We convert them
# to inline macros because they are *not* at the start of the line....
diff --git a/resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb b/resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb
index 0558315a094d..2755f8df0a16 100644
--- a/resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb
+++ b/resources/asciidoctor/spec/elastic_compat_preprocessor_spec.rb
@@ -30,57 +30,102 @@
include_examples "doesn't break line numbers"
- [
- %w[added added note],
- %w[coming changed note],
- %w[deprecated deleted warning],
- ].each do |(name, revisionflag, tag)|
- it "invokes the #{name} block macro when #{name}[version] starts a line" do
- actual = convert <<~ASCIIDOC
- == Example
- #{name}[some_version]
- ASCIIDOC
- expected = <<~DOCBOOK
-
- Example
- <#{tag} revisionflag="#{revisionflag}" revision="some_version">
-
- #{tag}>
-
- DOCBOOK
- expect(actual).to eq(expected.strip)
- end
-
- it "invokes the #{name} inline macro when #{name}[version] is otherwise on the line" do
- actual = convert <<~ASCIIDOC
- == Example
- words #{name}[some_version]
- ASCIIDOC
- expected = <<~DOCBOOK
-
- Example
- words
-
-
- DOCBOOK
- expect(actual).to eq(expected.strip)
- end
-
- it "doesn't mind skipped #{name} block macros" do
- actual = convert <<~ASCIIDOC
- == Example
+ context 'change admonitions' do
+ shared_examples 'change admonition' do
+ include_context 'convert without logs'
+
+ shared_examples 'invokes the block macro' do
+ let(:expected) do
+ <<~DOCBOOK
+ <#{tag} revisionflag="#{revisionflag}" revision="some_version">
+
+ #{tag}>
+ DOCBOOK
+ end
+ it 'invokes the block macro' do
+ expect(converted).to include(expected)
+ end
+ end
+ context 'when the admonition is alone on a line' do
+ let(:input) { "#{name}[some_version]" }
+ include_examples 'invokes the block macro'
+ end
+ context 'when the admonition has spaces before it' do
+ let(:input) { " #{name}[some_version]" }
+ include_examples 'invokes the block macro'
+ end
+ context 'when the admonition has spaces after it' do
+ let(:input) { "#{name}[some_version] " }
+ include_examples 'invokes the block macro'
+ end
+ context 'when the admonition has a `]` in it' do
+ let(:input) { "#{name}[some_version, link:link.html[Title]]" }
+ include_examples 'invokes the block macro'
+ let(:expected) do
+ <<~DOCBOOK
+ <#{tag} revisionflag="#{revisionflag}" revision="some_version">
+ Title
+ #{tag}>
+ DOCBOOK
+ end
+ end
- ifeval::["true" == "false"]
- #{name}[some_version]
- #endif::[]
- ASCIIDOC
- expected = <<~DOCBOOK
-
- Example
+ shared_examples 'invokes the inline macro' do
+ it 'invokes the inline macro' do
+ expect(converted).to include(
+ %()
+ )
+ end
+ end
+ context "when the admonition is surrounded by other text" do
+ let(:input) { "words #{name}[some_version] words" }
+ include_examples 'invokes the inline macro'
+ end
+ context "when the admonition has text before it" do
+ let(:input) { "words #{name}[some_version]" }
+ include_examples 'invokes the inline macro'
+ end
+ context "when the admonition has text after it" do
+ let(:input) { "#{name}[some_version] words" }
+ include_examples 'invokes the inline macro'
+ end
-
- DOCBOOK
- expect(actual).to eq(expected.strip)
+ context 'when the admonition is skipped' do
+ let(:input) do
+ <<~ASCIIDOC
+ words before skip
+ ifeval::["true" == "false"]
+ #{name}[some_version]
+ endif::[]
+ words after skip
+ ASCIIDOC
+ end
+ it 'skips the admonition' do
+ expect(converted).not_to include('revisionflag')
+ end
+ it 'properly converts the rest of the text' do
+ expect(converted).to include('words before skip')
+ expect(converted).to include('words after skip')
+ end
+ end
+ end
+ context 'for added' do
+ include_context 'change admonition'
+ let(:name) { 'added' }
+ let(:revisionflag) { 'added' }
+ let(:tag) { 'note' }
+ end
+ context 'for coming' do
+ include_context 'change admonition'
+ let(:name) { 'coming' }
+ let(:revisionflag) { 'changed' }
+ let(:tag) { 'note' }
+ end
+ context 'for added' do
+ include_context 'change admonition'
+ let(:name) { 'deprecated' }
+ let(:revisionflag) { 'deleted' }
+ let(:tag) { 'warning' }
end
end