forked from elland/haddock2
Embed Anchor content inside token
This commit is contained in:
parent
82e1c76fe7
commit
8887476626
3 changed files with 311 additions and 313 deletions
15
src/Lexer.hs
15
src/Lexer.hs
|
|
@ -31,7 +31,7 @@ data Level
|
|||
|
||||
data Token
|
||||
= Token Text
|
||||
| Anchor
|
||||
| Anchor Text
|
||||
| BirdTrack
|
||||
| BoldOpen
|
||||
| BoldClose
|
||||
|
|
@ -54,6 +54,7 @@ data Token
|
|||
| MathsParenClose
|
||||
| MathsBracketOpen
|
||||
| MathsBracketClose
|
||||
| NumericEntity Int
|
||||
| Module
|
||||
| QuoteOpen
|
||||
| QuoteClose
|
||||
|
|
@ -167,22 +168,15 @@ 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)
|
||||
]
|
||||
pure [(pos, Anchor txt)]
|
||||
where
|
||||
anchor' = (string "#" <|> string "\\#")
|
||||
|
||||
-- "Module.Name"
|
||||
-- "Module.Name#anchor"
|
||||
-- "Module.Name#anchor"
|
||||
modules :: Lexer
|
||||
modules = do
|
||||
pos <- getPosition
|
||||
|
|
@ -192,9 +186,8 @@ modules = do
|
|||
anch <- option [] do
|
||||
pos'' <- getPosition
|
||||
void $ try (string "#" <|> string "\\#")
|
||||
pos''' <- getPosition
|
||||
a <- Text.pack <$> many (satisfy (\c -> c /= '"' && not (isSpace c)))
|
||||
pure [(pos'', Anchor), (pos''', Token a)]
|
||||
pure [(pos'', Anchor a)]
|
||||
|
||||
void $ char '"'
|
||||
pure $ [(pos, Module), (pos', Token modName)] <> anch
|
||||
|
|
|
|||
|
|
@ -51,8 +51,7 @@ modules = do
|
|||
"\"OtherModule.Name#myAnchor\""
|
||||
`shouldLexTo` [ (1, 1, Module)
|
||||
, (1, 2, Token "OtherModule.Name")
|
||||
, (1, 18, Anchor)
|
||||
, (1, 19, Token "myAnchor")
|
||||
, (1, 18, Anchor "myAnchor")
|
||||
]
|
||||
|
||||
link :: Expectation
|
||||
|
|
@ -85,9 +84,7 @@ labeledLink =
|
|||
anchors :: Expectation
|
||||
anchors =
|
||||
"#myAnchor#"
|
||||
`shouldLexTo` [ (1, 1, Anchor)
|
||||
, (1, 2, Token "myAnchor")
|
||||
, (1, 10, Anchor)
|
||||
`shouldLexTo` [ (1, 1, Anchor "myAnchor")
|
||||
]
|
||||
|
||||
maths :: IO ()
|
||||
|
|
|
|||
|
|
@ -27,8 +27,16 @@ ftp\://example.com
|
|||
|
||||

|
||||
|
||||
\(mathematical expression\)
|
||||
\[mathematical expression\]
|
||||
\(mathematical 1+3 expression\)
|
||||
|
||||
\[mathematical
|
||||
expression
|
||||
accross lines with + addition and such
|
||||
\]
|
||||
|
||||
{
|
||||
e
|
||||
¥
|
||||
|
||||
@
|
||||
code block content
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue