@@ -50,6 +50,7 @@ import Text.Pandoc.Options (ReaderOptions(readerParseRaw, readerTrace)
5050 Ext_native_divs, Ext_native_spans))
5151import Text.Pandoc.Parsing hiding ((<|>))
5252import Text.Pandoc.Walk
53+import qualified Data.Map as M
5354import Data.Maybe ( fromMaybe, isJust)
5455import Data.List ( intercalate, isInfixOf, isPrefixOf, isSuffixOf )
5556import Data.Char ( isDigit )
@@ -75,8 +76,9 @@ readHtml :: ReaderOptions -- ^ Reader options
7576 -> Either PandocError Pandoc
7677readHtml opts inp =
7778 mapLeft (ParseFailure . getError) . flip runReader def $
78− runParserT parseDoc (HTMLState def{ stateOptions = opts } [] Nothing)
79− "source" tags
79+ runParserT parseDoc
80+ (HTMLState def{ stateOptions = opts } [] Nothing [] M.empty)
81+ "source" tags
8082 where tags = stripPrefixes . canonicalizeTags $
8183 parseTagsOptions parseOptions{ optTagPosition = True } inp
8284 parseDoc = do
@@ -101,7 +103,9 @@ data HTMLState =
101103 HTMLState
102104 { parserState :: ParserState,
103105 noteTable :: [(String, Blocks)],
104− baseHref :: Maybe String
106+ baseHref :: Maybe String,
107+ identifiers :: [String],
108+ headerMap :: M.Map Inlines String
105109 }
106110
107111data HTMLLocal = HTMLLocal { quoteContext :: QuoteContext
@@ -398,9 +402,10 @@ pHeader = try $ do
398402 let ident = fromMaybe "" $ lookup "id" attr
399403 let classes = maybe [] words $ lookup "class" attr
400404 let keyvals = [(k,v) | (k,v) <- attr, k /= "class", k /= "id"]
405+ attr' <- registerHeader (ident, classes, keyvals) contents
401406 return $ if bodyTitle
402407 then mempty -- skip a representation of the title in the body
403− else B.headerWith (ident, classes, keyvals) level contents
408+ else B.headerWith attr' level contents
404409
405410pHrule :: TagParser Blocks
406411pHrule = do
@@ -983,6 +988,14 @@ isSpace _ = False
983988
984989-- Instances
985990
991+instance HasIdentifierList HTMLState where
992+ extractIdentifierList = identifiers
993+ updateIdentifierList f s = s{ identifiers = f (identifiers s) }
994+
995+instance HasHeaderMap HTMLState where
996+ extractHeaderMap = headerMap
997+ updateHeaderMap f s = s{ headerMap = f (headerMap s) }
998+
986999-- This signature should be more general
9871000-- MonadReader HTMLLocal m => HasQuoteContext st m
9881001instance HasQuoteContext st (Reader HTMLLocal) where
@@ -992,9 +1005,6 @@ instance HasQuoteContext st (Reader HTMLLocal) where
9921005instance HasReaderOptions HTMLState where
9931006 extractReaderOptions = extractReaderOptions . parserState
9941007
995−instance Default HTMLState where
996− def = HTMLState def [] Nothing
997−
9981008instance HasMeta HTMLState where
9991009 setMeta s b st = st {parserState = setMeta s b $ parserState st}
10001010 deleteMeta s st = st {parserState = deleteMeta s $ parserState st}