diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-08-13 11:48:44 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-08-13 11:48:44 -0700 |
commit | f9656ece4ea1e106296bb3e140c46874df09955a (patch) | |
tree | 38331b3867070bb247596a3be7f10699e492d6eb /src | |
parent | 253a7c620136bcba1a0134898b6a8cf3dcf47eca (diff) | |
download | pandoc-f9656ece4ea1e106296bb3e140c46874df09955a.tar.gz |
Resolve references to section numbers in LaTeX reader.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index ffc44ded3..96e5adbc6 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -106,9 +106,23 @@ parseLaTeX = do -- handle the case where you have \part or \chapter (if bottomLevel < 1 then walk (adjustHeaders (1 - bottomLevel)) - else id) doc' + else id) $ + walk (resolveRefs (sLabels st)) $ doc' return $ Pandoc meta bs' +resolveRefs :: M.Map String [Inline] -> Inline -> Inline +resolveRefs labels x@(Span (ident,classes,kvs) _) = + case (lookup "reference-type" kvs, + lookup "reference" kvs) of + (Just "ref", Just lab) -> + case M.lookup lab labels of + Just txt -> Span (ident,classes,kvs) + [Link nullAttr txt ('#':lab, "")] + Nothing -> x + _ -> x +resolveRefs _ x = x + + -- testParser :: LP PandocIO a -> Text -> IO a -- testParser p t = do -- res <- runIOorExplode (runParserT p defaultLaTeXState{ @@ -145,7 +159,7 @@ data LaTeXState = LaTeXState{ sOptions :: ReaderOptions , sInListItem :: Bool , sInTableCell :: Bool , sLastHeaderNum :: HeaderNum - , sLabels :: M.Map String Inlines + , sLabels :: M.Map String [Inline] } deriving Show @@ -1720,7 +1734,7 @@ section starred (ident, classes, kvs) lvl = do let num = incrementHeaderNum lvl hn updateState $ \st -> st{ sLastHeaderNum = num } updateState $ \st -> st{ sLabels = M.insert lab - (str (renderHeaderNum num)) + [Str (renderHeaderNum num)] (sLabels st) } attr' <- registerHeader (lab, classes', kvs) contents return $ headerWith attr' lvl contents |