From e0214f0677b52cddb9e91ba7ef8a7f333281740a Mon Sep 17 00:00:00 2001 From: A Farzat Date: Sat, 7 Mar 2026 11:26:12 +0300 Subject: 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). --- src/xml.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') 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!( @@ -97,12 +97,13 @@ pub fn build_epub_chapter( {|doc| make_stylesheet_links(doc, chapter, chapter_dir, url_to_file)} - {processed_fragment} ); + let wrapper_suffix = ""; + let wrapper_prefix = wrapper_xhtml.as_str().strip_suffix(wrapper_suffix).context("Wrapper must end with ")?; - 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. -- cgit v1.2.3-70-g09d2