aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-12-04 23:45:09 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-01-25 17:07:40 +0100
commit92cc80b58bc1c932e3e102a260388df83fd7e0c0 (patch)
tree13cd072b30e686ae3310d30a59c6fa436aecdb18 /src/Text
parent03ede3e31263d6a4db1d726022d1e0bf22363540 (diff)
downloadpandoc-92cc80b58bc1c932e3e102a260388df83fd7e0c0.tar.gz
RST reader: implement start-after, end-before fields for include.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/RST.hs18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs
index 5185a1149..92d0e8670 100644
--- a/src/Text/Pandoc/Readers/RST.hs
+++ b/src/Text/Pandoc/Readers/RST.hs
@@ -39,7 +39,7 @@ import Text.Pandoc.Options
import Text.Pandoc.Error
import qualified Text.Pandoc.UTF8 as UTF8
import Control.Monad ( when, liftM, guard, mzero )
-import Data.List ( findIndex, intercalate,
+import Data.List ( findIndex, intercalate, isInfixOf,
transpose, sort, deleteFirstsBy, isSuffixOf , nub, union)
import Data.Maybe (fromMaybe, isJust)
import qualified Data.Map as M
@@ -405,8 +405,6 @@ blockQuote = do
Unsupported options for include:
tab-width
encoding
-start-after: text to find
-end-before: text to find
-}
include :: PandocMonad m => RSTParser m Blocks
@@ -441,9 +439,17 @@ include = try $ do
Nothing -> numLines + 1
Just x | x >= 0 -> x
| otherwise -> numLines + x -- negative from end
- let contents' = unlines $ drop (startLine' - 1)
- $ take (endLine' - 1)
- $ contentLines
+ let contentLines' = drop (startLine' - 1)
+ $ take (endLine' - 1)
+ $ contentLines
+ let contentLines'' = (case trim <$> lookup "end-before" fields of
+ Just patt -> takeWhile (not . (patt `isInfixOf`))
+ Nothing -> id) .
+ (case trim <$> lookup "start-after" fields of
+ Just patt -> drop 1 .
+ dropWhile (not . (patt `isInfixOf`))
+ Nothing -> id) $ contentLines'
+ let contents' = unlines contentLines''
case lookup "code" fields of
Just lang -> do
let numberLines = lookup "number-lines" fields