Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit d95c4e5

Browse files
committed
Allow more characters in anchor following module reference
1 parent 8551fcd commit d95c4e5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

haddock-library/src/Documentation/Haddock/Parser.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,18 @@ monospace = DocMonospaced . parseParagraph
242242
-- Note that we allow '#' and '\' to support anchors (old style anchors are of
243243
-- the form "SomeModule\#anchor").
244244
moduleName :: Parser (DocH mod a)
245-
moduleName = DocModule <$> ("\"" *> modid <* "\"")
245+
moduleName = DocModule <$> ("\"" *> (modid `maybeFollowedBy` anchor_) <* "\"")
246246
where
247247
modid = intercalate "." <$> conid `Parsec.sepBy1` "."
248+
anchor_ = (++)
249+
<$> (Parsec.string "#" <|> Parsec.string "\\#")
250+
<*> many (Parsec.satisfy (\c -> c /= '"' && not (isSpace c)))
251+
252+
maybeFollowedBy pre suf = (\x -> maybe x (x ++)) <$> pre <*> optional suf
253+
248254
conid = (:)
249255
<$> Parsec.satisfy (\c -> isAlpha c && isUpper c)
250-
<*> many (conChar <|> Parsec.oneOf "\\#")
256+
<*> many conChar
251257

252258
conChar = Parsec.alphaNum <|> Parsec.char '_'
253259

haddock-library/test/Documentation/Haddock/ParserSpec.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ spec = do
431431
it "accepts anchor reference syntax as DocModule" $ do
432432
"\"Foo#bar\"" `shouldParseTo` DocModule "Foo#bar"
433433

434+
it "accepts anchor with hyphen as DocModule" $ do
435+
"\"Foo#bar-baz\"" `shouldParseTo` DocModule "Foo\\#bar-baz"
436+
434437
it "accepts old anchor reference syntax as DocModule" $ do
435438
"\"Foo\\#bar\"" `shouldParseTo` DocModule "Foo\\#bar"
436439

0 commit comments

Comments
 (0)