From 1b3431a165309aad3a28a0e8a75755c299561280 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 25 Aug 2017 22:04:57 -0700 Subject: LaTeX reader: improved support for \hyperlink, \hypertarget. Closes #2549. --- src/Text/Pandoc/Readers/LaTeX.hs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index ac471bdb1..06e112cef 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -1391,11 +1391,8 @@ inlineCommands = M.fromList $ <|> citation "citeauthor" AuthorInText False) , ("nocite", mempty <$ (citation "nocite" NormalCitation False >>= addMeta "nocite")) - -- hyperlink: for now, we just preserve contents. - -- we might add the actual links, but we need to avoid clashes - -- with ids produced by label. - , ("hypertarget", braced >> tok) - , ("hyperlink", braced >> tok) + , ("hyperlink", hyperlink) + , ("hypertarget", hypertargetInline) -- glossaries package , ("gls", doAcronym "short") , ("Gls", doAcronym "short") @@ -1450,6 +1447,26 @@ inlineCommands = M.fromList $ , ("Rn", romanNumeralLower) ] +hyperlink :: PandocMonad m => LP m Inlines +hyperlink = try $ do + src <- toksToString <$> braced + lab <- tok + return $ link ('#':src) "" lab + +hypertargetBlock :: PandocMonad m => LP m Blocks +hypertargetBlock = try $ do + ref <- toksToString <$> braced + bs <- grouped block + case toList bs of + [Header 1 (ident,_,_) _] | ident == ref -> return bs + _ -> return $ divWith (ref, [], []) bs + +hypertargetInline :: PandocMonad m => LP m Inlines +hypertargetInline = try $ do + ref <- toksToString <$> braced + ils <- grouped inline + return $ spanWith (ref, [], []) ils + romanNumeralUpper :: (PandocMonad m) => LP m Inlines romanNumeralUpper = str . toRomanNumeral <$> romanNumeralArg @@ -1972,7 +1989,7 @@ blockCommands = M.fromList $ , ("setdefaultlanguage", setDefaultLanguage) , ("setmainlanguage", setDefaultLanguage) -- hyperlink - , ("hypertarget", try $ braced >> grouped block) + , ("hypertarget", hypertargetBlock) -- LaTeX colors , ("textcolor", coloredBlock "color") , ("colorbox", coloredBlock "background-color") -- cgit v1.2.3