diff --git a/src/Text/Pandoc/Writers/Docbook.hs b/src/Text/Pandoc/Writers/Docbook.hs index 1697b201c..2c47ba1f5 100644 --- a/src/Text/Pandoc/Writers/Docbook.hs +++ b/src/Text/Pandoc/Writers/Docbook.hs @@ -94,7 +94,8 @@ writeDocbook5 opts d = -- | Convert Pandoc document to string in Docbook format. writeDocbook :: PandocMonad m => WriterOptions -> Pandoc -> DB m Text -writeDocbook opts (Pandoc meta blocks) = do +writeDocbook opts doc = do + let Pandoc meta blocks = ensureValidXmlIdentifiers doc let colwidth = if writerWrapText opts == WrapAuto then Just $ writerColumns opts else Nothing diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index d48883dcd..794a338c7 100644 --- a/src/Text/Pandoc/Writers/EPUB.hs +++ b/src/Text/Pandoc/Writers/EPUB.hs @@ -35,7 +35,8 @@ import qualified Data.Text.Lazy as TL import System.FilePath (takeExtension, takeFileName, makeRelative) import Text.HTML.TagSoup (Tag (TagOpen), fromAttrib, parseTags) import Text.Pandoc.Builder (fromList, setMeta) -import Text.Pandoc.Class.PandocMonad (PandocMonad, report) +import Text.Pandoc.Writers.Shared (ensureValidXmlIdentifiers) +import Text.Pandoc.Class (PandocMonad, report) import qualified Text.Pandoc.Class.PandocPure as P import qualified Text.Pandoc.Class.PandocMonad as P import Data.Time @@ -435,8 +436,9 @@ pandocToEPUB :: PandocMonad m -> Pandoc -> E m B.ByteString pandocToEPUB version opts doc = do + let doc' = ensureValidXmlIdentifiers doc -- handle pictures - Pandoc meta blocks <- walkM (transformInline opts) doc >>= + Pandoc meta blocks <- walkM (transformInline opts) doc' >>= walkM transformBlock picEntries <- mapMaybe (snd . snd) <$> gets stMediaPaths diff --git a/src/Text/Pandoc/Writers/FB2.hs b/src/Text/Pandoc/Writers/FB2.hs index bb965a31f..42a5535c1 100644 --- a/src/Text/Pandoc/Writers/FB2.hs +++ b/src/Text/Pandoc/Writers/FB2.hs @@ -40,7 +40,8 @@ import Text.Pandoc.Logging import Text.Pandoc.Options (HTMLMathMethod (..), WriterOptions (..), def) import Text.Pandoc.Shared (capitalize, isURI, orderedListMarkers, makeSections, tshow, stringify) -import Text.Pandoc.Writers.Shared (lookupMetaString, toLegacyTable) +import Text.Pandoc.Writers.Shared (lookupMetaString, toLegacyTable, + ensureValidXmlIdentifiers) import Data.Generics (everywhere, mkT) -- | Data to be written at the end of the document: @@ -76,7 +77,8 @@ pandocToFB2 :: PandocMonad m => WriterOptions -> Pandoc -> FBM m Text -pandocToFB2 opts (Pandoc meta blocks) = do +pandocToFB2 opts doc = do + let Pandoc meta blocks = ensureValidXmlIdentifiers doc modify (\s -> s { writerOptions = opts }) desc <- description meta title <- cMapM toXml . docTitle $ meta diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 79d9b12e7..25a978e24 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -149,12 +149,14 @@ writeHtml5 = writeHtml' defaultWriterState{ stHtml5 = True } -- | Convert Pandoc document to Html 4 string. writeHtml4String :: PandocMonad m => WriterOptions -> Pandoc -> m Text -writeHtml4String = writeHtmlString' - defaultWriterState{ stHtml5 = False } +writeHtml4String opts = writeHtmlString' + defaultWriterState{ stHtml5 = False } opts . + ensureValidXmlIdentifiers -- | Convert Pandoc document to Html 4 structure. writeHtml4 :: PandocMonad m => WriterOptions -> Pandoc -> m Html -writeHtml4 = writeHtml' defaultWriterState{ stHtml5 = False } +writeHtml4 opts = writeHtml' defaultWriterState{ stHtml5 = False } opts . + ensureValidXmlIdentifiers -- | Convert Pandoc document to Html appropriate for an epub version. writeHtmlStringForEPUB :: PandocMonad m @@ -164,6 +166,8 @@ writeHtmlStringForEPUB version o = writeHtmlString' defaultWriterState{ stHtml5 = version == EPUB3, stEPUBVersion = Just version } o{ writerWrapText = WrapNone } + -- we don't use ensureValidXmlIdentifiers here because we + -- do that in the EPUB writer -- | Convert Pandoc document to Reveal JS HTML slide show. writeRevealJs :: PandocMonad m @@ -173,22 +177,25 @@ writeRevealJs = writeHtmlSlideShow' RevealJsSlides -- | Convert Pandoc document to S5 HTML slide show. writeS5 :: PandocMonad m => WriterOptions -> Pandoc -> m Text -writeS5 = writeHtmlSlideShow' S5Slides +writeS5 opts = writeHtmlSlideShow' S5Slides opts . + ensureValidXmlIdentifiers -- | Convert Pandoc document to Slidy HTML slide show. writeSlidy :: PandocMonad m => WriterOptions -> Pandoc -> m Text -writeSlidy = writeHtmlSlideShow' SlidySlides +writeSlidy opts = writeHtmlSlideShow' SlidySlides opts . + ensureValidXmlIdentifiers -- | Convert Pandoc document to Slideous HTML slide show. writeSlideous :: PandocMonad m => WriterOptions -> Pandoc -> m Text -writeSlideous = writeHtmlSlideShow' SlideousSlides +writeSlideous opts = writeHtmlSlideShow' SlideousSlides opts . + ensureValidXmlIdentifiers -- | Convert Pandoc document to DZSlides HTML slide show. writeDZSlides :: PandocMonad m => WriterOptions -> Pandoc -> m Text -writeDZSlides = writeHtmlSlideShow' DZSlides +writeDZSlides opts = writeHtmlSlideShow' DZSlides opts writeHtmlSlideShow' :: PandocMonad m => HTMLSlideVariant -> WriterOptions -> Pandoc -> m Text diff --git a/src/Text/Pandoc/Writers/ICML.hs b/src/Text/Pandoc/Writers/ICML.hs index ea6009fd1..8d75bb7df 100644 --- a/src/Text/Pandoc/Writers/ICML.hs +++ b/src/Text/Pandoc/Writers/ICML.hs @@ -131,7 +131,8 @@ citeName = "Cite" -- | Convert Pandoc document to string in ICML format. writeICML :: PandocMonad m => WriterOptions -> Pandoc -> m Text -writeICML opts (Pandoc meta blocks) = do +writeICML opts doc = do + let Pandoc meta blocks = ensureValidXmlIdentifiers doc let colwidth = if writerWrapText opts == WrapAuto then Just $ writerColumns opts else Nothing diff --git a/src/Text/Pandoc/Writers/ODT.hs b/src/Text/Pandoc/Writers/ODT.hs index 60c9342e5..cafa48c0b 100644 --- a/src/Text/Pandoc/Writers/ODT.hs +++ b/src/Text/Pandoc/Writers/ODT.hs @@ -36,7 +36,8 @@ import Text.Pandoc.Options (WrapOption (..), WriterOptions (..)) import Text.DocLayout import Text.Pandoc.Shared (stringify, pandocVersion, tshow) import Text.Pandoc.Writers.Shared (lookupMetaString, lookupMetaBlocks, - fixDisplayMath, getLang) + fixDisplayMath, getLang, + ensureValidXmlIdentifiers) import Text.Pandoc.UTF8 (fromStringLazy, fromTextLazy, toTextLazy) import Text.Pandoc.Walk import Text.Pandoc.Writers.OpenDocument (writeOpenDocument) @@ -58,8 +59,9 @@ writeODT :: PandocMonad m writeODT opts doc = let initState = ODTState{ stEntries = [] } + doc' = ensureValidXmlIdentifiers doc in - evalStateT (pandocToODT opts doc) initState + evalStateT (pandocToODT opts doc') initState -- | Produce an ODT file from a Pandoc document. pandocToODT :: PandocMonad m diff --git a/src/Text/Pandoc/Writers/TEI.hs b/src/Text/Pandoc/Writers/TEI.hs index bf5948ba6..c67005ec2 100644 --- a/src/Text/Pandoc/Writers/TEI.hs +++ b/src/Text/Pandoc/Writers/TEI.hs @@ -28,7 +28,8 @@ import Text.Pandoc.XML -- | Convert Pandoc document to string in Docbook format. writeTEI :: PandocMonad m => WriterOptions -> Pandoc -> m Text -writeTEI opts (Pandoc meta blocks) = do +writeTEI opts doc = do + let Pandoc meta blocks = ensureValidXmlIdentifiers doc let colwidth = if writerWrapText opts == WrapAuto then Just $ writerColumns opts else Nothing