aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-03-12 12:42:03 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-03-12 12:42:03 +0100
commit0ef1e51211cd35b1ddb54a5fe8bee4247f1e1801 (patch)
tree4ea2f452be3b4c0b837bfeb530147ab3b2482973 /src
parentcf0a1b2034dc2ceced000f77d64c82b6e9d3f19e (diff)
downloadpandoc-0ef1e51211cd35b1ddb54a5fe8bee4247f1e1801.tar.gz
Shared: export extractIds.
This will be used to help with #1745.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Shared.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 3b9ae7501..95a53be72 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -64,6 +64,7 @@ module Text.Pandoc.Shared (
Element (..),
hierarchicalize,
uniqueIdent,
+ extractIds,
inlineListToIdentifier,
isHeaderBlock,
headerShift,
@@ -529,6 +530,25 @@ headerLtEq level (Header l _ _) = l <= level
headerLtEq level (Div ("",["references"],[]) (Header l _ _ : _)) = l <= level
headerLtEq _ _ = False
+-- | Extract the identifiers from a block element.
+extractBlockIds :: Block -> Set.Set String
+extractBlockIds (Header _ (ident,_,_) _) | not (null ident) =
+ Set.singleton ident
+extractBlockIds (Div (ident,_,_) _) | not (null ident) =
+ Set.singleton ident
+extractBlockIds _ = Set.empty
+
+-- | Extract the identifiers from an inline element.
+extractInlineIds :: Inline -> Set.Set String
+extractInlineIds (Span (ident,_,_) _) | not (null ident) =
+ Set.singleton ident
+extractInlineIds _ = Set.empty
+
+-- | Extract the identifiers from a pandoc document.
+extractIds :: Pandoc -> Set.Set String
+extractIds doc =
+ query extractBlockIds doc `Set.union` query extractInlineIds doc
+
-- | Generate a unique identifier from a list of inlines.
-- Second argument is a list of already used identifiers.
uniqueIdent :: [Inline] -> Set.Set String -> String