Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/Text/Pandoc/Writers/EPUB.hs
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ pandocToEPUB :: PandocMonad m
pandocToEPUB version opts doc = do
let doc' = ensureValidXmlIdentifiers doc
-- handle pictures
Pandoc meta blocks <- walkM (transformInline opts) doc' >>=
walkM transformBlock
Pandoc meta blocks <- walkM (transformInline version opts) doc' >>=
walkM (transformBlock version)
picEntries <- mapMaybe (snd . snd) <$> gets stMediaPaths

epubSubdir <- gets stEpubSubdir
Expand Down Expand Up @@ -1203,42 +1203,47 @@ getMediaNextNewName ext = do
modify $ \st -> st { stMediaNextId = nextId + 1 }
return $ "file" ++ show nextId ++ ext

isHtmlFormat :: Format -> Bool
isHtmlFormat (Format "html") = True
isHtmlFormat (Format "html4") = True
isHtmlFormat (Format "html5") = True
isHtmlFormat _ = False
isHtmlFormat :: EPUBVersion -> Format -> Bool
isHtmlFormat _ (Format "html") = True
isHtmlFormat _ (Format "html4") = True
isHtmlFormat _ (Format "html5") = True
isHtmlFormat _ (Format "epub") = True
isHtmlFormat EPUB2 (Format "epub2") = True
isHtmlFormat EPUB3 (Format "epub3") = True
isHtmlFormat _ _ = False

transformBlock :: PandocMonad m
=> Block
=> EPUBVersion
-> Block
-> E m Block
transformBlock (RawBlock fmt raw)
| isHtmlFormat fmt = do
transformBlock version (RawBlock fmt raw)
| isHtmlFormat version fmt = do
let tags = parseTags raw
tags' <- mapM transformTag tags
return $ RawBlock fmt (renderTags' tags')
transformBlock b = return b
transformBlock _ b = return b

transformInline :: PandocMonad m
=> WriterOptions
=> EPUBVersion
-> WriterOptions
-> Inline
-> E m Inline
transformInline _opts (Image attr@(_,_,kvs) lab (src,tit))
transformInline _ _opts (Image attr@(_,_,kvs) lab (src,tit))
| isNothing (lookup "external" kvs) = do
newsrc <- modifyMediaRef $ T.unpack src
return $ Image attr lab ("../" <> newsrc, tit)
transformInline opts x@(Math t m)
transformInline _ opts x@(Math t m)
| WebTeX url <- writerHTMLMathMethod opts = do
newsrc <- modifyMediaRef (T.unpack (url <> urlEncode m))
let mathclass = if t == DisplayMath then "display" else "inline"
return $ Span ("",["math",mathclass],[])
[Image nullAttr [x] ("../" <> newsrc, "")]
transformInline _opts (RawInline fmt raw)
| isHtmlFormat fmt = do
transformInline version _opts (RawInline fmt raw)
| isHtmlFormat version fmt = do
let tags = parseTags raw
tags' <- mapM transformTag tags
return $ RawInline fmt (renderTags' tags')
transformInline _ x = return x
transformInline _ _ x = return x

(!) :: (t -> Element) -> [(Text, Text)] -> t -> Element
(!) f attrs n = add_attrs (map (\(k,v) -> Attr (unqual k) v) attrs) (f n)
Expand Down
10 changes: 10 additions & 0 deletions src/Text/Pandoc/Writers/HTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1795,10 +1795,20 @@ intrinsicEventsHTML4 =
isRawHtml :: PandocMonad m => Format -> StateT WriterState m Bool
isRawHtml f = do
html5 <- gets stHtml5
epubVersion <- gets stEPUBVersion
return $ f == Format "html" ||
((html5 && f == Format "html5") || f == Format "html4") ||
isEpubFormat epubVersion f ||
isSlideVariant f

-- | Check to see if Format matches with an EPUB variant
isEpubFormat :: Maybe EPUBVersion -> Format -> Bool
isEpubFormat Nothing _ = False
isEpubFormat (Just EPUB2) f =
f == Format "epub" || f == Format "epub2"
isEpubFormat (Just EPUB3) f =
f == Format "epub" || f == Format "epub3"

-- | Check to see if Format matches with an HTML slide variant
isSlideVariant :: Format -> Bool
isSlideVariant f = f `elem` [Format "s5", Format "slidy", Format "slideous",
Expand Down
42 changes: 42 additions & 0 deletions test/command/8880.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Raw EPUB attributes are rendered in EPUB output.

```
% pandoc -f native -t epub --metadata title=Raw -o - | pandoc -f epub -t html
[ RawBlock (Format "epub") "<p>ok</p>" ]
^D
<p><span id="title_page.xhtml"></span></p>
<p><span id="ch001.xhtml"></span></p>
<section id="ch001.xhtml_raw" class="unnumbered level1">
<h1 class="unnumbered">Raw</h1>
<p>ok</p>
</section>
```

Raw EPUB2 attributes are omitted from EPUB3 output.

```
% pandoc -f markdown -t epub3 --metadata title=Raw -o - | pandoc -f epub -t html
~~~ {=epub2}
<p>ok</p>
~~~
^D
<p><span id="title_page.xhtml"></span></p>
<p><span id="ch001.xhtml"></span></p>
<section id="ch001.xhtml_raw" class="unnumbered level1">
<h1 class="unnumbered">Raw</h1>
</section>
```

```
% pandoc -f markdown -t epub3 --metadata title=Raw -o - | pandoc -f epub -t html
~~~ {=epub3}
<p>ok</p>
~~~
^D
<p><span id="title_page.xhtml"></span></p>
<p><span id="ch001.xhtml"></span></p>
<section id="ch001.xhtml_raw" class="unnumbered level1">
<h1 class="unnumbered">Raw</h1>
<p>ok</p>
</section>
```
Loading