Muse reader: parse anchors
This commit is contained in:
parent
e38c023007
commit
b5d064e8f0
2 changed files with 31 additions and 1 deletions
|
@ -35,7 +35,6 @@ TODO:
|
|||
- Org tables
|
||||
- table.el tables
|
||||
- Images with attributes (floating and width)
|
||||
- Anchors
|
||||
- Citations and <biblio>
|
||||
- <play> environment
|
||||
-}
|
||||
|
@ -535,6 +534,7 @@ tableParseCaption = try $ do
|
|||
|
||||
inline :: PandocMonad m => MuseParser m (F Inlines)
|
||||
inline = choice [ br
|
||||
, anchor
|
||||
, footnote
|
||||
, strong
|
||||
, strongTag
|
||||
|
@ -552,6 +552,16 @@ inline = choice [ br
|
|||
, symbol
|
||||
] <?> "inline"
|
||||
|
||||
anchor :: PandocMonad m => MuseParser m (F Inlines)
|
||||
anchor = try $ do
|
||||
getPosition >>= \pos -> guard (sourceColumn pos == 1)
|
||||
char '#'
|
||||
first <- letter
|
||||
rest <- many (letter <|> digit)
|
||||
skipMany spaceChar <|> void newline
|
||||
let anchorId = first:rest
|
||||
return $ return $ B.spanWith (anchorId, [], []) mempty
|
||||
|
||||
footnote :: PandocMonad m => MuseParser m (F Inlines)
|
||||
footnote = try $ do
|
||||
ref <- noteMarker
|
||||
|
|
|
@ -344,6 +344,26 @@ tests =
|
|||
] =?>
|
||||
blockQuote (para "* Hi")
|
||||
]
|
||||
, testGroup "Anchors"
|
||||
[ "Anchor" =:
|
||||
T.unlines [ "; A comment to make sure anchor is not parsed as a directive"
|
||||
, "#anchor Target"
|
||||
] =?>
|
||||
para (spanWith ("anchor", [], []) mempty <> "Target")
|
||||
, "Anchor cannot start with a number" =:
|
||||
T.unlines [ "; A comment to make sure anchor is not parsed as a directive"
|
||||
, "#0notanchor Target"
|
||||
] =?>
|
||||
para "#0notanchor Target"
|
||||
, "Not anchor if starts with a space" =:
|
||||
" #notanchor Target" =?>
|
||||
para "#notanchor Target"
|
||||
, "Anchor inside a paragraph" =:
|
||||
T.unlines [ "Paragraph starts here"
|
||||
, "#anchor and ends here."
|
||||
] =?>
|
||||
para ("Paragraph starts here " <> spanWith ("anchor", [], []) mempty <> "and ends here.")
|
||||
]
|
||||
, testGroup "Footnotes"
|
||||
[ "Simple footnote" =:
|
||||
T.unlines [ "Here is a footnote[1]."
|
||||
|
|
Loading…
Add table
Reference in a new issue