diff options
| author | Albert Krewinkel <albert@zeitkraut.de> | 2014-11-05 22:49:17 +0100 |
|---|---|---|
| committer | Albert Krewinkel <albert@zeitkraut.de> | 2014-11-05 23:15:28 +0100 |
| commit | e6cd8c907788c083adea5e00def8918b11553f2b (patch) | |
| tree | 0f7514217a0192e5eae593cabfd3bc91e8471c1f | |
| parent | daaf635806fba3ec459da3c2c97301920cea1270 (diff) | |
| download | pandoc-e6cd8c907788c083adea5e00def8918b11553f2b.tar.gz | |
Org reader: allow empty links for gitit interop
While empty links are not allowed in Emacs org-mode, Pandoc org-mode
should support them: gitit relies on empty links as they are used to
create wiki links.
Fixes jgm/gitit#471
| -rw-r--r-- | src/Text/Pandoc/Readers/Org.hs | 6 | ||||
| -rw-r--r-- | tests/Tests/Readers/Org.hs | 4 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/Org.hs b/src/Text/Pandoc/Readers/Org.hs index 2f149765e..4c34b7bd5 100644 --- a/src/Text/Pandoc/Readers/Org.hs +++ b/src/Text/Pandoc/Readers/Org.hs @@ -1099,7 +1099,7 @@ linkOrImage = explicitOrImageLink explicitOrImageLink :: OrgParser (F Inlines) explicitOrImageLink = try $ do char '[' - srcF <- applyCustomLinkFormat =<< linkTarget + srcF <- applyCustomLinkFormat =<< possiblyEmptyLinkTarget title <- enclosedRaw (char '[') (char ']') title' <- parseFromString (mconcat <$> many inline) title char ']' @@ -1132,6 +1132,9 @@ selfTarget = try $ char '[' *> linkTarget <* char ']' linkTarget :: OrgParser String linkTarget = enclosedByPair '[' ']' (noneOf "\n\r[]") +possiblyEmptyLinkTarget :: OrgParser String +possiblyEmptyLinkTarget = try linkTarget <|> ("" <$ string "[]") + applyCustomLinkFormat :: String -> OrgParser (F String) applyCustomLinkFormat link = do let (linkType, rest) = break (== ':') link @@ -1142,6 +1145,7 @@ applyCustomLinkFormat link = do linkToInlinesF :: String -> Inlines -> F Inlines linkToInlinesF s = case s of + "" -> pure . B.link "" "" ('#':_) -> pure . B.link s "" _ | isImageFilename s -> const . pure $ B.image s "" "" _ | isUri s -> pure . B.link s "" diff --git a/tests/Tests/Readers/Org.hs b/tests/Tests/Readers/Org.hs index fd337f760..e59080bae 100644 --- a/tests/Tests/Readers/Org.hs +++ b/tests/Tests/Readers/Org.hs @@ -205,6 +205,10 @@ tests = "[[../file.txt][moin]]" =?> (para $ link "../file.txt" "" "moin") + , "Empty link (for gitit interop)" =: + "[[][New Link]]" =?> + (para $ link "" "" "New Link") + , "Image link" =: "[[sunset.png][dusk.svg]]" =?> (para $ link "sunset.png" "" (image "dusk.svg" "" "")) |
