diff --git a/se/commands/create_draft.py b/se/commands/create_draft.py index 75d1a216..5ec53de3 100644 --- a/se/commands/create_draft.py +++ b/se/commands/create_draft.py @@ -767,7 +767,6 @@ def _create_draft(args: Namespace): _copy_template_file("container.xml", content_path / "META-INF") _copy_template_file("mimetype", content_path) _copy_template_file("onix.xml", content_path / "epub") - _copy_template_file("toc.xhtml", content_path / "epub") _copy_template_file("core.css", content_path / "epub" / "css") if args.white_label: @@ -775,6 +774,7 @@ def _create_draft(args: Namespace): _copy_template_file("titlepage-white-label.xhtml", content_path / "epub" / "text" / "titlepage.xhtml") _copy_template_file("cover.jpg", content_path / "epub" / "images") _copy_template_file("local-white-label.css", content_path / "epub" / "css" / "local.css") + _copy_template_file("toc-white-label.xhtml", content_path / "epub" / "toc.xhtml") else: _copy_template_file("cover.jpg", repo_path / "images") @@ -788,6 +788,7 @@ def _create_draft(args: Namespace): _copy_template_file("uncopyright.xhtml", content_path / "epub" / "text") _copy_template_file("titlepage.xhtml", content_path / "epub" / "text") _copy_template_file("content.opf", content_path / "epub") + _copy_template_file("toc.xhtml", content_path / "epub") _copy_template_file("LICENSE.md", repo_path) # Try to find Wikipedia links if possible diff --git a/se/data/templates/compatibility-white-label.css b/se/data/templates/compatibility-white-label.css new file mode 100644 index 00000000..ddbf9b93 --- /dev/null +++ b/se/data/templates/compatibility-white-label.css @@ -0,0 +1,52 @@ +/* For legacy reading systems */ +article, +aside, +figure, +figcaption, +footer, +header, +main, +nav, +section{ + display: block; +} + +/* Give PNGs a white background for night mode compatibility... */ +img[epub|type~="se:image.color-depth.black-on-transparent"]{ + background: #fff !important; /* `!important` is required to make sure readers respect the BG color */ +} + +/* ...unless the device supports prefers-color-scheme. We’ll invert the image in core.css. RMSDK requires a target media as well as a state. */ +@media all and (prefers-color-scheme){ + img[epub|type~="se:image.color-depth.black-on-transparent"]:not([epub|type~="se:image.style.realistic"]){ + background: transparent !important; + } +} + +/* Vertical align any MathML images we might have */ +img.mathml{ + vertical-align: middle; +} + +/* As of 2020-09 hanging punctuation only works on iBooks. However, when it hangs over the page margin, it's + not rendered. So here we simply remove it for iBooks, unless it's on an element that already has a margin + like
*/ +:root[__ibooks_internal_theme] blockquote + p, +:root[__ibooks_internal_theme] h2 + p, +:root[__ibooks_internal_theme] h3 + p, +:root[__ibooks_internal_theme] h4 + p, +:root[__ibooks_internal_theme] h5 + p, +:root[__ibooks_internal_theme] h6 + p, +:root[__ibooks_internal_theme] header + p, +:root[__ibooks_internal_theme] hr + p, +:root[__ibooks_internal_theme] ol + p, +:root[__ibooks_internal_theme] ul + p, +:root[__ibooks_internal_theme] table + p, +:root[__ibooks_internal_theme] hgroup + p, +:root[__ibooks_internal_theme] p:first-child{ + hanging-punctuation: none !important; +} + +:root[__ibooks_internal_theme] blockquote p:first-child{ + hanging-punctuation: first last !important; +} diff --git a/se/data/templates/compatibility.css b/se/data/templates/compatibility.css index 612e795e..879ab66e 100644 --- a/se/data/templates/compatibility.css +++ b/se/data/templates/compatibility.css @@ -19,7 +19,7 @@ section[epub|type~="imprint"] h2{ display: none; } -/* ...but enable them accessibility in all other ereaders */ +/* ...but enable them for accessibility in all other ereaders */ @supports(font-size: 0){ section[epub|type~="titlepage"] h1, section[epub|type~="titlepage"] p, @@ -39,13 +39,13 @@ img[epub|type~="se:image.color-depth.black-on-transparent"]{ background: #fff !important; /* `!important` is required to make sure readers respect the BG color */ } -/* Except our house PNGs, which were rendered from SVGs with a white stroke... */ +/* ...except our house PNGs, which were rendered from SVGs with a white stroke... */ [epub|type~="titlepage"] img[epub|type~="se:image.color-depth.black-on-transparent"], img[epub|type~="se:image.color-depth.black-on-transparent"][epub|type~="z3998:publisher-logo"]{ background: transparent !important; } -/* ..or if the device supports prefers-color-scheme. We’ll invert the image in core.css. RMSDK requires a target media as well as a state. */ +/* ...or if the device supports prefers-color-scheme. We’ll invert the image in core.css. RMSDK requires a target media as well as a state. */ @media all and (prefers-color-scheme){ img[epub|type~="se:image.color-depth.black-on-transparent"]:not([epub|type~="se:image.style.realistic"]){ background: transparent !important; diff --git a/se/data/templates/local-white-label.css b/se/data/templates/local-white-label.css index 74ef50c8..64785876 100644 --- a/se/data/templates/local-white-label.css +++ b/se/data/templates/local-white-label.css @@ -1,12 +1,7 @@ @charset "utf-8"; @namespace epub "http://www.idpf.org/2007/ops"; -h1{ - margin-bottom: 1em; -} - -#titlepage p{ - font-variant: small-caps; +section[epub|type~="titlepage"] p{ text-align: center; text-indent: 0; } diff --git a/se/data/templates/titlepage-white-label.xhtml b/se/data/templates/titlepage-white-label.xhtml index c7a2614f..5758a2f3 100644 --- a/se/data/templates/titlepage-white-label.xhtml +++ b/se/data/templates/titlepage-white-label.xhtml @@ -8,12 +8,9 @@

TITLE

-

By
- AUTHOR

-

Translated by
- TRANSLATOR

-

Illustrated by
- ILLUSTRATOR

+

By AUTHOR.

+

Translated by TRANSLATOR.

+

Illustrated by ILLUSTRATOR.

diff --git a/se/data/templates/toc-white-label.xhtml b/se/data/templates/toc-white-label.xhtml new file mode 100644 index 00000000..4b1842c5 --- /dev/null +++ b/se/data/templates/toc-white-label.xhtml @@ -0,0 +1,21 @@ + + + + Table of Contents + + + + + + diff --git a/se/data/templates/toc.xhtml b/se/data/templates/toc.xhtml index 6cbd1975..22b41655 100644 --- a/se/data/templates/toc.xhtml +++ b/se/data/templates/toc.xhtml @@ -27,21 +27,9 @@ diff --git a/se/se_epub_build.py b/se/se_epub_build.py index 64b8bc30..119b7463 100644 --- a/se/se_epub_build.py +++ b/se/se_epub_build.py @@ -222,9 +222,13 @@ def build(self, run_epubcheck: bool, check_only: bool, build_kobo: bool, build_k # Now add compatibility fixes for older ereaders. # Include compatibility CSS + compatibility_css_filename = "compatibility.css" + if not self.metadata_dom.xpath("//dc:identifier[starts-with(., 'url:https://standardebooks.org')]"): + compatibility_css_filename = "compatibility-white-label.css" + with open(work_compatible_epub_dir / "epub" / "css" / "core.css", "a", encoding="utf-8") as core_css_file: - with importlib_resources.open_text("se.data.templates", "compatibility.css", encoding="utf-8") as compatibility_css_file: - core_css_file.write(compatibility_css_file.read()) + with importlib_resources.open_text("se.data.templates", compatibility_css_filename, encoding="utf-8") as compatibility_css_file: + core_css_file.write("\n" + compatibility_css_file.read()) # Simplify CSS and tags total_css = ""