@@ -391,6 +391,9 @@ lookupBlockAttribute key =
391391
392392type BlockProperties = (Int, String) -- (Indentation, Block-Type)
393393
394+updateIndent :: BlockProperties -> Int -> BlockProperties
395+updateIndent (_, blkType) indent = (indent, blkType)
396+
394397orgBlock :: OrgParser (F Blocks)
395398orgBlock = try $ do
396399 blockProp@(_, blkType) <- blockHeaderStart
@@ -407,11 +410,23 @@ orgBlock = try $ do
407410 _ -> withParsed (fmap $ divWithClass blkType)
408411
409412blockHeaderStart :: OrgParser (Int, String)
410−blockHeaderStart = try $ (,) <$> indent <*> blockType
413+blockHeaderStart = try $ (,) <$> indentation <*> blockType
411414 where
412− indent = length <$> many spaceChar
413415 blockType = map toLower <$> (stringAnyCase "#+begin_" *> orgArgWord)
414416
417+indentation :: OrgParser Int
418+indentation = try $ do
419+ tabStop <- getOption readerTabStop
420+ s <- many spaceChar
421+ return $ spaceLength tabStop s
422+
423+spaceLength :: Int -> String -> Int
424+spaceLength tabStop s = (sum . map charLen) s
425+ where
426+ charLen ' ' = 1
427+ charLen '\t' = tabStop
428+ charLen _ = 0
429+
415430withRaw' :: (String -> F Blocks) -> BlockProperties -> OrgParser (F Blocks)
416431withRaw' f blockProp = (ignHeaders *> (f <$> rawBlockContent blockProp))
417432
@@ -450,7 +465,8 @@ codeBlock blkProp = do
450465 skipSpaces
451466 (classes, kv) <- codeHeaderArgs <|> (mempty <$ ignHeaders)
452467 id' <- fromMaybe "" <$> lookupBlockAttribute "name"
453− content <- rawBlockContent blkProp
468+ leadingIndent <- lookAhead indentation
469+ content <- rawBlockContent (updateIndent blkProp leadingIndent)
454470 resultsContent <- followingResultsBlock
455471 let includeCode = exportsCode kv
456472 let includeResults = exportsResults kv
@@ -472,7 +488,7 @@ rawBlockContent (indent, blockType) = try $
472488 unlines . map commaEscaped <$> manyTill indentedLine blockEnder
473489 where
474490 indentedLine = try $ ("" <$ blankline) <|> (indentWith indent *> anyLine)
475− blockEnder = try $ indentWith indent *> stringAnyCase ("#+end_" <> blockType)
491+ blockEnder = try $ skipSpaces *> stringAnyCase ("#+end_" <> blockType)
476492
477493parsedBlockContent :: BlockProperties -> OrgParser (F Blocks)
478494parsedBlockContent blkProps = try $ do