diff options
author | Albert Krewinkel <tarleb@moltkeplatz.de> | 2014-04-24 17:42:01 +0200 |
---|---|---|
committer | Albert Krewinkel <tarleb@moltkeplatz.de> | 2014-04-24 17:57:06 +0200 |
commit | 2f724aaaa4875a21560870d25c3d212f974c6dde (patch) | |
tree | 0c938aa4036739465ac2a824d9b7056f55c51003 /src/Text/Pandoc | |
parent | c128daba9dee096ce0e78b81a381f43337b74285 (diff) | |
download | pandoc-2f724aaaa4875a21560870d25c3d212f974c6dde.tar.gz |
Org reader: Read anchors as empty spans
Anchors (like <<this>>) are parsed as empty spans.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Readers/Org.hs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Readers/Org.hs b/src/Text/Pandoc/Readers/Org.hs index 7a50b1db9..7f1893936 100644 --- a/src/Text/Pandoc/Readers/Org.hs +++ b/src/Text/Pandoc/Readers/Org.hs @@ -740,6 +740,7 @@ inline = , linebreak , footnote , linkOrImage + , anchor , str , endline , emph @@ -886,6 +887,30 @@ isImageFilename filename = imageExtensions = [ "jpeg" , "jpg" , "png" , "gif" , "svg" ] protocols = [ "file", "http", "https" ] +-- | Parse an anchor like @<<anchor-id>>@ and return an empty span with +-- @anchor-id@ set as id. Legal anchors in org-mode are defined through +-- @org-target-regexp@, which is fairly liberal. Since no link is created if +-- @anchor-id@ contains spaces, we are more restrictive in what is accepted as +-- an anchor. + +anchor :: OrgParser (F Inlines) +anchor = try $ pure <$> (B.spanWith <$> attributes <*> pure mempty) + where + name = string "<<" + *> many1 (noneOf "\t\n\r<>\"' ") + <* string ">>" + attributes = name >>= \n -> return (solidify n, [], []) + +-- | Replace every char but [a-zA-Z0-9_.-:] with a hypen '-'. This mirrors +-- the org function @org-export-solidify-link-text@. + +solidify :: String -> String +solidify = map replaceSpecialChar + where replaceSpecialChar c + | isAlphaNum c = c + | c `elem` "_.-:" = c + | otherwise = '-' + emph :: OrgParser (F Inlines) emph = fmap B.emph <$> emphasisBetween '/' |