aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorA Farzat <a@farzat.xyz>2026-03-07 11:26:12 +0300
committerA Farzat <a@farzat.xyz>2026-03-07 11:26:12 +0300
commite0214f0677b52cddb9e91ba7ef8a7f333281740a (patch)
tree5b5696e6463a34d06d0cced1e690c013c5050d69 /src
parent2dff30140ff8b46b8b82b761b4305ceb7b67108d (diff)
downloadoreilly-epub-e0214f0677b52cddb9e91ba7ef8a7f333281740a.tar.gz
oreilly-epub-e0214f0677b52cddb9e91ba7ef8a7f333281740a.zip
Prevent processed_fragment from escaping
This is done by not including it in the xml! macro in the first place. Instead, it is inserted later by using format!. This is because ogrim does not support injecting raw xml yet (to my knowledge).
Diffstat (limited to 'src')
-rw-r--r--src/xml.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/xml.rs b/src/xml.rs
index 63b4700..937fdcb 100644
--- a/src/xml.rs
+++ b/src/xml.rs
@@ -1,4 +1,4 @@
-use anyhow::Result;
+use anyhow::{Context, Result};
use ogrim::{Document, xml};
use quick_xml::events::{BytesStart, Event};
use quick_xml::{Reader, Writer};
@@ -88,7 +88,7 @@ pub fn build_epub_chapter(
// Wrap in EPUB XHTML Boilerplate.
// EPUBs strictly require the w3 and idpf namespaces to validate properly.
- let full_xhtml = xml!(
+ let wrapper_xhtml = xml!(
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"
lang={epub_data.language} xml:lang={epub_data.language}>
@@ -97,12 +97,13 @@ pub fn build_epub_chapter(
{|doc| make_stylesheet_links(doc, chapter, chapter_dir, url_to_file)}
</head>
<body>
- {processed_fragment}
</body>
</html>
);
+ let wrapper_suffix = "</body></html>";
+ let wrapper_prefix = wrapper_xhtml.as_str().strip_suffix(wrapper_suffix).context("Wrapper must end with </body></html>")?;
- Ok(full_xhtml.into_string())
+ Ok(format!("{}\n{}\n{}", wrapper_prefix, processed_fragment, wrapper_suffix))
}
/// Helper function add link elements for stylesheets to an xml Document.