From 82e1c76fe7f08baceda8a4e8283892c8ce03c3b8 Mon Sep 17 00:00:00 2001 From: Igor Ranieri Date: Sun, 21 Sep 2025 21:20:35 +0200 Subject: [PATCH] Added anchors --- src/Lexer.hs | 19 +++++++++++++++++++ test/Spec.hs | 9 +++++++++ 2 files changed, 28 insertions(+) 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..0b61570 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -19,6 +19,7 @@ main = hspec $ do it "handles unicode" unicode it "escapes" escaping it "maths" maths + it "anchors" anchors it "space chars" space it "bare string" someString it "emphasis" emphatic @@ -81,6 +82,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\\]"