git.iko.soy/typeable/pandoc
on master help sign in
Org reader: Add support for definition lists
commit480b33b7100048ef3fad51754ae76c21daa8b86f authorAlbert Krewinkel <tarleb@moltkeplatz.de> dateSun 6 Apr 2014, 14:49 (13 years ago) parent4ebf6f6
2 files changed+39−4
src/Text/Pandoc/Readers/Org.hs+16−1 tests/Tests/Readers/Org.hs+23−3
src/Text/Pandoc/Readers/Org.hs+16−1
@@ -383,7 +383,10 @@ restOfLine = mconcat <$> manyTill inline newline
383383--
384384
385385list :: OrgParser Blocks
386−list = choice [ bulletList, orderedList ] <?> "list"
386+list = choice [ definitionList, bulletList, orderedList ] <?> "list"
387+
388+definitionList :: OrgParser Blocks
389+definitionList = B.definitionList <$> many1 (definitionListItem bulletListStart)
387390
388391bulletList :: OrgParser Blocks
389392bulletList = B.bulletList . compactify' <$> many1 (listItem bulletListStart)
@@ -407,6 +410,18 @@ orderedListStart = genericListStart orderedListMarker
407410 -- Ordered list markers allowed in org-mode
408411 where orderedListMarker = mappend <$> many1 digit <*> (pure <$> oneOf ".)")
409412
413+definitionListItem :: OrgParser Int
414+ -> OrgParser (Inlines, [Blocks])
415+definitionListItem parseMarkerGetLength = try $ do
416+ markerLength <- parseMarkerGetLength
417+ term <- manyTill (noneOf "\n\r") (try $ string "::")
418+ first <- anyLineNewline
419+ cont <- concat <$> many (listContinuation markerLength)
420+ term' <- parseFromString inline term
421+ contents' <- parseFromString parseBlocks $ first ++ cont
422+ return (term', [contents'])
423+
424+
410425-- parse raw text for one list item, excluding start marker and continuations
411426listItem :: OrgParser Int
412427 -> OrgParser Blocks
tests/Tests/Readers/Org.hs+23−3
@@ -43,8 +43,8 @@ tests =
4343 para (strong "Cider")
4444
4545 , "Strong Emphasis" =:
46− "/*strength*/" =?>
47− para (emph . strong $ "strength")
46+ "/*strength*/" =?>
47+ para (emph . strong $ "strength")
4848
4949 , "Strikeout" =:
5050 "+Kill Bill+" =?>
@@ -428,7 +428,27 @@ tests =
428428 , "Bullet List in Ordered List" =:
429429 ("1. GNU\n" ++
430430 " - Freedom\n") =?>
431− orderedList [ (para "GNU") <> bulletList [ (plain "Freedom") ] ]
431+ orderedList [ (para "GNU") <> bulletList [ (plain "Freedom") ] ]
432+
433+ , "Definition List" =:
434+ unlines [ "- PLL :: phase-locked loop"
435+ , "- TTL ::"
436+ , " transistor-transistor logic"
437+ , "- PSK::phase-shift keying"
438+ , ""
439+ , " a digital modulation scheme"
440+ ] =?>
441+ definitionList [ ("PLL", [ plain $ "phase-locked" <> space <> "loop" ])
442+ , ("TTL", [ plain $ "transistor-transistor" <> space <>
443+ "logic" ])
444+ , ("PSK", [ mconcat
445+ [ para $ "phase-shift" <> space <> "keying"
446+ , plain $ spcSep [ "a", "digital"
447+ , "modulation", "scheme" ]
448+ ]
449+ ]
450+ )
451+ ]
432452 ]
433453
434454 , testGroup "Tables"