diff options
| author | A Farzat <a@farzat.xyz> | 2026-03-06 13:00:51 +0300 |
|---|---|---|
| committer | A Farzat <a@farzat.xyz> | 2026-03-07 09:26:03 +0300 |
| commit | 8c1629670614f639df8a43d4730d025fe4dcdfb8 (patch) | |
| tree | 913846e615ea764648c9333e521b0b814c6fb1e9 /src/epub.rs | |
| parent | c98b360d611c37315c9c5330089a1d91dbb2021c (diff) | |
| download | oreilly-epub-8c1629670614f639df8a43d4730d025fe4dcdfb8.tar.gz oreilly-epub-8c1629670614f639df8a43d4730d025fe4dcdfb8.zip | |
Use xml! macro for cleaner xml handling
Diffstat (limited to 'src/epub.rs')
| -rw-r--r-- | src/epub.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/epub.rs b/src/epub.rs index 5383251..1d4676d 100644 --- a/src/epub.rs +++ b/src/epub.rs @@ -3,6 +3,7 @@ use crate::{ xml::build_epub_chapter, }; use anyhow::{Context, Result}; +use ogrim::xml; use relative_path::{RelativePath, RelativePathBuf}; use reqwest::Client; use std::{ @@ -22,21 +23,20 @@ fn write_container_xml_to_zip( opf_full_path: &RelativePathBuf, ) -> Result<()> { // Prepare file contents. - let contents = format!( - r#"<?xml version="1.0" encoding="UTF-8"?> -<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container"> - <rootfiles> - <rootfile full-path="{opf_full_path}" media-type="application/oebps-package+xml"/> - </rootfiles> -</container> -"# + let contents = xml!( + <?xml version="1.0" encoding="UTF-8"?> + <container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container"> + <rootfiles> + <rootfile full-path={opf_full_path} media-type="application/oebps-package+xml"/> + </rootfiles> + </container> ); // Write down the file. let options: FileOptions<()> = FileOptions::default().compression_method(CompressionMethod::Deflated); zip.start_file("META-INF/container.xml", options)?; - zip.write_all(contents.as_bytes())?; + zip.write_all(contents.as_str().as_bytes())?; Ok(()) } |
