From e7e973d1c6f00ac1c1eaabd6a7565f90be438d62 Mon Sep 17 00:00:00 2001
From: Gabriel Arazas <foodogsquared@foodogsquared.one>
Date: Fri, 24 Nov 2023 11:47:28 +0800
Subject: [PATCH] Add sidebar block for HTML5-modified

---
 .../converters/html5-extended.rb              | 16 +++++++
 spec/html5_extended_converter.rb              | 48 +++++++++++++++++++
 2 files changed, 64 insertions(+)

diff --git a/lib/asciidoctor/foodogsquared/converters/html5-extended.rb b/lib/asciidoctor/foodogsquared/converters/html5-extended.rb
index 40e3cff..57e7cf3 100644
--- a/lib/asciidoctor/foodogsquared/converters/html5-extended.rb
+++ b/lib/asciidoctor/foodogsquared/converters/html5-extended.rb
@@ -67,6 +67,22 @@ module Asciidoctor::Foodogsquared::Converters
       html.to_html(indent: 2)
     end
 
+    def convert_sidebar(node)
+      html = Nokogiri::XML::DocumentFragment.parse '<aside></aside>'
+      aside = html.first_element_child
+      add_common_attributes node, aside
+
+      if node.title?
+        html.document.create_element 'strong' do |strong|
+          strong.add_class 'title'
+          strong.content = node.captioned_title
+          aside.add_child strong
+        end
+      end
+
+      aside.inner_html += node.content
+      html.to_html(indent: 2)
+    end
 
     # A modified version of the audio node except it can accept multiple
     # sources.
diff --git a/spec/html5_extended_converter.rb b/spec/html5_extended_converter.rb
index 36544bf..c4d2174 100644
--- a/spec/html5_extended_converter.rb
+++ b/spec/html5_extended_converter.rb
@@ -161,4 +161,52 @@ describe Asciidoctor::Foodogsquared::Converters::HTML5Modified do
     actual = (Asciidoctor.convert input).chomp
     (expect actual).to eq expected.chomp
   end
+
+  it 'should have a more semantic sidebar block' do
+    input = <<~INPUT
+      ****
+      A sidebar is used for auxiliary bits of content.
+      ****
+    INPUT
+
+    expected = <<~HTML
+      <aside><p>A sidebar is used for auxiliary bits of content.</p></aside>
+    HTML
+
+    actual = (Asciidoctor.convert input).chomp
+    (expect actual).to eq expected.chomp
+  end
+
+  it 'should have a more semantic sidebar block with a title' do
+    input = <<~INPUT
+      .A sidebar title
+      ****
+      A sidebar is used for auxiliary bits of content.
+      ****
+    INPUT
+
+    expected = <<~HTML
+      <aside><strong class="title">A sidebar title</strong><p>A sidebar is used for auxiliary bits of content.</p></aside>
+    HTML
+
+    actual = (Asciidoctor.convert input).chomp
+    (expect actual).to eq expected.chomp
+  end
+
+  it 'should have a more semantic sidebar block with a title, an ID, and several roles' do
+    input = <<~INPUT
+      [#sidebar-id.several.roles]
+      .A sidebar title
+      ****
+      A sidebar is used for auxiliary bits of content.
+      ****
+    INPUT
+
+    expected = <<~HTML
+      <aside id="sidebar-id" class="several roles"><strong class="title">A sidebar title</strong><p>A sidebar is used for auxiliary bits of content.</p></aside>
+    HTML
+
+    actual = (Asciidoctor.convert input).chomp
+    (expect actual).to eq expected.chomp
+  end
 end