git.iko.soy/typeable/pandoc
on master help sign in
Fix definition lists with internal links in terms (closes #1032).

This fix puts braces around a term that contains an internal link, to avoid problems with square brackets.

commite63aafd62004e3424da46de75c78ba4dc7562af4 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 21 Oct 2013, 17:33 (13 years ago) parentd84624f
2 files changed+13−1
src/Text/Pandoc/Writers/LaTeX.hs+8−1 tests/Tests/Writers/LaTeX.hs+5
src/Text/Pandoc/Writers/LaTeX.hs+8−1
@@ -513,8 +513,15 @@ listItemToLaTeX lst = blockListToLaTeX lst >>= return . (text "\\item" $$) .
513513defListItemToLaTeX :: ([Inline], [[Block]]) -> State WriterState Doc
514514defListItemToLaTeX (term, defs) = do
515515 term' <- inlineListToLaTeX term
516+ -- put braces around term if it contains an internal link,
517+ -- since otherwise we get bad bracket interactions: \item[\hyperref[..]
518+ let isInternalLink (Link _ ('#':_,_)) = True
519+ isInternalLink _ = False
520+ let term'' = if any isInternalLink term
521+ then braces term'
522+ else term'
516523 def' <- liftM vsep $ mapM blockListToLaTeX defs
517− return $ "\\item" <> brackets term' $$ def'
524+ return $ "\\item" <> brackets term'' $$ def'
518525
519526-- | Craft the section header, inserting the secton reference, if supplied.
520527sectionHeader :: Bool -- True for unnumbered
tests/Tests/Writers/LaTeX.hs+5
@@ -39,6 +39,11 @@ tests = [ testGroup "code blocks"
3939 , test latexListing "no identifier" $ codeBlock "hi" =?>
4040 ("\\begin{lstlisting}\nhi\n\\end{lstlisting}" :: String)
4141 ]
42+ , testGroup "definition lists"
43+ [ "with internal link" =: definitionList [(link "#go" "" (str "testing"),
44+ [plain (text "hi there")])] =?>
45+ "\\begin{description}\n\\itemsep1pt\\parskip0pt\\parsep0pt\n\\item[{\\hyperref[go]{testing}}]\nhi there\n\\end{description}"
46+ ]
4247 , testGroup "math"
4348 [ "escape |" =: para (math "\\sigma|_{\\{x\\}}") =?>
4449 "$\\sigma|_{\\{x\\}}$"