git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: add definition list support (#3860)
commit0a839cbdc982217819c08c918cca75f6f56eabbb authorAlexander <ilabdsf@gmail.com> dateTue 22 Aug 2017, 07:08 (9 years ago) parent4567105
2 files changed+80−1
src/Text/Pandoc/Readers/Muse.hs+28−1 test/Tests/Readers/Muse.hs+52
src/Text/Pandoc/Readers/Muse.hs+28−1
@@ -33,7 +33,6 @@ TODO:
3333- Page breaks (five "*")
3434- Headings with anchors (make it round trip with Muse writer)
3535- <verse> and ">"
36−- Definition lists
3736- Org tables
3837- table.el tables
3938- Images with attributes (floating and width)
@@ -184,6 +183,7 @@ blockElements = choice [ comment
184183 , quoteTag
185184 , bulletList
186185 , orderedList
186+ , definitionList
187187 , table
188188 , commentTag
189189 , noteBlock
@@ -348,6 +348,33 @@ orderedList = try $ do
348348 items <- sequence <$> many1 (listItem $ orderedListStart style delim)
349349 return $ B.orderedListWith p <$> items
350350
351+definitionListItem :: PandocMonad m => MuseParser m (F (Inlines, [Blocks]))
352+definitionListItem = try $ do
353+ term <- termParser
354+ many1 spaceChar
355+ string "::"
356+ firstLine <- anyLineNewline
357+ restLines <- manyTill anyLineNewline endOfListItemElement
358+ let lns = firstLine : restLines
359+ lineContent <- parseFromString (withListContext parseBlocks) $ concat lns ++ "\n"
360+ pure $ do lineContent' <- lineContent
361+ pure (B.text term, [lineContent'])
362+ where
363+ termParser = (many1 spaceChar) >> -- Initial space as required by Amusewiki, but not Emacs Muse
364+ (many1Till anyChar $ lookAhead (void (try (spaceChar >> string "::")) <|> void newline))
365+ endOfInput = try $ skipMany blankline >> skipSpaces >> eof
366+ twoBlankLines = try $ blankline >> skipMany1 blankline
367+ newDefinitionListItem = try $ void termParser
368+ endOfListItemElement = lookAhead $ endOfInput <|> newDefinitionListItem <|> twoBlankLines
369+
370+definitionListItems :: PandocMonad m => MuseParser m (F [(Inlines, [Blocks])])
371+definitionListItems = sequence <$> many1 definitionListItem
372+
373+definitionList :: PandocMonad m => MuseParser m (F Blocks)
374+definitionList = do
375+ listItems <- definitionListItems
376+ return $ B.definitionList <$> listItems
377+
351378--
352379-- tables
353380--
test/Tests/Readers/Muse.hs+52
@@ -421,6 +421,58 @@ tests =
421421 ] =?>
422422 bulletList [ para "Foo" <> para "bar" ] <> bulletList [ para "Baz" ]
423423 ]
424+ -- Test that definition list requires a leading space.
425+ -- Emacs Muse does not require a space, we follow Amusewiki here.
426+ , "Not a definition list" =:
427+ T.unlines
428+ [ "First :: second"
429+ , "Foo :: bar"
430+ ] =?>
431+ para "First :: second Foo :: bar"
432+ , "Definition list" =:
433+ T.unlines
434+ [ " First :: second"
435+ , " Foo :: bar"
436+ ] =?>
437+ definitionList [ ("First", [ para "second" ])
438+ , ("Foo", [ para "bar" ])
439+ ]
440+ , "Definition list term cannot include newline" =:
441+ T.unlines
442+ [ " Foo" -- "Foo" is not a part of the definition list term
443+ , " Bar :: baz"
444+ ] =?>
445+ para "Foo" <>
446+ definitionList [ ("Bar", [ para "baz" ]) ]
447+ , "Multi-line definition lists" =:
448+ T.unlines
449+ [ " First term :: Definition of first term"
450+ , "and its continuation."
451+ , " Second term :: Definition of second term."
452+ ] =?>
453+ definitionList [ ("First term", [ para "Definition of first term and its continuation." ])
454+ , ("Second term", [ para "Definition of second term." ])
455+ ]
456+ -- Emacs Muse creates two separate lists when indentation of items is different.
457+ -- We follow Amusewiki and allow different indentation within one list.
458+ , "Changing indentation" =:
459+ T.unlines
460+ [ " First term :: Definition of first term"
461+ , "and its continuation."
462+ , " Second term :: Definition of second term."
463+ ] =?>
464+ definitionList [ ("First term", [ para "Definition of first term and its continuation." ])
465+ , ("Second term", [ para "Definition of second term." ])
466+ ]
467+ , "Two blank lines separate definition lists" =:
468+ T.unlines
469+ [ " First :: list"
470+ , ""
471+ , ""
472+ , " Second :: list"
473+ ] =?>
474+ definitionList [ ("First", [ para "list" ]) ] <>
475+ definitionList [ ("Second", [ para "list" ]) ]
424476 -- Headers in first column of list continuation are not allowed
425477 , "No headers in list continuation" =:
426478 T.unlines