@@ -740,6 +740,7 @@ inline =
740 , linebreak
740 , linebreak
741 , footnote
741 , footnote
742 , linkOrImage
742 , linkOrImage
744 , endline
745 , endline
@@ -886,6 +887,30 @@ isImageFilename filename =
886 imageExtensions = [ "jpeg" , "jpg" , "png" , "gif" , "svg" ]
887 imageExtensions = [ "jpeg" , "jpg" , "png" , "gif" , "svg" ]
887 protocols = [ "file", "http", "https" ]
888 protocols = [ "file", "http", "https" ]
890+-- | Parse an anchor like @<<anchor-id>>@ and return an empty span with
891+-- @anchor-id@ set as id. Legal anchors in org-mode are defined through
892+-- @org-target-regexp@, which is fairly liberal. Since no link is created if
893+-- @anchor-id@ contains spaces, we are more restrictive in what is accepted as
896+anchor :: OrgParser (F Inlines)
897+anchor = try $ pure <$> (B.spanWith <$> attributes <*> pure mempty)
900+ *> many1 (noneOf "\t\n\r<>\"' ")
902+ attributes = name >>= \n -> return (solidify n, [], [])
904+-- | Replace every char but [a-zA-Z0-9_.-:] with a hypen '-'. This mirrors
905+-- the org function @org-export-solidify-link-text@.
907+solidify :: String -> String
908+solidify = map replaceSpecialChar
909+ where replaceSpecialChar c
911+ | c `elem` "_.-:" = c
889emph :: OrgParser (F Inlines)
914emph :: OrgParser (F Inlines)
890emph = fmap B.emph <$> emphasisBetween '/'
915emph = fmap B.emph <$> emphasisBetween '/'