From c17c2040ed888df62568e227b5322ee0467795a1 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 23 Oct 2024 20:44:09 -0700 Subject: [PATCH] RST reader: support :file: on raw directive. Closes #8584. --- src/Text/Pandoc/Readers/RST.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 03e0bb07f6b2..7ccad218bea0 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -30,7 +30,7 @@ import qualified Data.Text as T import Text.Printf (printf) import Text.Pandoc.Builder (Blocks, Inlines, fromList, setMeta, trimInlines) import qualified Text.Pandoc.Builder as B -import Text.Pandoc.Class (PandocMonad, fetchItem, getTimestamp) +import Text.Pandoc.Class (PandocMonad, readFileFromDirs, fetchItem, getTimestamp) import Text.Pandoc.CSV (CSVOptions (..), defaultCSVOptions, parseCSV) import Text.Pandoc.Definition import Text.Pandoc.Error @@ -742,7 +742,12 @@ directive' = do if fieldIndent == 0 then return [] else many $ rawFieldListItem fieldIndent - body <- option "" $ try $ blanklines >> indentedBlock + let mbfile = trim <$> lookup "file" fields + body <- case mbfile of + Just f | label == "raw" -> do + currentDir <- takeDirectory . sourceName <$> getPosition + fromMaybe mempty <$> readFileFromDirs [currentDir] (T.unpack f) + _ -> option "" $ try $ blanklines >> indentedBlock optional blanklines let body' = body <> "\n\n" name = trim $ fromMaybe "" (lookup "name" fields)