From 39c507f735fd34c25cbf3cfbf9a39637ab5acafd Mon Sep 17 00:00:00 2001 From: Tor Erlend Fjelde Date: Wed, 24 May 2023 22:29:38 +0100 Subject: [PATCH 1/3] strip away potential quotation marks in header args for Org CodeBlocks --- src/Text/Pandoc/Readers/Org/Blocks.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs index 79f0e1238ae5..2b1c7cdfc306 100644 --- a/src/Text/Pandoc/Readers/Org/Blocks.hs +++ b/src/Text/Pandoc/Readers/Org/Blocks.hs @@ -415,7 +415,7 @@ blockOption = try $ do return (argKey, paramValue) orgParamValue :: Monad m => OrgParser m Text -orgParamValue = try $ fmap T.pack $ +orgParamValue = try $ fmap (stripQuotes . T.pack) $ skipSpaces *> notFollowedBy orgArgKey *> noneOf "\n\r" `many1Till` endOfValue @@ -424,6 +424,9 @@ orgParamValue = try $ fmap T.pack $ endOfValue = lookAhead $ try (skipSpaces <* oneOf "\n\r") <|> try (skipSpaces1 <* orgArgKey) + stripQuotes :: Text -> Text + stripQuotes = T.dropAround (== '\"') + -- -- Drawers From 46f861e0e0cbdcc6c9afbb96017bb64faeaa5c83 Mon Sep 17 00:00:00 2001 From: Tor Erlend Fjelde Date: Wed, 24 May 2023 22:50:51 +0100 Subject: [PATCH 2/3] should now be parsing quoted header args properly --- src/Text/Pandoc/Readers/Org/Blocks.hs | 8 ++++---- test/Tests/Readers/Org/Block/CodeBlock.hs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs index 2b1c7cdfc306..70051327d6dc 100644 --- a/src/Text/Pandoc/Readers/Org/Blocks.hs +++ b/src/Text/Pandoc/Readers/Org/Blocks.hs @@ -415,18 +415,18 @@ blockOption = try $ do return (argKey, paramValue) orgParamValue :: Monad m => OrgParser m Text -orgParamValue = try $ fmap (stripQuotes . T.pack) $ +orgParamValue = try $ fmap T.pack $ skipSpaces *> notFollowedBy orgArgKey - *> noneOf "\n\r" `many1Till` endOfValue + *> (quotedValue <|> regularValue) <* skipSpaces where endOfValue = lookAhead $ try (skipSpaces <* oneOf "\n\r") <|> try (skipSpaces1 <* orgArgKey) - stripQuotes :: Text -> Text - stripQuotes = T.dropAround (== '\"') + quotedValue = char '\"' *> manyTill anyChar (char '\"') + regularValue = noneOf "\n\r" `many1Till` endOfValue -- -- Drawers diff --git a/test/Tests/Readers/Org/Block/CodeBlock.hs b/test/Tests/Readers/Org/Block/CodeBlock.hs index bec1fe9fe3fa..9650358d4fe2 100644 --- a/test/Tests/Readers/Org/Block/CodeBlock.hs +++ b/test/Tests/Readers/Org/Block/CodeBlock.hs @@ -202,4 +202,18 @@ tests = , ("city", "Zürich") ] in codeBlockWith ( "", ["c"], params) "code body\n" + + , "Header args with quotes" =: + T.unlines [ "#+begin_src haskell :exports \"both\" :tangle \"main.hs\"" + , "main :: IO ()" + , "main = putStrLn \"Hello, World!\"" + , "#+end_src" + ] =?> + let params = [ ("org-language", "haskell") + , ("exports", "both") + , ("tangle", "main.hs") + ] + in codeBlockWith ("", ["haskell"], params) + "main :: IO ()\nmain = putStrLn \"Hello, World!\"\n" + ] From 1cb17ba852ec10ed5094476be91e498ee19d01dd Mon Sep 17 00:00:00 2001 From: Tor Erlend Fjelde Date: Wed, 24 May 2023 22:51:16 +0100 Subject: [PATCH 3/3] added some tests --- test/Tests/Readers/Org/Block/CodeBlock.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/Tests/Readers/Org/Block/CodeBlock.hs b/test/Tests/Readers/Org/Block/CodeBlock.hs index 9650358d4fe2..51af02931c8c 100644 --- a/test/Tests/Readers/Org/Block/CodeBlock.hs +++ b/test/Tests/Readers/Org/Block/CodeBlock.hs @@ -209,11 +209,21 @@ tests = , "main = putStrLn \"Hello, World!\"" , "#+end_src" ] =?> - let params = [ ("org-language", "haskell") - , ("exports", "both") + let params = [ ("exports", "both") , ("tangle", "main.hs") ] in codeBlockWith ("", ["haskell"], params) "main :: IO ()\nmain = putStrLn \"Hello, World!\"\n" + , "Header args with colon" =: + T.unlines [ "#+begin_src haskell :exports \"both\" :session \"my :session\"" + , "main :: IO ()" + , "main = putStrLn \"Hello, World!\"" + , "#+end_src" + ] =?> + let params = [ ("exports", "both") + , ("session", "my :session") + ] + in codeBlockWith ("", ["haskell"], params) + "main :: IO ()\nmain = putStrLn \"Hello, World!\"\n" ]