summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-12-05 07:28:50 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2009-12-05 07:28:50 +0000
commitda6291d930487055726c128b1d09e074c5db5ad3 (patch)
treec0c8b42e92e20259e7d09d1106c024b4afda18e7 /src/Text/Pandoc
parent90c335c463f4fb706aa34e543476ea0263b5b308 (diff)
Fixed handling of footnotes in titles (HTML) and headers (LaTeX).
Resolves Issues #137. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1648 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs29
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs15
2 files changed, 28 insertions, 16 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index 3f8bf3637..fc60a063a 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -35,6 +35,7 @@ import Text.Pandoc.CharacterReferences ( decodeCharacterReferences )
import Text.Pandoc.Shared
import Text.Pandoc.Readers.TeXMath
import Text.Pandoc.Highlighting ( highlightHtml, defaultHighlightingCss )
+import Text.Pandoc.XML (stripTags)
import Numeric ( showHex )
import Data.Char ( ord, toLower )
import Data.List ( isPrefixOf )
@@ -87,13 +88,13 @@ writeHtmlString opts =
writeHtml :: WriterOptions -> Pandoc -> Html
writeHtml opts (Pandoc (Meta tit authors date) blocks) =
let titlePrefix = writerTitlePrefix opts
- topTitle = evalState (inlineListToHtml opts tit) defaultWriterState
- topTitle' = if null titlePrefix
- then topTitle
- else if null tit
- then stringToHtml titlePrefix
- else titlePrefix +++ " - " +++ topTitle
- metadata = thetitle topTitle' +++
+ (topTitle,st) = runState (inlineListToHtml opts tit) defaultWriterState
+ topTitle'' = stripTags $ showHtmlFragment topTitle
+ topTitle' = titlePrefix ++
+ (if null topTitle'' || null titlePrefix
+ then ""
+ else " - ") ++ topTitle''
+ metadata = thetitle << topTitle' +++
meta ! [httpequiv "Content-Type",
content "text/html; charset=UTF-8"] +++
meta ! [name "generator", content "pandoc"] +++
@@ -108,17 +109,17 @@ writeHtml opts (Pandoc (Meta tit authors date) blocks) =
else noHtml
sects = hierarchicalize blocks
toc = if writerTableOfContents opts
- then evalState (tableOfContents opts sects) defaultWriterState
+ then evalState (tableOfContents opts sects) st
else noHtml
- (blocks', newstate) = runState
- (mapM (elementToHtml opts) sects >>= return . toHtmlFromList)
- defaultWriterState
- cssLines = stCSS newstate
+ (blocks', st') = runState
+ (mapM (elementToHtml opts) sects >>= return . toHtmlFromList)
+ st
+ cssLines = stCSS st'
css = if S.null cssLines
then noHtml
else style ! [thetype "text/css"] $ primHtml $
'\n':(unlines $ S.toList cssLines)
- math = if stMath newstate
+ math = if stMath st'
then case writerHTMLMathMethod opts of
LaTeXMathML Nothing ->
primHtml latexMathMLScript
@@ -134,7 +135,7 @@ writeHtml opts (Pandoc (Meta tit authors date) blocks) =
else noHtml
head' = header $ metadata +++ math +++ css +++
primHtml (writerHeader opts)
- notes = reverse (stNotes newstate)
+ notes = reverse (stNotes st')
before = primHtml $ writerIncludeBefore opts
after = primHtml $ writerIncludeAfter opts
thebody = before +++ titleHeader +++ toc +++ blocks' +++
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 9a74a069e..0ced9d781 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -188,10 +188,21 @@ blockToLaTeX (DefinitionList lst) = do
blockToLaTeX HorizontalRule = return $ text $
"\\begin{center}\\rule{3in}{0.4pt}\\end{center}\n"
blockToLaTeX (Header level lst) = do
- txt <- inlineListToLaTeX (deVerb lst)
+ let lst' = deVerb lst
+ txt <- inlineListToLaTeX lst'
+ let noNote (Note _) = Str ""
+ noNote x = x
+ let lstNoNotes = processWith noNote lst'
+ -- footnotes in sections don't work unless you specify an optional
+ -- argument: \section[mysec]{mysec\footnote{blah}}
+ optional <- if lstNoNotes == lst'
+ then return empty
+ else do
+ res <- inlineListToLaTeX lstNoNotes
+ return $ char '[' <> res <> char ']'
return $ if (level > 0) && (level <= 3)
then text ("\\" ++ (concat (replicate (level - 1) "sub")) ++
- "section{") <> txt <> text "}\n"
+ "section") <> optional <> char '{' <> txt <> text "}\n"
else txt <> char '\n'
blockToLaTeX (Table caption aligns widths heads rows) = do
headers <- tableRowToLaTeX heads