@@ -37,6 +37,7 @@ import Text.Pandoc.Options
37import qualified Text.Pandoc.Parsing as P
37import qualified Text.Pandoc.Parsing as P
38import Text.Pandoc.Parsing hiding ( F, unF, askF, asksF, runF
38import Text.Pandoc.Parsing hiding ( F, unF, askF, asksF, runF
39 , newline, orderedListMarker
39 , newline, orderedListMarker
40 , updateLastStrPos )
41 , updateLastStrPos )
41import Text.Pandoc.Shared (compactify')
42import Text.Pandoc.Shared (compactify')
@@ -47,7 +48,7 @@ import Control.Monad (foldM, guard, liftM, liftM2, when)
47import Control.Monad.Reader (Reader, runReader, ask, asks)
48import Control.Monad.Reader (Reader, runReader, ask, asks)
48import Data.Char (toLower)
49import Data.Char (toLower)
49import Data.Default
50import Data.Default
50−import Data.List (isPrefixOf, isSuffixOf)
51+import Data.List (intersperse, isPrefixOf, isSuffixOf)
51import Data.Maybe (listToMaybe, fromMaybe)
52import Data.Maybe (listToMaybe, fromMaybe)
52import Data.Monoid (Monoid, mconcat, mempty, mappend)
53import Data.Monoid (Monoid, mconcat, mempty, mappend)
@@ -156,6 +157,16 @@ addToNotesTable note = do
156 oldnotes <- orgStateNotes' <$> getState
157 oldnotes <- orgStateNotes' <$> getState
157 updateState $ \s -> s{ orgStateNotes' = note:oldnotes }
158 updateState $ \s -> s{ orgStateNotes' = note:oldnotes }
160+-- The version Text.Pandoc.Parsing cannot be used, as we need additional parts
161+-- of the state saved and restored.
162+parseFromString :: OrgParser a -> String -> OrgParser a
163+parseFromString parser str' = do
164+ oldLastPreCharPos <- orgStateLastPreCharPos <$> getState
165+ updateState $ \s -> s{ orgStateLastPreCharPos = Nothing }
166+ result <- P.parseFromString parser str'
167+ updateState $ \s -> s{ orgStateLastPreCharPos = oldLastPreCharPos }
161-- Adaptions and specializations of parsing utilities
172-- Adaptions and specializations of parsing utilities
@@ -218,13 +229,27 @@ block = choice [ mempty <$ blanklines
218orgBlock :: OrgParser (F Blocks)
229orgBlock :: OrgParser (F Blocks)
219orgBlock = try $ do
230orgBlock = try $ do
220 (indent, blockType, args) <- blockHeader
231 (indent, blockType, args) <- blockHeader
221− blockStr <- rawBlockContent indent blockType
232+ content <- rawBlockContent indent blockType
233+ contentBlocks <- parseFromString parseBlocks (content ++ "\n")
222 let classArgs = [ translateLang . fromMaybe [] $ listToMaybe args ]
234 let classArgs = [ translateLang . fromMaybe [] $ listToMaybe args ]
223 case blockType of
235 case blockType of
224 "comment" -> return mempty
236 "comment" -> return mempty
225− "src" -> return . return $ B.codeBlockWith ("", classArgs, []) blockStr
237+ "src" -> returnF $ B.codeBlockWith ("", classArgs, []) content
238+ "html" -> returnF $ B.rawBlock "html" content
239+ "latex" -> returnF $ B.rawBlock "latex" content
240+ "ascii" -> returnF $ B.rawBlock "ascii" content
241+ "example" -> returnF $ exampleCode content
242+ "quote" -> return $ B.blockQuote <$> contentBlocks
243+ "verse" -> parseVerse content
226− _ -> fmap (B.divWith ("", [blockType], []))
244+ _ -> return $ B.divWith ("", [blockType], []) <$> contentBlocks
246+ returnF :: a -> OrgParser (F a)
247+ returnF = return . return
249+ parseVerse :: String -> OrgParser (F Blocks)
251+ fmap B.para . mconcat . intersperse (pure B.linebreak)
227− <$> parseFromString parseBlocks blockStr
252+ <$> mapM (parseFromString parseInlines) (lines cs)
229blockHeader :: OrgParser (Int, String, [String])
254blockHeader :: OrgParser (Int, String, [String])
230blockHeader = (,,) <$> blockIndent
255blockHeader = (,,) <$> blockIndent
@@ -270,8 +295,10 @@ commaEscaped cs = cs
271example :: OrgParser (F Blocks)
296example :: OrgParser (F Blocks)
272example = try $ do
297example = try $ do
273− body <- unlines <$> many1 exampleLine
298+ return . return . exampleCode =<< unlines <$> many1 exampleLine
300+exampleCode :: String -> Blocks
274− return . return $ B.codeBlockWith ("", ["example"], []) body
301+exampleCode = B.codeBlockWith ("", ["example"], [])
276exampleLine :: OrgParser String
303exampleLine :: OrgParser String
277exampleLine = try $ string ": " *> anyLine
304exampleLine = try $ string ": " *> anyLine