diff options
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 |