Org reader: support line selection in INCLUDE directives. (#8060)
This commit is contained in:
parent
ed054b4c74
commit
ae8ed408b0
6 changed files with 55 additions and 1 deletions
|
@ -535,8 +535,15 @@ include = try $ do
|
|||
return $ pure . B.codeBlockWith attr <$> parseRaw
|
||||
_ -> return $ return . B.fromList . blockFilter params <$> blockList
|
||||
currentDir <- takeDirectory . sourceName <$> getPosition
|
||||
let (startLine, endLine) =
|
||||
case lookup "lines" params of
|
||||
Nothing -> (Nothing, Nothing)
|
||||
Just bounds -> let boundStr = T.drop 1 (T.dropEnd 1 bounds)
|
||||
begStr = T.takeWhile (/= '-') boundStr
|
||||
endStr = T.takeWhileEnd (/= '-') boundStr
|
||||
in (safeRead begStr, pred <$> safeRead endStr)
|
||||
insertIncludedFile blocksParser toSources
|
||||
[currentDir] filename Nothing Nothing
|
||||
[currentDir] filename startLine endLine
|
||||
where
|
||||
includeTarget :: PandocMonad m => OrgParser m FilePath
|
||||
includeTarget = do
|
||||
|
|
8
test/command/6466-beg.hs
Normal file
8
test/command/6466-beg.hs
Normal file
|
@ -0,0 +1,8 @@
|
|||
want :: Int
|
||||
want = 42
|
||||
|
||||
-- DO NOT WANT this; right bound is exclusive
|
||||
|
||||
-- DO NOT WANT the below
|
||||
doNotWant :: Int
|
||||
doNotWant = 999
|
4
test/command/6466-end.hs
Normal file
4
test/command/6466-end.hs
Normal file
|
@ -0,0 +1,4 @@
|
|||
-- DO NOT WANT
|
||||
|
||||
want :: Int
|
||||
want = 42
|
10
test/command/6466-mid.hs
Normal file
10
test/command/6466-mid.hs
Normal file
|
@ -0,0 +1,10 @@
|
|||
-- DO NOT WANT
|
||||
|
||||
want :: Int
|
||||
want = 42
|
||||
|
||||
-- AVOID EXCLUSIVE RIGHT BOUND
|
||||
|
||||
-- DO NOT WANT
|
||||
doNotWant :: Int
|
||||
doNotWant = 999
|
2
test/command/6466-whole.hs
Normal file
2
test/command/6466-whole.hs
Normal file
|
@ -0,0 +1,2 @@
|
|||
want :: Int
|
||||
want = 42
|
23
test/command/6466.md
Normal file
23
test/command/6466.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
```
|
||||
% pandoc -f org -t native
|
||||
Stuff
|
||||
|
||||
#+INCLUDE: "command/6466-beg.hs" src haskell :lines "-4"
|
||||
#+INCLUDE: "command/6466-mid.hs" src haskell :lines "3-6"
|
||||
#+INCLUDE: "command/6466-end.hs" src haskell :lines "3-"
|
||||
#+INCLUDE: "command/6466-whole.hs" src haskell :lines "-"
|
||||
|
||||
More stuff
|
||||
^D
|
||||
[ Para [ Str "Stuff" ]
|
||||
, CodeBlock
|
||||
( "" , [ "haskell" ] , [] ) "want :: Int\nwant = 42\n\n"
|
||||
, CodeBlock
|
||||
( "" , [ "haskell" ] , [] ) "want :: Int\nwant = 42\n\n"
|
||||
, CodeBlock
|
||||
( "" , [ "haskell" ] , [] ) "want :: Int\nwant = 42\n"
|
||||
, CodeBlock
|
||||
( "" , [ "haskell" ] , [] ) "want :: Int\nwant = 42\n"
|
||||
, Para [ Str "More" , Space , Str "stuff" ]
|
||||
]
|
||||
```
|
Loading…
Add table
Reference in a new issue