From 7639e800c5af85e5ded862a6e218d54489d17bfc Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Sun, 3 Aug 2025 14:59:35 +0200 Subject: Org template: add `#+options` lines if necessary The default template now adds `#+options` lines if non-default settings are used for the `smart_quotes` and `special_strings` extensions. --- data/templates/default.org | 6 ++++++ src/Text/Pandoc/Writers/Org.hs | 11 +++++++++++ test/command/10919.md | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 test/command/10919.md diff --git a/data/templates/default.org b/data/templates/default.org index ee073c6e5..38b6e6fcc 100644 --- a/data/templates/default.org +++ b/data/templates/default.org @@ -8,6 +8,12 @@ $endif$ $if(date)$ #+date: $date$ +$endif$ +$if(options/pairs)$ +$for(options/pairs)$ +#+options: ${it.key}:${it.value} +$endfor$ + $endif$ $for(header-includes)$ $header-includes$ diff --git a/src/Text/Pandoc/Writers/Org.hs b/src/Text/Pandoc/Writers/Org.hs index 6c05467cb..f1a516a66 100644 --- a/src/Text/Pandoc/Writers/Org.hs +++ b/src/Text/Pandoc/Writers/Org.hs @@ -71,6 +71,17 @@ pandocToOrg (Pandoc meta blocks) = do let main = body $+$ notes let context = defField "body" main . defField "math" hasMath + . defField "options" + (M.fromList + ((if isEnabled Ext_smart_quotes opts + then (("'", "t"):) + else id) . + (if not (isEnabled Ext_special_strings opts) + then (("-", "nil"):) + else id) + $ ([] :: [(Text, Text)]))) + . defField "option-special-strings" + (isEnabled Ext_special_strings opts) $ metadata return $ render colwidth $ case writerTemplate opts of diff --git a/test/command/10919.md b/test/command/10919.md new file mode 100644 index 000000000..6f03c8371 --- /dev/null +++ b/test/command/10919.md @@ -0,0 +1,21 @@ +# Org output with smart quotes turned on + +``` +% pandoc -t org+smart_quotes -s +"It's nice" she said. +^D +#+options: ':t + +"It's nice" she said. +``` + +Same test, but with special strings turned off. +``` +% pandoc -t org+smart_quotes-special_strings -s +"It's nice" she said. +^D +#+options: ':t +#+options: -:nil + +"It’s nice" she said. +``` -- cgit v1.2.3