git.iko.soy/typeable/pandoc
on master help sign in
HTML writer: Better handling of authors in meta tags.

Footnotes and email addresses now come out in a more pleasing way. Modified from a patch by B. Scott Michel.

commit673c044a157e49c1cd6458c70d55afeac7d91970 authorJohn MacFarlane <fiddlosopher@gmail.com> dateFri 30 Dec 2011, 13:03 (15 years ago) parentedf646a
1 file changed+26−12
src/Text/Pandoc/Writers/HTML.hs+26−12
src/Text/Pandoc/Writers/HTML.hs+26−12
@@ -34,6 +34,7 @@ import Text.Pandoc.Definition
3434import Text.Pandoc.CharacterReferences ( decodeCharacterReferences )
3535import Text.Pandoc.Shared
3636import Text.Pandoc.Templates
37+import Text.Pandoc.Generic
3738import Text.Pandoc.Readers.TeXMath
3839import Text.Pandoc.Highlighting ( highlight, styleToHtml,
3940 formatHtmlInline, formatHtmlBlock )
@@ -80,25 +81,25 @@ nl opts = if writerWrapText opts
8081-- | Convert Pandoc document to Html string.
8182writeHtmlString :: WriterOptions -> Pandoc -> String
8283writeHtmlString opts d =
83− let (tit, auths, date, toc, body', newvars) = evalState (pandocToHtml opts d)
84− defaultWriterState
84+ let (tit, auths, authsMeta, date, toc, body', newvars) = evalState (pandocToHtml opts d)
85+ defaultWriterState
8586 in if writerStandalone opts
86− then inTemplate opts tit auths date toc body' newvars
87+ then inTemplate opts tit auths authsMeta date toc body' newvars
8788 else renderHtml body'
8889
8990-- | Convert Pandoc document to Html structure.
9091writeHtml :: WriterOptions -> Pandoc -> Html
9192writeHtml opts d =
92− let (tit, auths, date, toc, body', newvars) = evalState (pandocToHtml opts d)
93− defaultWriterState
93+ let (tit, auths, authsMeta, date, toc, body', newvars) = evalState (pandocToHtml opts d)
94+ defaultWriterState
9495 in if writerStandalone opts
95− then inTemplate opts tit auths date toc body' newvars
96+ then inTemplate opts tit auths authsMeta date toc body' newvars
9697 else body'
9798
9899-- result is (title, authors, date, toc, body, new variables)
99100pandocToHtml :: WriterOptions
100101 -> Pandoc
101− -> State WriterState (Html, [Html], Html, Maybe Html, Html, [(String,String)])
102+ -> State WriterState (Html, [Html], [Html], Html, Maybe Html, Html, [(String,String)])
102103pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
103104 let standalone = writerStandalone opts
104105 tit <- if standalone
@@ -107,6 +108,9 @@ pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
107108 auths <- if standalone
108109 then mapM (inlineListToHtml opts) authors'
109110 else return []
111+ authsMeta <- if standalone
112+ then mapM (inlineListToHtml opts . prepForMeta) authors'
113+ else return []
110114 date <- if standalone
111115 then inlineListToHtml opts date'
112116 else return mempty
@@ -158,20 +162,30 @@ pandocToHtml opts (Pandoc (Meta title' authors' date') blocks) = do
158162 $ writerHighlightStyle opts) |
159163 stHighlighting st] ++
160164 [("math", renderHtml math) | stMath st]
161− return (tit, auths, date, toc, thebody, newvars)
165+ return (tit, auths, authsMeta, date, toc, thebody, newvars)
166+
167+-- | Prepare author for meta tag, converting notes into
168+-- bracketed text and removing links.
169+prepForMeta :: [Inline] -> [Inline]
170+prepForMeta = bottomUp (concatMap fixInline)
171+ where fixInline (Note [Para xs]) = [Str " ["] ++ xs ++ [Str "]"]
172+ fixInline (Note [Plain xs]) = [Str " ["] ++ xs ++ [Str "]"]
173+ fixInline (Link lab _) = lab
174+ fixInline (Image lab _) = lab
175+ fixInline x = [x]
162176
163177inTemplate :: TemplateTarget a
164178 => WriterOptions
165179 -> Html
166180 -> [Html]
181+ -> [Html]
167182 -> Html
168183 -> Maybe Html
169184 -> Html
170185 -> [(String,String)]
171186 -> a
172−inTemplate opts tit auths date toc body' newvars =
187+inTemplate opts tit auths authsMeta date toc body' newvars =
173188 let title' = renderHtml tit
174− authors = map renderHtml auths
175189 date' = renderHtml date
176190 variables = writerVariables opts ++ newvars
177191 context = variables ++
@@ -187,8 +201,8 @@ inTemplate opts tit auths date toc body' newvars =
187201 (case toc of
188202 Just t -> [ ("toc", renderHtml t)]
189203 Nothing -> []) ++
190− [ ("author", a) | a <- authors ] ++
191− [ ("author-meta", stripTags a) | a <- authors ]
204+ [ ("author", renderHtml a) | a <- auths ] ++
205+ [ ("author-meta", stripTags $ renderHtml a) | a <- authsMeta ]
192206 in renderTemplate context $ writerTemplate opts
193207
194208-- | Like Text.XHtml's identifier, but adds the writerIdentifierPrefix