@@ -47,6 +47,7 @@ import Text.Pandoc.Walk
4747import Text.Pandoc.Writers.HTML (writeHtml5String)
4848import Text.Pandoc.Writers.Math (texMathToInlines)
4949import Text.Pandoc.XML (toHtml5Entities)
50+import Data.Coerce (coerce)
5051
5152type Notes = [[Block]]
5253type Ref = (Text, Target, Attr)
@@ -903,6 +904,7 @@ getNextIndex = do
903904 prevRefs <- gets stPrevRefs
904905 refs <- gets stRefs
905906 i <- (+ 1) <$> gets stLastIdx
907+ modify $ \s -> s{ stLastIdx = i }
906908 let refLbls = map (\(r,_,_) -> r) $ prevRefs ++ refs
907909 return $ findUsableIndex refLbls i
908910
@@ -915,12 +917,15 @@ getReference attr label target = do
915917 Just (ref, _, _) -> return ref
916918 Nothing -> do
917919 keys <- gets stKeys
918− case M.lookup (getKey label) keys of
920+ let key = getKey label
921+ let rawkey = coerce key
922+ case M.lookup key keys of
919923 Nothing -> do -- no other refs with this label
920− (lab', idx) <- if isEmpty label
924+ (lab', idx) <- if T.null rawkey ||
925+ T.length rawkey > 999 ||
926+ T.any (\c -> c == '[' || c == ']') rawkey
921927 then do
922928 i <- getNextIndex
923− modify $ \s -> s{ stLastIdx = i }
924929 return (tshow i, i)
925930 else
926931 return (render Nothing label, 0)
@@ -947,11 +952,10 @@ getReference attr label target = do
947952 return lab'
948953 Nothing -> do -- but this one is to a new target
949954 i <- getNextIndex
950− modify $ \s -> s{ stLastIdx = i }
951955 let lab' = tshow i
952956 modify (\s -> s{
953957 stRefs = (lab', target, attr) : refs,
954− stKeys = M.insert (getKey label)
958+ stKeys = M.insert key
955959 (M.insert (target, attr) i km)
956960 (stKeys s) })
957961 return lab'