From 393b6e8a22c55c332cf44ecef079fe5499513a5e Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Tue, 5 Nov 2024 11:53:49 -0600 Subject: [PATCH] build: Improve proofreading CSS, and add color to no-break spaces and no-break hyphens --- se/data/templates/proofreading.css | 4 +++- se/se_epub_build.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/se/data/templates/proofreading.css b/se/data/templates/proofreading.css index dd09c95b..baf5432e 100644 --- a/se/data/templates/proofreading.css +++ b/se/data/templates/proofreading.css @@ -2,6 +2,8 @@ [epub|type~="z3998:roman"], [lang]:not(html), abbr, -time{ +time, +.proofreading, +span[epub|type]{ background: #C0C0C0; } diff --git a/se/se_epub_build.py b/se/se_epub_build.py index 37a2ba92..d09691f7 100644 --- a/se/se_epub_build.py +++ b/se/se_epub_build.py @@ -182,6 +182,16 @@ def build(self, run_epubcheck: bool, check_only: bool, build_kobo: bool, build_k with importlib.resources.files("se.data.templates").joinpath("proofreading.css").open("r", encoding="utf-8") as proofreading_css_file: local_css_file.write("\n" + proofreading_css_file.read()) + # Wrap no-break hyphens and no-break spaces in a class that will colorize them when proofing. + for file_path in work_compatible_epub_dir.glob("**/*.xhtml"): + with open(file_path, "r+", encoding="utf-8") as file: + xhtml = file.read() + + xhtml = regex.sub(fr"([{se.NO_BREAK_HYPHEN}{se.NO_BREAK_SPACE}])", r"""\1""", xhtml) + file.seek(0) + file.write(se.formatting.simplify_css(xhtml)) + file.truncate() + # Update the release date in the metadata and colophon if self.last_commit: for file_path in work_compatible_epub_dir.glob("**/*.xhtml"):