From 012405e8c3df0ce400b05f524d14de88cf5d5115 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 28 Dec 2011 22:04:38 -0800 Subject: Preserve attributes in highlighted HTML. The container element will have the classes, id, and key-value attributes you specified in the delimited code block. Previously these were stripped off. --- src/Text/Pandoc/Highlighting.hs | 3 ++- src/Text/Pandoc/Writers/HTML.hs | 6 ++++-- tests/lhs-test.html | 2 +- tests/lhs-test.html+lhs | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Text/Pandoc/Highlighting.hs b/src/Text/Pandoc/Highlighting.hs index 276d98529..a40bab66a 100644 --- a/src/Text/Pandoc/Highlighting.hs +++ b/src/Text/Pandoc/Highlighting.hs @@ -70,6 +70,7 @@ highlight formatter (_, classes, keyvals) rawCode = in case find (`elem` lcLanguages) lcclasses of Nothing -> Nothing Just language -> Just - $ formatter fmtOpts{ codeClasses = [language] } + $ formatter fmtOpts{ codeClasses = [language], + containerClasses = classes } $ highlightAs language rawCode diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 3b926cf06..5b885dbfb 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -379,7 +379,7 @@ blockToHtml opts (CodeBlock (id',classes,keyvals) rawCode) = do in return $ foldl (!) H.pre attrs $ H.code $ toHtml adjCode Just h -> modify (\st -> st{ stHighlighting = True }) >> - return h + return (foldl (!) h (attrsToHtml opts (id',[],keyvals))) blockToHtml opts (BlockQuote blocks) = -- in S5, treat list in blockquote specially -- if default is incremental, make it nonincremental; @@ -547,7 +547,9 @@ inlineToHtml opts inline = Nothing -> return $ foldl (!) H.code (attrsToHtml opts attr) $ strToHtml str - Just h -> return h + Just h -> return $ foldl (!) h $ + attrsToHtml opts (id',[],keyvals) + where (id',_,keyvals) = attr (Strikeout lst) -> inlineListToHtml opts lst >>= return . H.del (SmallCaps lst) -> inlineListToHtml opts lst >>= diff --git a/tests/lhs-test.html b/tests/lhs-test.html index 1b6805ed8..291c374f3 100644 --- a/tests/lhs-test.html +++ b/tests/lhs-test.html @@ -27,7 +27,7 @@ code > span.er { color: #ff0000; font-weight: bold; }

lhs test

unsplit is an arrow that takes a pair of values and combines them to return a single value:

-
unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d
+
unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d
 unsplit = arr . uncurry       
           -- arr (\op (x,y) -> x `op` y) 

(***) combines two arrows into a new arrow by running the two arrows on a pair of values (one arrow on the first item of the pair and one arrow on the second item of the pair).

diff --git a/tests/lhs-test.html+lhs b/tests/lhs-test.html+lhs index e21522cef..ff0ebfac5 100644 --- a/tests/lhs-test.html+lhs +++ b/tests/lhs-test.html+lhs @@ -27,7 +27,7 @@ code > span.er { color: #ff0000; font-weight: bold; }

lhs test

unsplit is an arrow that takes a pair of values and combines them to return a single value:

-
> unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d
+
> unsplit :: (Arrow a) => (b -> c -> d) -> a (b, c) d
 > unsplit = arr . uncurry       
 >           -- arr (\op (x,y) -> x `op` y) 

(***) combines two arrows into a new arrow by running the two arrows on a pair of values (one arrow on the first item of the pair and one arrow on the second item of the pair).

-- cgit v1.2.3