private HtmlDom MakePageFile(XmlElement pageElement, int pageIndex, int firstContentPageIndex)
{
var pageDom = GetEpubFriendlyHtmlDomForPage(pageElement);
// Note, the following stylsheet stuff can be quite bewildering...
// Testing shows that these stylesheets are not actually used
// in RemoveUnwantedContent(), which falls back to the stylsheets in place for the book, which in turn,
// in unit tests, is backed by a simple mocked BookStorage which doesn't have the stylesheet smarts. Sigh.
pageDom.RemoveModeStyleSheets();
if (Unpaginated)
{
RemoveRegularStylesheets(pageDom);
pageDom.AddStyleSheet(Storage.GetFileLocator().LocateFileWithThrow(@"baseEPUB.css").ToLocalhost());
}
else
{
// Review: this branch is not currently used. Very likely we need SOME different stylesheets
// from the printed book, possibly including baseEPUB.css, if it's even possible to make
// useful fixed-layout books out of Bloom books that will work with current readers.
pageDom.AddStyleSheet(Storage.GetFileLocator().LocateFileWithThrow(@"basePage.css").ToLocalhost());
pageDom.AddStyleSheet(Storage.GetFileLocator().LocateFileWithThrow(@"previewMode.css"));
pageDom.AddStyleSheet(Storage.GetFileLocator().LocateFileWithThrow(@"origami.css"));
}
RemoveUnwantedContent(pageDom);
pageDom.AddStyleSheet("languageDisplay.css");
pageDom.SortStyleSheetLinks();
pageDom.AddPublishClassToBody();
MakeCssLinksAppropriateForEpub(pageDom);
RemoveBloomUiElements(pageDom);
RemoveSpuriousLinks(pageDom);
RemoveScripts(pageDom);
FixIllegalIds(pageDom);
FixPictureSizes(pageDom);
// Since we only allow one htm file in a book folder, I don't think there is any
// way this name can clash with anything else.
var pageDocName = pageIndex + ".xhtml";
if (pageIndex == 1)
_coverPage = pageDocName;
CopyImages(pageDom);
_manifestItems.Add(pageDocName);
_spineItems.Add(pageDocName);
if (!_publishWithoutAudio)
AddAudioOverlay(pageDom, pageDocName);
if (pageIndex == firstContentPageIndex)
_firstContentPageItem = pageDocName;
FixChangedFileNames(pageDom);
pageDom.AddStyleSheet("fonts.css"); // enhance: could omit if we don't embed any
// ePUB validator requires HTML to use namespace. Do this last to avoid (possibly?) messing up our xpaths.
pageDom.RawDom.DocumentElement.SetAttribute("xmlns", "http://www.w3.org/1999/xhtml");
RobustFile.WriteAllText(Path.Combine(_contentFolder, pageDocName), pageDom.RawDom.OuterXml);
return pageDom;
}