@@ -68,11 +68,13 @@ import qualified Text.Pandoc.Builder as B
6868import Text.Pandoc.Class (PandocMonad (..))
6969import Text.Pandoc.CSS (foldOrElse, pickStyleAttrProps)
7070import Text.Pandoc.Definition
71+import Text.Pandoc.Readers.LaTeX (rawLaTeXInline)
72+import Text.Pandoc.Readers.LaTeX.Types (Macro)
7173import Text.Pandoc.Error
7274import Text.Pandoc.Logging
7375import Text.Pandoc.Options (
7476 Extension (Ext_epub_html_exts, Ext_empty_paragraphs, Ext_native_divs,
75− Ext_native_spans, Ext_raw_html, Ext_line_blocks),
77+ Ext_native_spans, Ext_raw_html, Ext_line_blocks, Ext_raw_tex),
7678 ReaderOptions (readerExtensions, readerStripComments),
7779 extensionEnabled)
7880import Text.Pandoc.Parsing hiding ((<|>))
@@ -102,7 +104,8 @@ readHtml opts inp = do
102104 (m:_) -> messageString m
103105 result <- flip runReaderT def $
104106 runParserT parseDoc
105− (HTMLState def{ stateOptions = opts } [] Nothing Set.empty M.empty [])
107+ (HTMLState def{ stateOptions = opts }
108+ [] Nothing Set.empty M.empty [] M.empty)
106109 "source" tags
107110 case result of
108111 Right doc -> return doc
@@ -124,7 +127,8 @@ data HTMLState =
124127 baseHref :: Maybe URI,
125128 identifiers :: Set.Set String,
126129 headerMap :: M.Map Inlines String,
127− logMessages :: [LogMessage]
130+ logMessages :: [LogMessage],
131+ macros :: M.Map Text Macro
128132 }
129133
130134data HTMLLocal = HTMLLocal { quoteContext :: QuoteContext
@@ -907,9 +911,25 @@ pTagContents =
907911 <|> pStr
908912 <|> pSpace
909913 <|> smartPunctuation pTagContents
914+ <|> pRawTeX
910915 <|> pSymbol
911916 <|> pBad
912917
918+pRawTeX :: PandocMonad m => InlinesParser m Inlines
919+pRawTeX = do
920+ lookAhead $ try $ do
921+ char '\\'
922+ choice $ map (try . string) ["begin", "eqref", "ref"]
923+ guardEnabled Ext_raw_tex
924+ inp <- getInput
925+ st <- getState
926+ res <- lift $ runParserT (withRaw rawLaTeXInline) st "chunk" (T.unpack inp)
927+ case res of
928+ Left _ -> mzero
929+ Right (contents, raw) -> do
930+ _ <- count (length raw) anyChar
931+ return $ B.rawInline "tex" contents
932+
913933pStr :: PandocMonad m => InlinesParser m Inlines
914934pStr = do
915935 result <- many1 $ satisfy $ \c ->
@@ -923,6 +943,7 @@ isSpecial '\'' = True
923943isSpecial '.' = True
924944isSpecial '-' = True
925945isSpecial '$' = True
946+isSpecial '\\' = True
926947isSpecial '\8216' = True
927948isSpecial '\8217' = True
928949isSpecial '\8220' = True
@@ -1249,6 +1270,10 @@ isSpace _ = False
12491270
12501271-- Instances
12511272
1273+instance HasMacros HTMLState where
1274+ extractMacros = macros
1275+ updateMacros f st = st{ macros = f $ macros st }
1276+
12521277instance HasIdentifierList HTMLState where
12531278 extractIdentifierList = identifiers
12541279 updateIdentifierList f s = s{ identifiers = f (identifiers s) }