Created
August 2, 2012 16:36
-
-
Save benshimmin/3238456 to your computer and use it in GitHub Desktop.
How to extract all links and link text from a Markdown file using pandoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- adapted from <http://johnmacfarlane.net/pandoc/scripting.html> | |
import Text.Pandoc | |
import Text.Pandoc.Shared (stringify) | |
extractURL :: Inline -> [String] | |
extractURL (Link txt (u,_)) = [stringify txt ++ " : <" ++ u ++ ">"] | |
extractURL (Image _ (u,_)) = [u] | |
extractURL _ = [] | |
extractURLs :: Pandoc -> [String] | |
extractURLs = queryWith extractURL | |
readDoc :: String -> Pandoc | |
readDoc = readMarkdown defaultParserState | |
main :: IO () | |
main = interact (unlines . extractURLs . readDoc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment