aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers/HTML.hs
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-12-20 00:25:54 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-12-20 00:25:54 +0000
commit5cf769b1cd1d9e76ff5f543aba8b4a15a90b7d88 (patch)
treec09f786f43f29aba1bdd43587fec0c5162ae441a /src/Text/Pandoc/Writers/HTML.hs
parentc1ebe94e40a66a092c2cd501eda1edb5ec216938 (diff)
downloadpandoc-5cf769b1cd1d9e76ff5f543aba8b4a15a90b7d88.tar.gz
Modified the HTML writer to add invisible anchors to each section
heading. The anchors are derived form the text of the section heading as described in README. This makes it easy to insert links that jump from one part of a document to another: for example, '[back to the Introduction](#Introduction)'. git-svn-id: https://pandoc.googlecode.com/svn/trunk@246 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Text/Pandoc/Writers/HTML.hs')
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index f1bd0f8b5..7ba506acb 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -154,12 +154,14 @@ blockToHtml options (OrderedList lst) =
let attribs = if (writerIncremental options) then " class=\"incremental\"" else "" in
"<ol" ++ attribs ++ ">\n" ++ (concatMap (listItemToHtml options) lst) ++ "</ol>\n"
blockToHtml options HorizontalRule = "<hr />\n"
-blockToHtml options (Header level lst) = if ((level > 0) && (level <= 6)) then
- "<h" ++ (show level) ++ ">" ++
- (inlineListToHtml options lst) ++
- "</h" ++ (show level) ++ ">\n"
- else
- "<p>" ++ (inlineListToHtml options lst) ++ "</p>\n"
+blockToHtml options (Header level lst) =
+ let contents = inlineListToHtml options lst in
+ let simplify = gsub "<[^>]*>" "" . gsub " " "_" in
+ if ((level > 0) && (level <= 6))
+ then "<a id=\"" ++ simplify contents ++ "\"></a>\n" ++
+ "<h" ++ (show level) ++ ">" ++ contents ++
+ "</h" ++ (show level) ++ ">\n"
+ else "<p>" ++ contents ++ "</p>\n"
listItemToHtml options list = "<li>" ++ (concatMap (blockToHtml options) list) ++ "</li>\n"
-- | Convert list of Pandoc inline elements to HTML.