diff --git a/src/Lexer.hs b/src/Lexer.hs index f17592b..c299d41 100644 --- a/src/Lexer.hs +++ b/src/Lexer.hs @@ -83,6 +83,7 @@ lexText = go , link , labeledLink , modules + , anchors , textElement , quotes , birdTrack @@ -161,6 +162,24 @@ header5 = delimitedMaybe (void $ "===== ") eol (Header Five) Nothing header6 :: Lexer header6 = delimitedMaybe (void $ "====== ") eol (Header Six) Nothing +-- #anchors# +anchors :: Lexer +anchors = do + pos <- getPosition + void $ try anchor' + pos' <- getPosition + txt <- anyUntil anchor' + pos'' <- getPosition + void $ try anchor' + + pure + [ (pos, Anchor) + , (pos', Token txt) + , (pos'', Anchor) + ] + where + anchor' = (string "#" <|> string "\\#") + -- "Module.Name" -- "Module.Name#anchor" -- "Module.Name#anchor" diff --git a/test/Spec.hs b/test/Spec.hs index cdbaf6e..724a5aa 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -81,6 +81,14 @@ labeledLink = , (1, 35, LabeledLinkClose) ] +anchors :: Expectation +anchors = + "#myAnchor#" + `shouldLexTo` [ (1, 1, Anchor) + , (1, 2, Token "myAnchor") + , (1, 10, Anchor) + ] + maths :: IO () maths = do "\\[some math\\]"