git.iko.soy/typeable/pandoc
on master help sign in
Shared: export extractIds.
0ef1e51John MacFarlane
src/Text/Pandoc/Shared.hs+20
@@ -64,6 +64,7 @@ module Text.Pandoc.Shared (
64 Element (..),
64 Element (..),
65 hierarchicalize,
65 hierarchicalize,
66 uniqueIdent,
66 uniqueIdent,
67+ extractIds,
67 inlineListToIdentifier,
68 inlineListToIdentifier,
68 isHeaderBlock,
69 isHeaderBlock,
69 headerShift,
70 headerShift,
@@ -529,6 +530,25 @@ headerLtEq level (Header l _ _) = l <= level
529headerLtEq level (Div ("",["references"],[]) (Header l _ _ : _)) = l <= level
530headerLtEq level (Div ("",["references"],[]) (Header l _ _ : _)) = l <= level
530headerLtEq _ _ = False
531headerLtEq _ _ = False
531
532
533+-- | Extract the identifiers from a block element.
534+extractBlockIds :: Block -> Set.Set String
535+extractBlockIds (Header _ (ident,_,_) _) | not (null ident) =
536+ Set.singleton ident
537+extractBlockIds (Div (ident,_,_) _) | not (null ident) =
538+ Set.singleton ident
539+extractBlockIds _ = Set.empty
540+
541+-- | Extract the identifiers from an inline element.
542+extractInlineIds :: Inline -> Set.Set String
543+extractInlineIds (Span (ident,_,_) _) | not (null ident) =
544+ Set.singleton ident
545+extractInlineIds _ = Set.empty
546+
547+-- | Extract the identifiers from a pandoc document.
548+extractIds :: Pandoc -> Set.Set String
549+extractIds doc =
550+ query extractBlockIds doc `Set.union` query extractInlineIds doc
551+
532-- | Generate a unique identifier from a list of inlines.
552-- | Generate a unique identifier from a list of inlines.
533-- Second argument is a list of already used identifiers.
553-- Second argument is a list of already used identifiers.
534uniqueIdent :: [Inline] -> Set.Set String -> String
554uniqueIdent :: [Inline] -> Set.Set String -> String