git.iko.soy/typeable/pandoc
on master help sign in
Shared: Export uniqueIdent, don't allow tilde in identifier.
26b41cefiddlosopher
README+1−2
@@ -1044,8 +1044,7 @@ identifier. This identifier is based on the text of the header. To
1044derive the identifier from the header text,
1044derive the identifier from the header text,
1045
1045
1046 - Remove all formatting, links, etc.
1046 - Remove all formatting, links, etc.
1047− - Remove all punctuation, except underscores, hyphens, periods,
1047+ - Remove all punctuation, except underscores, hyphens, and periods.
1048− and tildes.
1049 - Replace all spaces and newlines with hyphens.
1048 - Replace all spaces and newlines with hyphens.
1050 - Convert all alphabetic characters to lowercase.
1049 - Convert all alphabetic characters to lowercase.
1051 - Remove everything up to the first letter (identifiers may
1050 - Remove everything up to the first letter (identifiers may
src/Text/Pandoc/Shared.hs+4−1
@@ -97,6 +97,7 @@ module Text.Pandoc.Shared (
97 compactify,
97 compactify,
98 Element (..),
98 Element (..),
99 hierarchicalize,
99 hierarchicalize,
100+ uniqueIdent,
100 isHeaderBlock,
101 isHeaderBlock,
101 -- * Writer options
102 -- * Writer options
102 HTMLMathMethod (..),
103 HTMLMathMethod (..),
@@ -902,7 +903,7 @@ inlineListToIdentifier' [] = ""
902inlineListToIdentifier' (x:xs) =
903inlineListToIdentifier' (x:xs) =
903 xAsText ++ inlineListToIdentifier' xs
904 xAsText ++ inlineListToIdentifier' xs
904 where xAsText = case x of
905 where xAsText = case x of
905− Str s -> filter (\c -> c `elem` "_-.~" || not (isPunctuation c)) $
906+ Str s -> filter (\c -> c `elem` "_-." || not (isPunctuation c)) $
906 intercalate "-" $ words $ map toLower s
907 intercalate "-" $ words $ map toLower s
907 Emph lst -> inlineListToIdentifier' lst
908 Emph lst -> inlineListToIdentifier' lst
908 Strikeout lst -> inlineListToIdentifier' lst
909 Strikeout lst -> inlineListToIdentifier' lst
@@ -952,6 +953,8 @@ headerLtEq :: Int -> Block -> Bool
952headerLtEq level (Header l _) = l <= level
953headerLtEq level (Header l _) = l <= level
953headerLtEq _ _ = False
954headerLtEq _ _ = False
954
955
956+-- | Generate a unique identifier from a list of inlines.
957+-- Second argument is a list of already used identifiers.
955uniqueIdent :: [Inline] -> [String] -> String
958uniqueIdent :: [Inline] -> [String] -> String
956uniqueIdent title' usedIdents =
959uniqueIdent title' usedIdents =
957 let baseIdent = inlineListToIdentifier title'
960 let baseIdent = inlineListToIdentifier title'