git.iko.soy/typeable/pandoc
on master help sign in
Org reader: Read anchors as empty spans

Anchors (like <<this>>) are parsed as empty spans.

commit2f724aaaa4875a21560870d25c3d212f974c6dde authorAlbert Krewinkel <tarleb@moltkeplatz.de> dateThu 24 Apr 2014, 17:42 (13 years ago) parentc128dab
1 file changed+25
src/Text/Pandoc/Readers/Org.hs+25
src/Text/Pandoc/Readers/Org.hs+25
@@ -740,6 +740,7 @@ inline =
740740 , linebreak
741741 , footnote
742742 , linkOrImage
743+ , anchor
743744 , str
744745 , endline
745746 , emph
@@ -886,6 +887,30 @@ isImageFilename filename =
886887 imageExtensions = [ "jpeg" , "jpg" , "png" , "gif" , "svg" ]
887888 protocols = [ "file", "http", "https" ]
888889
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
894+-- an anchor.
895+
896+anchor :: OrgParser (F Inlines)
897+anchor = try $ pure <$> (B.spanWith <$> attributes <*> pure mempty)
898+ where
899+ name = string "<<"
900+ *> many1 (noneOf "\t\n\r<>\"' ")
901+ <* string ">>"
902+ attributes = name >>= \n -> return (solidify n, [], [])
903+
904+-- | Replace every char but [a-zA-Z0-9_.-:] with a hypen '-'. This mirrors
905+-- the org function @org-export-solidify-link-text@.
906+
907+solidify :: String -> String
908+solidify = map replaceSpecialChar
909+ where replaceSpecialChar c
910+ | isAlphaNum c = c
911+ | c `elem` "_.-:" = c
912+ | otherwise = '-'
913+
889914emph :: OrgParser (F Inlines)
890915emph = fmap B.emph <$> emphasisBetween '/'
891916