aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-10-11 15:25:49 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-10-11 15:25:49 -0700
commit0e78eba791233b616f2435f2353586f9d3859480 (patch)
treebcf096faea5bf7b70a1e5ae45dd42d355ff27cfe /src/Text
parent60dcaa37d5cbaa9e9109b0a2a448ce663752b90d (diff)
downloadpandoc-0e78eba791233b616f2435f2353586f9d3859480.tar.gz
HTML reader/writer: better handling of "section" elements.
Previously `<section>` tags were just parsed as raw HTML blocks. With this change, section elements are parsed as Div elements with the class "section". The HTML writer will use `<section>` tags to render these Divs in HTML5; otherwise they will be rendered as `<div class="section">`. Closes #2438.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/HTML.hs13
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs7
2 files changed, 15 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs
index b32264d61..2c1034d1f 100644
--- a/src/Text/Pandoc/Readers/HTML.hs
+++ b/src/Text/Pandoc/Readers/HTML.hs
@@ -347,9 +347,16 @@ pRawTag = do
pDiv :: TagParser Blocks
pDiv = try $ do
guardEnabled Ext_native_divs
- TagOpen _ attr <- lookAhead $ pSatisfy $ tagOpen (=="div") (const True)
- contents <- pInTags "div" block
- return $ B.divWith (mkAttr attr) contents
+ let isDivLike "div" = True
+ isDivLike "section" = True
+ isDivLike _ = False
+ TagOpen tag attr <- lookAhead $ pSatisfy $ tagOpen isDivLike (const True)
+ contents <- pInTags tag block
+ let (ident, classes, kvs) = mkAttr attr
+ let classes' = if tag == "section"
+ then "section":classes
+ else classes
+ return $ B.divWith (ident, classes', kvs) contents
pRawHtmlBlock :: TagParser Blocks
pRawHtmlBlock = do
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index a2778ea97..6218de324 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -448,12 +448,15 @@ blockToHtml opts (Para [Image txt (s,'f':'i':'g':':':tit)]) = do
blockToHtml opts (Para lst) = do
contents <- inlineListToHtml opts lst
return $ H.p contents
-blockToHtml opts (Div attr@(_,classes,_) bs) = do
+blockToHtml opts (Div attr@(ident, classes, kvs) bs) = do
let speakerNotes = "notes" `elem` classes
-- we don't want incremental output inside speaker notes, see #1394
let opts' = if speakerNotes then opts{ writerIncremental = False } else opts
contents <- blockListToHtml opts' bs
let contents' = nl opts >> contents >> nl opts
+ let (divtag, classes') = if writerHtml5 opts && "section" `elem` classes
+ then (H5.section, filter (/= "section") classes)
+ else (H.div, classes)
return $
if speakerNotes
then case writerSlideVariant opts of
@@ -462,7 +465,7 @@ blockToHtml opts (Div attr@(_,classes,_) bs) = do
! (H5.customAttribute "role" "note")
NoSlides -> addAttrs opts' attr $ H.div $ contents'
_ -> mempty
- else addAttrs opts attr $ H.div $ contents'
+ else addAttrs opts (ident, classes', kvs) $ divtag $ contents'
blockToHtml opts (RawBlock f str)
| f == Format "html" = return $ preEscapedString str
| f == Format "latex" =