Skip to content

Commit

Permalink
repurpose example block as open block if filetype is not html
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Jul 26, 2023
1 parent a14db3d commit 6e7b649
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
This document provides a curated view of the changes to Asciidoctor Tabs per release.
For a detailed view of what has changed, refer to the {url-repo}/commits/main[commit history] on GitHub.

== Unreleased

=== Changed

* Repurpose example block as open block if filetype is not html

== 1.0.0-beta.5 (2023-05-28) - @mojavelinux

=== Changed
Expand Down
10 changes: 3 additions & 7 deletions lib/asciidoctor/tabs/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@ class Block < ::Asciidoctor::Extensions::BlockProcessor
on_context :example

def process parent, reader, attrs
tabs_number = (doc = parent.document).counter 'tabs-number'
doc = parent.document
return create_open_block parent, nil, attrs unless doc.attr? 'filetype', 'html'
tabs_number = doc.counter 'tabs-number'
block = create_block parent, attrs['cloaked-context'], nil, attrs, content_model: :compound
children = (parse_content block, reader).blocks
unless children.size == 1 && (seed_tabs = children[0]).context == :dlist && seed_tabs.items?
return (reset_counter doc, 'tabs-number', (tabs_number - 1)) || block
end
unless doc.attr? 'filetype', 'html'
(id = attrs['id']) && (doc.register :refs, [(seed_tabs.id = id), seed_tabs]) unless seed_tabs.id
(reftext = attrs['reftext']) && (seed_tabs.set_attr 'reftext', reftext) unless seed_tabs.reftext?
parent << seed_tabs
return reset_counter doc, 'tabs-number', (tabs_number - 1)
end
tabs_id = attrs['id'] || (generate_id %(tabs #{tabs_number}), doc)
tabs_role = 'tabs' + (!(block.option? 'nosync') && ((block.option? 'sync') || (doc.option? 'tabs-sync')) ?
((gid = attrs['sync-group-id']) ? %( is-sync data-sync-group-id=#{gid.gsub ' ', ?\u00a0}) : ' is-sync') : '')
Expand Down
10 changes: 7 additions & 3 deletions spec/tabs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -857,27 +857,29 @@ def convert_ulist node
(expect actual).to eql expected
end

it 'should output original dlist if filetype is not html' do
it 'should output original dlist in open block if filetype is not html' do
input = <<~END
[#not-tabs,reftext=Not Tabs]
#{single_tab}
END
expected = <<~'END'.chomp
<variablelist xml:id="not-tabs" xreflabel="Not Tabs">
<para xml:id="not-tabs" xreflabel="Not Tabs">
<variablelist>
<varlistentry>
<term>Tab A</term>
<listitem>
<simpara>Contents of tab A.</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
END

actual = Asciidoctor.convert input, backend: 'docbook'
(expect actual).to eql expected
end

it 'should prefer ID and reftext on dlist when filetype is not html' do
it 'should preserve ID and reftext on dlist when filetype is not html' do
input = <<~'END'
[tabs#not-tabs,reftext=Not Tabs]
====
Expand All @@ -886,6 +888,7 @@ def convert_ulist node
====
END
expected = <<~'END'.chomp
<para xml:id="not-tabs" xreflabel="Not Tabs">
<variablelist xml:id="varlist-1" xreflabel="A Variable List">
<varlistentry>
<term>Tab A</term>
Expand All @@ -894,6 +897,7 @@ def convert_ulist node
</listitem>
</varlistentry>
</variablelist>
</para>
END

actual = Asciidoctor.convert input, backend: 'docbook'
Expand Down

0 comments on commit 6e7b649

Please sign in to comment.