diff options
author | Gautier DI FOLCO <gautier.difolco@gmail.com> | 2021-01-17 01:15:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-16 16:15:33 -0800 |
commit | 6efd3460a776620fdb93812daa4f6831e6c332ce (patch) | |
tree | 0d6dfc64a0690efd03f9abfd6b8cf3004f5e19d1 /src/Text/Pandoc/Readers/Markdown.hs | |
parent | 83336a45a78b288dcc0104d2432135bdb3f5e8f1 (diff) | |
download | pandoc-6efd3460a776620fdb93812daa4f6831e6c332ce.tar.gz |
Markdown reader: support GitHub wiki's internal links (#2923) (#6458)
Canges overview:
* Add a `Ext_markdown_github_wikilink` constructor to `Extension` [API change].
* Add the parser `githubWikiLink` in `Text.Pandoc.Readers.Markdown`
* Add tests.
Diffstat (limited to 'src/Text/Pandoc/Readers/Markdown.hs')
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 5c3a21bb7..8fd0b68e2 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -21,6 +21,7 @@ module Text.Pandoc.Readers.Markdown ( import Control.Monad import Control.Monad.Except (throwError) import Data.Char (isAlphaNum, isPunctuation, isSpace) +import Data.Functor (($>)) import Data.List (transpose, elemIndex, sortOn) import qualified Data.Map as M import Data.Maybe @@ -1485,6 +1486,7 @@ inline = choice [ whitespace , note , cite , bracketedSpan + , githubWikiLink , link , image , math @@ -1780,6 +1782,29 @@ source = do linkTitle :: PandocMonad m => MarkdownParser m Text linkTitle = quotedTitle '"' <|> quotedTitle '\'' +-- Github wiki style link, with optional title +-- syntax documented under https://help.github.com/en/github/building-a-strong-community/editing-wiki-content +githubWikiLink :: PandocMonad m => MarkdownParser m (F Inlines) +githubWikiLink = try $ guardEnabled Ext_wikilinks >> wikilink + where + wikilink = try $ do + string "[[" + firstPart <- fmap mconcat . sequence <$> wikiText + (char '|' *> complexWikilink firstPart) + <|> (string "]]" $> (B.link + <$> (stringify <$> firstPart) + <*> return "wikilink" + <*> firstPart)) + + complexWikilink firstPart = do + url <- fmap stringify . sequence <$> wikiText + string "]]" + return $ B.link <$> url + <*> return "wikilink" + <*> firstPart + + wikiText = many (whitespace <|> bareURL <|> str <|> endline <|> escapedChar) + link :: PandocMonad m => MarkdownParser m (F Inlines) link = try $ do st <- getState |