git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: parse anchors
commitb5d064e8f08db27f3f9aa7287edd7a777be57594 authorAlexander Krotov <ilabdsf@gmail.com> dateThu 28 Sep 2017, 14:47 (9 years ago) parente38c023
2 files changed+31−1
src/Text/Pandoc/Readers/Muse.hs+11−1 test/Tests/Readers/Muse.hs+20
src/Text/Pandoc/Readers/Muse.hs+11−1
@@ -35,7 +35,6 @@ TODO:
3535- Org tables
3636- table.el tables
3737- Images with attributes (floating and width)
38−- Anchors
3938- Citations and <biblio>
4039- <play> environment
4140-}
@@ -535,6 +534,7 @@ tableParseCaption = try $ do
535534
536535inline :: PandocMonad m => MuseParser m (F Inlines)
537536inline = choice [ br
537+ , anchor
538538 , footnote
539539 , strong
540540 , strongTag
@@ -552,6 +552,16 @@ inline = choice [ br
552552 , symbol
553553 ] <?> "inline"
554554
555+anchor :: PandocMonad m => MuseParser m (F Inlines)
556+anchor = try $ do
557+ getPosition >>= \pos -> guard (sourceColumn pos == 1)
558+ char '#'
559+ first <- letter
560+ rest <- many (letter <|> digit)
561+ skipMany spaceChar <|> void newline
562+ let anchorId = first:rest
563+ return $ return $ B.spanWith (anchorId, [], []) mempty
564+
555565footnote :: PandocMonad m => MuseParser m (F Inlines)
556566footnote = try $ do
557567 ref <- noteMarker
test/Tests/Readers/Muse.hs+20
@@ -344,6 +344,26 @@ tests =
344344 ] =?>
345345 blockQuote (para "* Hi")
346346 ]
347+ , testGroup "Anchors"
348+ [ "Anchor" =:
349+ T.unlines [ "; A comment to make sure anchor is not parsed as a directive"
350+ , "#anchor Target"
351+ ] =?>
352+ para (spanWith ("anchor", [], []) mempty <> "Target")
353+ , "Anchor cannot start with a number" =:
354+ T.unlines [ "; A comment to make sure anchor is not parsed as a directive"
355+ , "#0notanchor Target"
356+ ] =?>
357+ para "#0notanchor Target"
358+ , "Not anchor if starts with a space" =:
359+ " #notanchor Target" =?>
360+ para "#notanchor Target"
361+ , "Anchor inside a paragraph" =:
362+ T.unlines [ "Paragraph starts here"
363+ , "#anchor and ends here."
364+ ] =?>
365+ para ("Paragraph starts here " <> spanWith ("anchor", [], []) mempty <> "and ends here.")
366+ ]
347367 , testGroup "Footnotes"
348368 [ "Simple footnote" =:
349369 T.unlines [ "Here is a footnote[1]."