@@ -219,10 +219,6 @@ def test_epub_metadata_and_text_are_unchanged() -> None:
219219 assert "Chapter text." in result .markdown
220220
221221
222- if __name__ == "__main__" :
223- raise SystemExit (pytest .main ([__file__ ]))
224-
225-
226222@pytest .mark .parametrize ("prefixed_part" , ["container" , "package" , "metadata" ])
227223def test_namespace_prefixes_do_not_change_epub_conversion (prefixed_part ):
228224 original = _build_epub (
@@ -276,3 +272,51 @@ def test_namespace_prefixes_do_not_change_epub_conversion(prefixed_part):
276272 text = result .markdown .replace ("\\ " , "" )
277273 assert "SECOND_BODY" in text and "FIRST_BODY" in text
278274 assert text .index ("SECOND_BODY" ) < text .index ("FIRST_BODY" )
275+
276+
277+ @pytest .mark .parametrize (
278+ "original_namespace,replacement_namespace" ,
279+ [
280+ (
281+ "http://www.idpf.org/2007/opf" ,
282+ "http://openebook.org/namespaces/oeb-package/1.0/" ,
283+ ),
284+ ("http://purl.org/dc/elements/1.1/" , "http://purl.org/dc/elements/1.0/" ),
285+ ("http://purl.org/dc/elements/1.1/" , "http://purl.org/dc/elements/1.1" ),
286+ ("urn:oasis:names:tc:opendocument:xmlns:container" , "urn:legacy:container" ),
287+ ("urn:oasis:names:tc:opendocument:xmlns:container" , "" ),
288+ ("http://www.idpf.org/2007/opf" , "" ),
289+ ],
290+ )
291+ def test_legacy_namespace_uris_keep_metadata_and_chapters (
292+ original_namespace , replacement_namespace
293+ ):
294+ original = _build_epub (
295+ [("c1" , "one.xhtml" )],
296+ ["c1" ],
297+ {"OEBPS/one.xhtml" : ("First" , "CHAPTER_BODY" )},
298+ )
299+ archive = io .BytesIO ()
300+ with zipfile .ZipFile (original ) as source , zipfile .ZipFile (archive , "w" ) as target :
301+ for entry in source .infolist ():
302+ content = source .read (entry )
303+ if entry .filename in ("META-INF/container.xml" , "OEBPS/content.opf" ):
304+ text = content .decode ().replace (
305+ original_namespace , replacement_namespace
306+ )
307+ if entry .filename == "OEBPS/content.opf" :
308+ text = text .replace (
309+ "</metadata>" ,
310+ "<dc:creator>Example Author</dc:creator></metadata>" ,
311+ )
312+ content = text .encode ()
313+ target .writestr (entry , content )
314+ archive .seek (0 )
315+ result = EpubConverter ().convert (archive , StreamInfo (extension = ".epub" ))
316+ assert result .title == "Encoded Hrefs"
317+ assert "**Authors:** Example Author" in result .markdown
318+ assert "CHAPTER_BODY" in result .markdown .replace ("\\ " , "" )
319+
320+
321+ if __name__ == "__main__" :
322+ raise SystemExit (pytest .main ([__file__ ]))
0 commit comments