@@ -268,8 +268,12 @@ data OrgTable = OrgTable
268table :: OrgParser Blocks
268table :: OrgParser Blocks
269table = try $ do
269table = try $ do
270 lookAhead tableStart
270 lookAhead tableStart
271− OrgTable _ aligns heads lns <- normalizeTable . rowsToTable <$> tableRows
271+ orgToPandocTable . normalizeTable . rowsToTable <$> tableRows
273+orgToPandocTable :: OrgTable
275+orgToPandocTable (OrgTable _ aligns heads lns) =
272− return $ B.table "" (zip aligns $ repeat 0) heads lns
276+ B.table "" (zip aligns $ repeat 0) heads lns
274tableStart :: OrgParser Char
278tableStart :: OrgParser Char
275tableStart = try $ skipSpaces *> char '|'
279tableStart = try $ skipSpaces *> char '|'
@@ -403,20 +407,14 @@ orderedListStart = genericListStart orderedListMarker
403 -- Ordered list markers allowed in org-mode
407 -- Ordered list markers allowed in org-mode
404 where orderedListMarker = mappend <$> many1 digit <*> (pure <$> oneOf ".)")
408 where orderedListMarker = mappend <$> many1 digit <*> (pure <$> oneOf ".)")
410+-- parse raw text for one list item, excluding start marker and continuations
406listItem :: OrgParser Int
411listItem :: OrgParser Int
407 -> OrgParser Blocks
412 -> OrgParser Blocks
408listItem start = try $ do
413listItem start = try $ do
409− (markerLength, first) <- try (start >>= rawListItem)
414+ markerLength <- try start
415+ firstLine <- anyLineNewline
410− rest <- many (listContinuation markerLength)
416+ rest <- concat <$> many (listContinuation markerLength)
411− parseFromString parseBlocks $ concat (first:rest)
417+ parseFromString parseBlocks $ firstLine ++ rest
413−-- parse raw text for one list item, excluding start marker and continuations
415− -> OrgParser (Int, String)
416−rawListItem markerLength = try $ do
417− firstLine <- anyLine
418− restLines <- many (listLine markerLength)
419− return (markerLength, (firstLine ++ "\n" ++ (concat restLines)))
421-- continuation of a list item - indented and separated by blankline or endline.
419-- continuation of a list item - indented and separated by blankline or endline.
422-- Note: nested lists are parsed as continuations.
420-- Note: nested lists are parsed as continuations.
@@ -424,14 +422,11 @@ listContinuation :: Int
424 -> OrgParser String
422 -> OrgParser String
425listContinuation markerLength = try $
423listContinuation markerLength = try $
426 mappend <$> many blankline
424 mappend <$> many blankline
427− <*> (concat <$> many1 (listLine markerLength))
425+ <*> (concat <$> many1 listLine)
426+ where listLine = try $ indentWith markerLength *> anyLineNewline
429−-- parse a line of a list item
431− -> OrgParser String
428+anyLineNewline :: OrgParser String
432−listLine markerLength = try $
429+anyLineNewline = (++ "\n") <$> anyLine
433− indentWith markerLength *> anyLine
@@ -491,12 +486,11 @@ explicitOrImageLink = try $ do
492 src <- enclosedRaw (char '[') (char ']')
487 src <- enclosedRaw (char '[') (char ']')
493 title <- enclosedRaw (char '[') (char ']')
488 title <- enclosedRaw (char '[') (char ']')
494− title' <- parseFromString (mconcat . butLast <$> many inline) (title++"\n")
489+ title' <- parseFromString (mconcat <$> many inline) title
496 return $ if (isImage src) && (isImage title)
491 return $ if (isImage src) && (isImage title)
497 then B.link src "" (B.image title "" "")
492 then B.link src "" (B.image title "" "")
498 else B.link src "" title'
493 else B.link src "" title'
499− where butLast = reverse . tail . reverse
501selflinkOrImage :: OrgParser Inlines
495selflinkOrImage :: OrgParser Inlines
502selflinkOrImage = try $ do
496selflinkOrImage = try $ do
@@ -552,11 +546,8 @@ inlinesEnclosedBy c = try $ do
552 updateState $ \st -> st { orgInlineCharStack = c:(orgInlineCharStack st) }
546 updateState $ \st -> st { orgInlineCharStack = c:(orgInlineCharStack st) }
553 res <- enclosedInlines (atStart (char c) <* endsOnThisOrNextLine c)
547 res <- enclosedInlines (atStart (char c) <* endsOnThisOrNextLine c)
554 (atEnd $ char c)
548 (atEnd $ char c)
555− updateState $ \st -> st { orgInlineCharStack = shift . orgInlineCharStack $ st }
549+ updateState $ \st -> st { orgInlineCharStack = drop 1 . orgInlineCharStack $ st }
556 return res
550 return res
559− | otherwise = tail xs
561enclosedRaw :: OrgParser a
552enclosedRaw :: OrgParser a
562 -> OrgParser b
553 -> OrgParser b
@@ -583,14 +574,13 @@ atStart p = do
583atEnd :: OrgParser a -> OrgParser a
574atEnd :: OrgParser a -> OrgParser a
584atEnd p = try $ do
575atEnd p = try $ do
585 p <* lookingAtEndOfWord
576 p <* lookingAtEndOfWord
586− where lookingAtEndOfWord = lookAhead . oneOf =<< postWordChars
577+ where lookingAtEndOfWord =
578+ eof <|> const (return ()) =<< lookAhead . oneOf =<< postWordChars
588postWordChars :: OrgParser [Char]
580postWordChars :: OrgParser [Char]
589postWordChars = do
581postWordChars = do
590 st <- getState
582 st <- getState
591− return $ "\t\n\r !\"'),-.:?}" ++ (safeSecond . orgInlineCharStack $ st)
583+ return $ "\t\n\r !\"'),-.:?}" ++ (take 1 . drop 1 . orgInlineCharStack $ st)
592− where safeSecond (_:x2:_) = [x2]
595-- FIXME: These functions are hacks and should be replaced
585-- FIXME: These functions are hacks and should be replaced
596endsOnThisOrNextLine :: Char
586endsOnThisOrNextLine :: Char
@@ -608,6 +598,7 @@ endsOnThisLine input c doOnOtherLines = do
608 postWordChars' <- postWordChars
598 postWordChars' <- postWordChars
609 case break (`elem` c:"\n") input of
599 case break (`elem` c:"\n") input of
610 (_,'\n':rest) -> doOnOtherLines rest
600 (_,'\n':rest) -> doOnOtherLines rest
601+ (_,_:[]) -> return ()
611 (_,_:rest@(n:_)) -> if n `elem` postWordChars'
602 (_,_:rest@(n:_)) -> if n `elem` postWordChars'
612 then return ()
603 then return ()
613 else endsOnThisLine rest c doOnOtherLines
604 else endsOnThisLine rest c doOnOtherLines