git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: use numerical labels for refs...
8c8d3baJohn MacFarlane
src/Text/Pandoc/Writers/Markdown.hs+9−5
@@ -47,6 +47,7 @@ import Text.Pandoc.Walk
47import Text.Pandoc.Writers.HTML (writeHtml5String)
47import Text.Pandoc.Writers.HTML (writeHtml5String)
48import Text.Pandoc.Writers.Math (texMathToInlines)
48import Text.Pandoc.Writers.Math (texMathToInlines)
49import Text.Pandoc.XML (toHtml5Entities)
49import Text.Pandoc.XML (toHtml5Entities)
50+import Data.Coerce (coerce)
50
51
51type Notes = [[Block]]
52type Notes = [[Block]]
52type Ref = (Text, Target, Attr)
53type Ref = (Text, Target, Attr)
@@ -903,6 +904,7 @@ getNextIndex = do
903 prevRefs <- gets stPrevRefs
904 prevRefs <- gets stPrevRefs
904 refs <- gets stRefs
905 refs <- gets stRefs
905 i <- (+ 1) <$> gets stLastIdx
906 i <- (+ 1) <$> gets stLastIdx
907+ modify $ \s -> s{ stLastIdx = i }
906 let refLbls = map (\(r,_,_) -> r) $ prevRefs ++ refs
908 let refLbls = map (\(r,_,_) -> r) $ prevRefs ++ refs
907 return $ findUsableIndex refLbls i
909 return $ findUsableIndex refLbls i
908
910
@@ -915,12 +917,15 @@ getReference attr label target = do
915 Just (ref, _, _) -> return ref
917 Just (ref, _, _) -> return ref
916 Nothing -> do
918 Nothing -> do
917 keys <- gets stKeys
919 keys <- gets stKeys
920+ let key = getKey label
921+ let rawkey = coerce key
918− case M.lookup (getKey label) keys of
922+ case M.lookup key keys of
919 Nothing -> do -- no other refs with this label
923 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
921 then do
927 then do
922 i <- getNextIndex
928 i <- getNextIndex
923− modify $ \s -> s{ stLastIdx = i }
924 return (tshow i, i)
929 return (tshow i, i)
925 else
930 else
926 return (render Nothing label, 0)
931 return (render Nothing label, 0)
@@ -947,11 +952,10 @@ getReference attr label target = do
947 return lab'
952 return lab'
948 Nothing -> do -- but this one is to a new target
953 Nothing -> do -- but this one is to a new target
949 i <- getNextIndex
954 i <- getNextIndex
950− modify $ \s -> s{ stLastIdx = i }
951 let lab' = tshow i
955 let lab' = tshow i
952 modify (\s -> s{
956 modify (\s -> s{
953 stRefs = (lab', target, attr) : refs,
957 stRefs = (lab', target, attr) : refs,
954− stKeys = M.insert (getKey label)
958+ stKeys = M.insert key
955 (M.insert (target, attr) i km)
959 (M.insert (target, attr) i km)
956 (stKeys s) })
960 (stKeys s) })
957 return lab'
961 return lab'