@@ -391,6 +391,9 @@ lookupBlockAttribute key =
392type BlockProperties = (Int, String) -- (Indentation, Block-Type)
392type BlockProperties = (Int, String) -- (Indentation, Block-Type)
394+updateIndent :: BlockProperties -> Int -> BlockProperties
395+updateIndent (_, blkType) indent = (indent, blkType)
394orgBlock :: OrgParser (F Blocks)
397orgBlock :: OrgParser (F Blocks)
395orgBlock = try $ do
398orgBlock = try $ do
396 blockProp@(_, blkType) <- blockHeaderStart
399 blockProp@(_, blkType) <- blockHeaderStart
@@ -407,11 +410,23 @@ orgBlock = try $ do
407 _ -> withParsed (fmap $ divWithClass blkType)
410 _ -> withParsed (fmap $ divWithClass blkType)
409blockHeaderStart :: OrgParser (Int, String)
412blockHeaderStart :: OrgParser (Int, String)
410−blockHeaderStart = try $ (,) <$> indent <*> blockType
413+blockHeaderStart = try $ (,) <$> indentation <*> blockType
412− indent = length <$> many spaceChar
413 blockType = map toLower <$> (stringAnyCase "#+begin_" *> orgArgWord)
415 blockType = map toLower <$> (stringAnyCase "#+begin_" *> orgArgWord)
417+indentation :: OrgParser Int
418+indentation = try $ do
419+ tabStop <- getOption readerTabStop
421+ return $ spaceLength tabStop s
423+spaceLength :: Int -> String -> Int
424+spaceLength tabStop s = (sum . map charLen) s
427+ charLen '\t' = tabStop
415withRaw' :: (String -> F Blocks) -> BlockProperties -> OrgParser (F Blocks)
430withRaw' :: (String -> F Blocks) -> BlockProperties -> OrgParser (F Blocks)
416withRaw' f blockProp = (ignHeaders *> (f <$> rawBlockContent blockProp))
431withRaw' f blockProp = (ignHeaders *> (f <$> rawBlockContent blockProp))
@@ -450,7 +465,8 @@ codeBlock blkProp = do
450 skipSpaces
465 skipSpaces
451 (classes, kv) <- codeHeaderArgs <|> (mempty <$ ignHeaders)
466 (classes, kv) <- codeHeaderArgs <|> (mempty <$ ignHeaders)
452 id' <- fromMaybe "" <$> lookupBlockAttribute "name"
467 id' <- fromMaybe "" <$> lookupBlockAttribute "name"
468+ leadingIndent <- lookAhead indentation
453− content <- rawBlockContent blkProp
469+ content <- rawBlockContent (updateIndent blkProp leadingIndent)
454 resultsContent <- followingResultsBlock
470 resultsContent <- followingResultsBlock
455 let includeCode = exportsCode kv
471 let includeCode = exportsCode kv
456 let includeResults = exportsResults kv
472 let includeResults = exportsResults kv
@@ -472,7 +488,7 @@ rawBlockContent (indent, blockType) = try $
472 unlines . map commaEscaped <$> manyTill indentedLine blockEnder
488 unlines . map commaEscaped <$> manyTill indentedLine blockEnder
474 indentedLine = try $ ("" <$ blankline) <|> (indentWith indent *> anyLine)
490 indentedLine = try $ ("" <$ blankline) <|> (indentWith indent *> anyLine)
475− blockEnder = try $ indentWith indent *> stringAnyCase ("#+end_" <> blockType)
491+ blockEnder = try $ skipSpaces *> stringAnyCase ("#+end_" <> blockType)
477parsedBlockContent :: BlockProperties -> OrgParser (F Blocks)
493parsedBlockContent :: BlockProperties -> OrgParser (F Blocks)
478parsedBlockContent blkProps = try $ do
494parsedBlockContent blkProps = try $ do