Skip to content

Commit

Permalink
Handle and ignore anchors in wiki-links
Browse files Browse the repository at this point in the history
Resolves #168
  • Loading branch information
srid committed Oct 10, 2021
1 parent 0ae24b4 commit 069dcc7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion emanote.cabal
Original file line number Diff line number Diff line change
@@ -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: [email protected]
Expand Down
27 changes: 19 additions & 8 deletions src/Emanote/Pandoc/Markdown/Syntax/WikiLink.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 069dcc7

Please sign in to comment.