diff --git a/emanote.cabal b/emanote.cabal index e13e577dd..2acb58c6e 100644 --- a/emanote.cabal +++ b/emanote.cabal @@ -1,6 +1,6 @@ cabal-version: 2.4 name: emanote -version: 0.3.7.0 +version: 0.3.8.0 license: AGPL-3.0-only copyright: 2021 Sridhar Ratnakumar maintainer: srid@srid.ca diff --git a/src/Emanote/Pandoc/Markdown/Syntax/WikiLink.hs b/src/Emanote/Pandoc/Markdown/Syntax/WikiLink.hs index 5b85a18a9..48a448845 100644 --- a/src/Emanote/Pandoc/Markdown/Syntax/WikiLink.hs +++ b/src/Emanote/Pandoc/Markdown/Syntax/WikiLink.hs @@ -195,20 +195,31 @@ wikilinkSpec = replicateM_ 2 $ CT.symbol '[' P.notFollowedBy (CT.symbol '[') url <- - CM.untokenize - <$> many - ( CT.satisfyTok - ( \t -> - not (CT.hasType (CM.Symbol '|') t || CT.hasType (CM.Symbol ']') t) - ) - ) + CM.untokenize <$> many (satisfyNoneOf [isPipe, isAnchor, isClose]) wl <- mkWikiLinkFromUrl url + -- We ignore the anchor until https://github.com/srid/emanote/discussions/105 + _anchor <- + M.optional $ + CM.untokenize + <$> ( CT.symbol '#' + *> many (satisfyNoneOf [isPipe, isClose]) + ) title <- M.optional $ -- TODO: Should parse as inline so link text can be formatted? CM.untokenize <$> ( CT.symbol '|' - *> many (CT.satisfyTok (not . CT.hasType (CM.Symbol ']'))) + *> many (satisfyNoneOf [isClose]) ) replicateM_ 2 $ CT.symbol ']' return $ wikilink typ wl (fmap CM.str title) + satisfyNoneOf toks = + CT.satisfyTok $ \t -> not $ or $ toks <&> \tok -> tok t + isAnchor = + isSymbol '#' + isPipe = + isSymbol '|' + isClose = + isSymbol ']' + isSymbol c = + CT.hasType (CM.Symbol c)