mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-26 09:25:48 +00:00
LaTeX writer: Fixed strikeout + highlighted code. Closes #1294.
Previously strikeout highlighted code caused an error.
This commit is contained in:
@@ -678,7 +678,9 @@ inlineToLaTeX (Emph lst) =
|
||||
inlineToLaTeX (Strong lst) =
|
||||
inlineListToLaTeX lst >>= return . inCmd "textbf"
|
||||
inlineToLaTeX (Strikeout lst) = do
|
||||
contents <- inlineListToLaTeX lst
|
||||
-- we need to protect VERB in an mbox or we get an error
|
||||
-- see #1294
|
||||
contents <- inlineListToLaTeX $ protectCode lst
|
||||
modify $ \s -> s{ stStrikeout = True }
|
||||
return $ inCmd "sout" contents
|
||||
inlineToLaTeX (Superscript lst) =
|
||||
@@ -784,6 +786,13 @@ inlineToLaTeX (Note contents) = do
|
||||
-- note: a \n before } needed when note ends with a Verbatim environment
|
||||
else "\\footnote" <> braces noteContents
|
||||
|
||||
protectCode :: [Inline] -> [Inline]
|
||||
protectCode [] = []
|
||||
protectCode (x@(Code ("",[],[]) _) : xs) = x : protectCode xs
|
||||
protectCode (x@(Code _ _) : xs) = ltx "\\mbox{" : x : ltx "}" : xs
|
||||
where ltx = RawInline (Format "latex")
|
||||
protectCode (x : xs) = x : protectCode xs
|
||||
|
||||
citationsToNatbib :: [Citation] -> State WriterState Doc
|
||||
citationsToNatbib (one:[])
|
||||
= citeCommand c p s k
|
||||
|
||||
@@ -8,7 +8,7 @@ import Tests.Helpers
|
||||
import Tests.Arbitrary()
|
||||
|
||||
latex :: (ToString a, ToPandoc a) => a -> String
|
||||
latex = writeLaTeX def . toPandoc
|
||||
latex = writeLaTeX def{ writerHighlight = True } . toPandoc
|
||||
|
||||
latexListing :: (ToString a, ToPandoc a) => a -> String
|
||||
latexListing = writeLaTeX def{ writerListings = True } . toPandoc
|
||||
@@ -54,4 +54,14 @@ tests = [ testGroup "code blocks"
|
||||
(text "Header 1" <> note (plain $ text "note")) =?>
|
||||
"\\section*{Header 1\\footnote{note}}\\label{foo}\n\\addcontentsline{toc}{section}{Header 1}\n"
|
||||
]
|
||||
, testGroup "inline code"
|
||||
[ "struck out and highlighted" =:
|
||||
strikeout (codeWith ("",["haskell"],[]) "foo" <> space
|
||||
<> str "bar") =?>
|
||||
"\\sout{\\mbox{\\VERB|\\NormalTok{foo}|} bar}"
|
||||
, "struck out and not highlighted" =:
|
||||
strikeout (code "foo" <> space
|
||||
<> str "bar") =?>
|
||||
"\\sout{\\texttt{foo} bar}"
|
||||
]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user