From 6e7b649552bf72163de384dc69c468d7c84bf6c2 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Tue, 25 Jul 2023 23:56:31 -0600 Subject: [PATCH] repurpose example block as open block if filetype is not html --- CHANGELOG.adoc | 6 ++++++ lib/asciidoctor/tabs/block.rb | 10 +++------- spec/tabs_spec.rb | 10 +++++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 2fab824..9ae4be5 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -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 diff --git a/lib/asciidoctor/tabs/block.rb b/lib/asciidoctor/tabs/block.rb index 312a314..54044c3 100644 --- a/lib/asciidoctor/tabs/block.rb +++ b/lib/asciidoctor/tabs/block.rb @@ -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') : '') diff --git a/spec/tabs_spec.rb b/spec/tabs_spec.rb index a568bf6..3a1dd6f 100644 --- a/spec/tabs_spec.rb +++ b/spec/tabs_spec.rb @@ -857,13 +857,14 @@ 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 - + + Tab A @@ -871,13 +872,14 @@ def convert_ulist node + 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] ==== @@ -886,6 +888,7 @@ def convert_ulist node ==== END expected = <<~'END'.chomp + Tab A @@ -894,6 +897,7 @@ def convert_ulist node + END actual = Asciidoctor.convert input, backend: 'docbook'