aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2013-10-17 13:23:38 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2013-10-17 13:23:38 -0700
commit6e1c24da8e9f4715e03fd1ff9ee64528936d8bf3 (patch)
treeda69f2bd0fafd7b6d7d1b2ce556da8bbdf66798c /src/Text
parent386e933432f5badf3149da1e6edaeb2e693bbb9b (diff)
downloadpandoc-6e1c24da8e9f4715e03fd1ff9ee64528936d8bf3.tar.gz
LaTeX writer: Add link anchors for code blocks with identifiers.
Closes #1025.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index dbfa57137..8f52b11ca 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -329,17 +329,23 @@ blockToLaTeX (CodeBlock (identifier,classes,keyvalAttr) str) = do
| writerListings opts -> listingsCodeBlock
| writerHighlight opts && not (null classes) -> highlightedCodeBlock
| otherwise -> rawCodeBlock
- where lhsCodeBlock = do
+ where ref = text identifier
+ linkAnchor = if null identifier
+ then empty
+ else "\\hyperdef{}" <> braces ref <>
+ braces ("\\label" <> braces ref)
+ lhsCodeBlock = do
modify $ \s -> s{ stLHS = True }
- return $ flush ("\\begin{code}" $$ text str $$ "\\end{code}") $$ cr
+ return $ flush (linkAnchor $$ "\\begin{code}" $$ text str $$
+ "\\end{code}") $$ cr
rawCodeBlock = do
st <- get
env <- if stInNote st
then modify (\s -> s{ stVerbInNote = True }) >>
return "Verbatim"
else return "verbatim"
- return $ flush (text ("\\begin{" ++ env ++ "}") $$ text str $$
- text ("\\end{" ++ env ++ "}")) <> cr
+ return $ flush (linkAnchor $$ text ("\\begin{" ++ env ++ "}") $$
+ text str $$ text ("\\end{" ++ env ++ "}")) <> cr
listingsCodeBlock = do
st <- get
let params = if writerListings (stOptions st)
@@ -367,7 +373,7 @@ blockToLaTeX (CodeBlock (identifier,classes,keyvalAttr) str) = do
case highlight formatLaTeXBlock ("",classes,keyvalAttr) str of
Nothing -> rawCodeBlock
Just h -> modify (\st -> st{ stHighlighting = True }) >>
- return (flush $ text h)
+ return (flush $ linkAnchor $$ text h)
blockToLaTeX (RawBlock f x)
| f == Format "latex" || f == Format "tex"
= return $ text x