Skip to content

Commit

Permalink
Org reader: fix parsing of src blocks with an -i flag.
Browse files Browse the repository at this point in the history
Tabs are now preserved in the contents of *src* blocks if the the block
has the `-i` flag.

Fixes: #10071
  • Loading branch information
tarleb committed Aug 8, 2024
1 parent 1f093ea commit b2755f7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Text/Pandoc/Readers/Org/Blocks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,12 @@ rawBlockContent blockType = try $ do
blkLines <- manyTill rawLine blockEnder
tabLen <- getOption readerTabStop
trimP <- orgStateTrimLeadBlkIndent <$> getState
let stripIndent strs = if trimP then map (T.drop (shortestIndent strs)) strs else strs
let stripIndent strs = map (T.drop (shortestIndent strs)) strs
(T.unlines
. stripIndent
. map (tabsToSpaces tabLen . commaEscaped)
. (if trimP
then stripIndent . map (tabsToSpaces tabLen)
else id)
. map commaEscaped
$ blkLines)
<$ updateState (\s -> s { orgStateTrimLeadBlkIndent = True })
where
Expand Down
15 changes: 15 additions & 0 deletions test/command/10071.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Leading tabs must be preserved in org mode *src* blocks with the `-i`
flag when pandoc is called with `-p`/`--preserve-tabs`.

```
% pandoc -f org -t native --preserve-tabs
#+begin_src makefile -i
%.o: %.cpp
$(CXX) -o $@ $<
#+end_src
^D
[ CodeBlock
( "" , [ "makefile" ] , [] )
"%.o: %.cpp\n\t$(CXX)\t-o\t$@\t$<\n"
]
```

0 comments on commit b2755f7

Please sign in to comment.