Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions htmlbook-autogen/block_example.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<%#encoding:UTF-8%><div<%= @id && %( id="#{@id}") %> data-type="example"<%= attr?('role') ? %( class="#{attr 'role'}") : nil %>>
<%#encoding:UTF-8%><% if option? 'collapsible' %><details<%= @id && %( id="#{@id}") %><%= attr?('role') ? %( class="#{attr 'role'}") : nil %>>
<summary class="title"><%= title %></summary>
<div class="content">
<%= content %>
</div>
</details><% else %><div<%= @id && %( id="#{@id}") %> data-type="example"<%= attr?('role') ? %( class="#{attr 'role'}") : nil %>>
<h5><%= title %></h5>
<%= content
%></div>
<%= content
%></div><% end %>
11 changes: 8 additions & 3 deletions htmlbook/block_example.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<%#encoding:UTF-8%><div<%= @id && %( id="#{@id}") %> data-type="example"<%= attr?('role') ? %( class="#{attr 'role'}") : nil %>>
<%#encoding:UTF-8%><% if option? 'collapsible' %><details<%= @id && %( id="#{@id}") %><%= attr?('role') ? %( class="#{attr 'role'}") : nil %>>
<summary class="title"><%= title %></summary>
<div class="content">
<%= content %>
</div>
</details><% else %><div<%= @id && %( id="#{@id}") %> data-type="example"<%= attr?('role') ? %( class="#{attr 'role'}") : nil %>>
<h5><%= title %></h5>
<%= content
%></div>
<%= content
%></div><% end %>
39 changes: 39 additions & 0 deletions spec/htmlbook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,45 @@
expect(html.xpath("//div[@data-type='example'][1]/pre[@data-type='programlisting']/@data-code-language").text).to eq("php")
end

# Tests collapsible block (details tag) support
it "should convert collapsible blocks to details/summary elements" do
html = Nokogiri::HTML(convert("
.Details
[%collapsible]
====
This would be the show and hide!
====
"))
expect(html.xpath("//details/summary[@class='title']").text).to eq("Details")
expect(html.xpath("//details/div[@class='content']/p").text).to eq("This would be the show and hide!")
end

it "should convert collapsible blocks with an id" do
html = Nokogiri::HTML(convert("
[[my-details]]
.Click to expand
[%collapsible]
====
Hidden content here.
====
"))
expect(html.xpath("//details/@id").text).to eq("my-details")
expect(html.xpath("//details/summary[@class='title']").text).to eq("Click to expand")
expect(html.xpath("//details/div[@class='content']/p").text).to eq("Hidden content here.")
end

it "should convert collapsible blocks with a role attribute" do
html = Nokogiri::HTML(convert("
.Summary text
[%collapsible,role='special']
====
Content with a role.
====
"))
expect(html.xpath("//details/@class").text).to eq("special")
expect(html.xpath("//details/summary[@class='title']").text).to eq("Summary text")
end

it "should convert line numbering attribute in informal code listing" do
html = Nokogiri::HTML(convert("
[source, php, linenums]
Expand Down