lib/asciidoctor-epub3/converter.rb in asciidoctor-epub3-1.5.0.alpha.5 vs lib/asciidoctor-epub3/converter.rb in asciidoctor-epub3-1.5.0.alpha.6
- old
+ new
@@ -147,30 +147,37 @@
mark_last_paragraph node
content = node.content
# NOTE must run after content is resolved
- # NOTE pubtree requires icon CSS to be repeated inside <body> (or in a linked stylesheet); perhaps create dynamic CSS file?
- icon_css = unless @icon_names.empty?
+ # TODO perhaps create dynamic CSS file?
+ if @icon_names.empty?
+ icon_css_head = icon_css_scoped = nil
+ else
icon_defs = @icon_names.map {|name|
%(.i-#{name}::before { content: "#{FontIconMap[name.tr('-', '_').to_sym]}"; })
} * EOL
- %(<style>
+ icon_css_head = %(<style>
#{icon_defs}
</style>
)
+ # NOTE Namo Pubtree requires icon CSS to be repeated inside <body> (or in a linked stylesheet); wrap in div to hide from Aldiko
+ icon_css_scoped = (node.attr? 'ebook-format', 'kf8') ? nil : %(<div style="display: none" aria-hidden="true"><style scoped="scoped">
+#{icon_defs}
+</style></div>
+)
end
# NOTE kindlegen seems to mangle the <header> element, so we wrap its content in a div
lines = [%(<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="#{lang = (node.attr 'lang', 'en')}" lang="#{lang}">
<head>
<meta charset="UTF-8"/>
<title>#{doctitle_sanitized}</title>
<link rel="stylesheet" type="text/css" href="styles/epub3.css"/>
<link rel="stylesheet" type="text/css" href="styles/epub3-css3-only.css" media="(min-device-width: 0px)"/>
-#{icon_css}<script type="text/javascript">
+#{icon_css_head}<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function(event) {
var epubReader = navigator.epubReadingSystem;
if (!epubReader) {
if (window.parent == window || !(epubReader = window.parent.navigator.epubReadingSystem)) {
return;
@@ -180,11 +187,11 @@
});
</script>
</head>
<body>
<section class="chapter" title="#{doctitle_sanitized.gsub '"', '"'}" epub:type="chapter" id="#{docid}">
-#{icon_css && (icon_css.sub '<style>', '<style scoped="scoped">')}<header>
+#{icon_css_scoped}<header>
<div class="chapter-header">
<p class="byline"><img src="#{imagesdir}avatars/#{username}.jpg"/> <b class="author">#{author}</b></p>
<h1 class="chapter-title">#{title_upper}#{subtitle ? %[ <small class="subtitle">#{subtitle_formatted_upper}</small>] : nil}</h1>
</div>
</header>
@@ -331,11 +338,11 @@
title_div = node.title? ? %(<figcaption>#{node.captioned_title}</figcaption>
) : nil
# patches conums to fix extra or missing leading space
# TODO apply this patch upstream to Asciidoctor
%(<figure class="#{figure_classes * ' '}">
-#{title_div}<pre class="#{pre_classes * ' '}"><code>#{node.content.gsub(/(?<! )<i class="conum"| +<i class="conum"/, ' <i class="conum"')}</code></pre>
+#{title_div}<pre class="#{pre_classes * ' '}"><code>#{(node.content || '').gsub(/(?<! )<i class="conum"| +<i class="conum"/, ' <i class="conum"')}</code></pre>
</figure>)
end
# QUESTION should we wrap the <pre> in either <div> or <figure>?
def literal node
@@ -560,11 +567,11 @@
lines << '<dd>'
if dd.blocks?
lines << %(<span class="principal">#{dd.text}</span>) if dd.text?
lines << dd.content
else
- lines << dd.text
+ lines << %(<span class="principal">#{dd.text}</span>)
end
lines << '</dd>'
end
end
lines << '</dl>
@@ -579,11 +586,11 @@
div_classes = ['ordered-list', node.style, node.role].compact
ol_classes = [node.style, ((node.option? 'brief') ? 'brief' : nil)].compact
ol_class_attr = ol_classes.empty? ? nil : %( class="#{ol_classes * ' '}")
id_attribute = node.id ? %( id="#{node.id}") : nil
lines = [%(<div#{id_attribute} class="#{div_classes * ' '}">)]
- lines << %(<h3>#{node.title}</h3>) if node.title?
+ lines << %(<h3 class="list-heading">#{node.title}</h3>) if node.title?
lines << %(<ol#{ol_class_attr}#{(node.option? 'reversed') ? ' reversed="reversed"' : nil}>)
node.items.each do |item|
lines << %(<li>
<span class="principal">#{item.text}</span>)
if item.blocks?
@@ -607,10 +614,10 @@
# TODO could strip WordJoiner if brief since not using justify
ul_classes = [node.style, ((node.option? 'brief') ? 'brief' : nil)].compact
ul_class_attr = ul_classes.empty? ? nil : %( class="#{ul_classes * ' '}")
id_attribute = node.id ? %( id="#{node.id}") : nil
lines = [%(<div#{id_attribute} class="#{div_classes * ' '}">)]
- lines << %(<h3>#{node.title}</h3>) if node.title?
+ lines << %(<h3 class="list-heading">#{node.title}</h3>) if node.title?
lines << %(<ul#{ul_class_attr}>)
node.items.each do |item|
lines << %(<li>
<span class="principal">#{item.text}</span>)
if item.blocks?