mirror of
https://github.com/foo-dogsquared/asciidoctor-foodogsquared-extensions.git
synced 2025-01-30 22:57:56 +00:00
Add video block for HTML5-modified
This commit is contained in:
parent
09a93481f0
commit
d868c0964c
@ -105,6 +105,48 @@ module Asciidoctor::Foodogsquared::Converters
|
|||||||
|
|
||||||
html.to_html(indent: 2)
|
html.to_html(indent: 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# A modified version of the video block except it can accept multiple
|
||||||
|
# sources with the `sources` attribute. Also, much of the built-in
|
||||||
|
# Asciidoctor capabilities such as the ability to quickly link from YouTube
|
||||||
|
# are removed.
|
||||||
|
def convert_video(node)
|
||||||
|
html = Nokogiri::HTML5::DocumentFragment.parse <<~HTML
|
||||||
|
<figure>
|
||||||
|
<video></video>
|
||||||
|
</figure>
|
||||||
|
HTML
|
||||||
|
figure = html.first_element_child
|
||||||
|
video = figure.first_element_child
|
||||||
|
|
||||||
|
add_common_attributes node, figure
|
||||||
|
add_boolean_attribute node, video, %w[loop controls muted]
|
||||||
|
add_attributes_from_node node, video, %w[width height]
|
||||||
|
|
||||||
|
if node.attr? 'sources'
|
||||||
|
_, sources = add_sources_elem node, video, 'video'
|
||||||
|
|
||||||
|
sources_download_links = sources.map do |src|
|
||||||
|
%(<a href="#{src}">#{src}</a>)
|
||||||
|
end
|
||||||
|
fallback_text = html.document.parse "Download the video at #{sources_download_links.join ', '}."
|
||||||
|
else
|
||||||
|
video['src'] = node.attr 'target'
|
||||||
|
fallback_text = html.document.parse "Download the video at #{node.attr 'target'}."
|
||||||
|
end
|
||||||
|
|
||||||
|
video.add_child fallback_text
|
||||||
|
|
||||||
|
if node.title?
|
||||||
|
html.document.create_element 'figcaption' do |block|
|
||||||
|
block.inner_html = node.captioned_title
|
||||||
|
figure.add_child block
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
html.to_html(indent: 2)
|
||||||
|
end
|
||||||
|
|
||||||
def add_common_attributes(node, html)
|
def add_common_attributes(node, html)
|
||||||
html['id'] = node.id if node.id
|
html['id'] = node.id if node.id
|
||||||
html.add_class node.role unless node.role.nil?
|
html.add_class node.role unless node.role.nil?
|
||||||
|
@ -66,6 +66,54 @@ describe Asciidoctor::Foodogsquared::Converters::HTML5Modified do
|
|||||||
(expect actual).to eq expected.chomp
|
(expect actual).to eq expected.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should have a video block with multiple <source>' do
|
||||||
|
input = <<~INPUT
|
||||||
|
video::hello.mp4[sources="hello.mp4,hello.webm"]
|
||||||
|
INPUT
|
||||||
|
|
||||||
|
expected = <<~HTML
|
||||||
|
<figure>
|
||||||
|
<video><source src="hello.mp4" type="video/mp4"><source src="hello.webm" type="video/webm"><p>Download the video at <a href="hello.mp4">hello.mp4</a>, <a href="hello.webm">hello.webm</a>.</p></video>
|
||||||
|
</figure>
|
||||||
|
HTML
|
||||||
|
|
||||||
|
actual = (Asciidoctor.convert input).chomp
|
||||||
|
(expect actual).to eq expected.chomp
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should have a video block with multiple <source> and a caption' do
|
||||||
|
input = <<~INPUT
|
||||||
|
.Making up stuff right now
|
||||||
|
video::./hello.mp4[sources="hello.mp4,hello.webm"]
|
||||||
|
INPUT
|
||||||
|
|
||||||
|
expected = <<~HTML
|
||||||
|
<figure>
|
||||||
|
<video><source src="hello.mp4" type="video/mp4"><source src="hello.webm" type="video/webm"><p>Download the video at <a href="hello.mp4">hello.mp4</a>, <a href="hello.webm">hello.webm</a>.</p></video>
|
||||||
|
<figcaption>Making up stuff right now</figcaption></figure>
|
||||||
|
HTML
|
||||||
|
|
||||||
|
actual = (Asciidoctor.convert input).chomp
|
||||||
|
(expect actual).to eq expected.chomp
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should have a video block with a caption, ID, and classes' do
|
||||||
|
input = <<~INPUT
|
||||||
|
[#video-sample.reverse]
|
||||||
|
.Making up stuff right now
|
||||||
|
video::./hello.mp4[sources="hello.mp4,hello.webm"]
|
||||||
|
INPUT
|
||||||
|
|
||||||
|
expected = <<~HTML
|
||||||
|
<figure id="video-sample" class="reverse">
|
||||||
|
<video><source src="hello.mp4" type="video/mp4"><source src="hello.webm" type="video/webm"><p>Download the video at <a href="hello.mp4">hello.mp4</a>, <a href="hello.webm">hello.webm</a>.</p></video>
|
||||||
|
<figcaption>Making up stuff right now</figcaption></figure>
|
||||||
|
HTML
|
||||||
|
|
||||||
|
actual = (Asciidoctor.convert input).chomp
|
||||||
|
(expect actual).to eq expected.chomp
|
||||||
|
end
|
||||||
|
|
||||||
it 'should have an audio block with multiple <source>' do
|
it 'should have an audio block with multiple <source>' do
|
||||||
input = <<~INPUT
|
input = <<~INPUT
|
||||||
audio::hello.mp3[sources="hello.mp3,hello.webm"]
|
audio::hello.mp3[sources="hello.mp3,hello.webm"]
|
||||||
|
Loading…
Reference in New Issue
Block a user