@@ -186,7 +186,7 @@ orgBlock = try $ do
186 "html" -> rawBlockLines (return . B.rawBlock (lowercase blkType))
186 "html" -> rawBlockLines (return . B.rawBlock (lowercase blkType))
187 "latex" -> rawBlockLines (return . B.rawBlock (lowercase blkType))
187 "latex" -> rawBlockLines (return . B.rawBlock (lowercase blkType))
188 "ascii" -> rawBlockLines (return . B.rawBlock (lowercase blkType))
188 "ascii" -> rawBlockLines (return . B.rawBlock (lowercase blkType))
189− "example" -> rawBlockLines (return . exampleCode)
189+ "example" -> exampleBlock blockAttrs
190 "quote" -> parseBlockLines (fmap B.blockQuote)
190 "quote" -> parseBlockLines (fmap B.blockQuote)
191 "verse" -> verseBlock
191 "verse" -> verseBlock
192 "src" -> codeBlock blockAttrs
192 "src" -> codeBlock blockAttrs
@@ -200,6 +200,16 @@ orgBlock = try $ do
200 lowercase :: String -> String
200 lowercase :: String -> String
201 lowercase = map toLower
201 lowercase = map toLower
203+exampleBlock :: PandocMonad m => BlockAttributes -> String -> OrgParser m (F Blocks)
204+exampleBlock blockAttrs _label = do
206+ (classes, kv) <- switchesAsAttributes
208+ content <- rawBlockContent "example"
209+ let id' = fromMaybe mempty $ blockAttrName blockAttrs
210+ let codeBlck = B.codeBlockWith (id', "example":classes, kv) content
211+ return . return $ codeBlck
203rawBlockLines :: Monad m => (String -> F Blocks) -> String -> OrgParser m (F Blocks)
213rawBlockLines :: Monad m => (String -> F Blocks) -> String -> OrgParser m (F Blocks)
204rawBlockLines f blockType = ignHeaders *> (f <$> rawBlockContent blockType)
214rawBlockLines f blockType = ignHeaders *> (f <$> rawBlockContent blockType)
@@ -216,11 +226,13 @@ rawBlockContent :: Monad m => String -> OrgParser m String
216rawBlockContent blockType = try $ do
226rawBlockContent blockType = try $ do
217 blkLines <- manyTill rawLine blockEnder
227 blkLines <- manyTill rawLine blockEnder
218 tabLen <- getOption readerTabStop
228 tabLen <- getOption readerTabStop
219− return
229+ trimP <- orgStateTrimLeadBlkIndent <$> getState
230+ let stripIndent strs = if trimP then map (drop (shortestIndent strs)) strs else strs
220− . unlines
231+ (unlines
221− . stripIndent
232+ . stripIndent
222− . map (tabsToSpaces tabLen . commaEscaped)
233+ . map (tabsToSpaces tabLen . commaEscaped)
223− $ blkLines
234+ $ blkLines)
235+ <$ updateState (\s -> s { orgStateTrimLeadBlkIndent = True })
225 rawLine :: Monad m => OrgParser m String
237 rawLine :: Monad m => OrgParser m String
226 rawLine = try $ ("" <$ blankline) <|> anyLine
238 rawLine = try $ ("" <$ blankline) <|> anyLine
@@ -228,9 +240,6 @@ rawBlockContent blockType = try $ do
228 blockEnder :: Monad m => OrgParser m ()
240 blockEnder :: Monad m => OrgParser m ()
229 blockEnder = try $ skipSpaces <* stringAnyCase ("#+end_" <> blockType)
241 blockEnder = try $ skipSpaces <* stringAnyCase ("#+end_" <> blockType)
231− stripIndent :: [String] -> [String]
232− stripIndent strs = map (drop (shortestIndent strs)) strs
234 shortestIndent :: [String] -> Int
243 shortestIndent :: [String] -> Int
235 shortestIndent = foldr (min . length . takeWhile isSpace) maxBound
244 shortestIndent = foldr (min . length . takeWhile isSpace) maxBound
236 . filter (not . null)
245 . filter (not . null)
@@ -357,12 +366,19 @@ switchPolarity = (SwitchMinus <$ char '-') <|> (SwitchPlus <$ char '+')
358-- | Parses a source block switch option.
367-- | Parses a source block switch option.
359switch :: Monad m => OrgParser m (Char, Maybe String, SwitchPolarity)
368switch :: Monad m => OrgParser m (Char, Maybe String, SwitchPolarity)
360−switch = try $ lineNumberSwitch <|> labelSwitch <|> simpleSwitch
369+switch = try $ lineNumberSwitch <|> labelSwitch
370+ <|> whitespaceSwitch <|> simpleSwitch
362 simpleSwitch = (\pol c -> (c, Nothing, pol)) <$> switchPolarity <*> letter
372 simpleSwitch = (\pol c -> (c, Nothing, pol)) <$> switchPolarity <*> letter
363 labelSwitch = genericSwitch 'l' $
373 labelSwitch = genericSwitch 'l' $
364 char '"' *> many1Till nonspaceChar (char '"')
374 char '"' *> many1Till nonspaceChar (char '"')
376+whitespaceSwitch :: Monad m => OrgParser m (Char, Maybe String, SwitchPolarity)
377+whitespaceSwitch = do
379+ updateState $ \s -> s { orgStateTrimLeadBlkIndent = False }
380+ return ('i', Nothing, SwitchMinus)
366-- | Generic source block switch-option parser.
382-- | Generic source block switch-option parser.
367genericSwitch :: Monad m
383genericSwitch :: Monad m
@@ -821,11 +837,22 @@ listItem parseIndentedMarker = try . withContext ListItemState $ do
822-- continuation of a list item - indented and separated by blankline or endline.
838-- continuation of a list item - indented and separated by blankline or endline.
823-- Note: nested lists are parsed as continuations.
839-- Note: nested lists are parsed as continuations.
824−listContinuation :: Monad m => Int
840+listContinuation :: PandocMonad m => Int -> OrgParser m String
825− -> OrgParser m String
826listContinuation markerLength = try $ do
841listContinuation markerLength = try $ do
827 notFollowedBy' blankline
842 notFollowedBy' blankline
828− mappend <$> (concat <$> many1 listLine)
843+ mappend <$> (concat <$> many1 (listContinuation' markerLength))
829 <*> many blankline
844 <*> many blankline
846+ listContinuation' indentation =
847+ blockLines indentation <|> listLine indentation
831− listLine = try $ indentWith markerLength *> anyLineNewline
848+ listLine indentation = try $ indentWith indentation *> anyLineNewline
849+ -- The block attributes and start must be appropriately indented,
850+ -- but the contents, and end do not.
851+ blockLines indentation =
852+ try $ lookAhead (indentWith indentation
855+ case attrFromBlockAttributes blockAttrs of
856+ ("", [], []) -> count 1 anyChar
857+ _ -> indentWith indentation))
858+ >> (snd <$> withRaw orgBlock)