@@ -35,6 +35,7 @@ module Text.Pandoc.Shared (
3535 splitByIndices,
3636 splitStringByIndices,
3737 substitute,
38+ ordNub,
3839 -- * Text processing
3940 backslashEscapes,
4041 escapeStringUsing,
@@ -94,6 +95,7 @@ import Data.List ( find, isPrefixOf, intercalate )
9495import qualified Data.Map as M
9596import Network.URI ( escapeURIString, isURI, nonStrictRelativeTo,
9697 unEscapeString, parseURIReference )
98+import qualified Data.Set as Set
9799import System.Directory
98100import Text.Pandoc.MIME (getMimeType)
99101import System.FilePath ( (</>), takeExtension, dropExtension )
@@ -174,6 +176,13 @@ substitute target replacement lst@(x:xs) =
174176 then replacement ++ substitute target replacement (drop (length target) lst)
175177 else x : substitute target replacement xs
176178
179+ordNub :: (Ord a) => [a] -> [a]
180+ordNub l = go Set.empty l
181+ where
182+ go _ [] = []
183+ go s (x:xs) = if x `Set.member` s then go s xs
184+ else x : go (Set.insert x s) xs
185+
177186--
178187-- Text processing
179188--