git.iko.soy/typeable/pandoc
on master help sign in
Org reader: support `\n` export option

The `\n` export option turns all newlines in the text into hard linebreaks. Closes #3950

commit514662e544a828e6c3904d2fec0216dc19bbcb9f authorAlbert Krewinkel <albert@zeitkraut.de> dateMon 2 Oct 2017, 23:11 (9 years ago) parent3e77ea4
4 files changed+12−2
src/Text/Pandoc/Readers/Org/ExportSettings.hs+1−1 src/Text/Pandoc/Readers/Org/Inlines.hs+2−1 src/Text/Pandoc/Readers/Org/ParserState.hs+2 test/Tests/Readers/Org.hs+7
src/Text/Pandoc/Readers/Org/ExportSettings.hs+1−1
@@ -52,7 +52,7 @@ exportSetting = choice
5252 , booleanSetting "-" (\val es -> es { exportSpecialStrings = val })
5353 , ignoredSetting ":"
5454 , ignoredSetting "<"
55− , ignoredSetting "\\n"
55+ , booleanSetting "\\n" (\val es -> es { exportPreserveBreaks = val })
5656 , archivedTreeSetting "arch" (\val es -> es { exportArchivedTrees = val })
5757 , booleanSetting "author" (\val es -> es { exportWithAuthor = val })
5858 , ignoredSetting "c"
src/Text/Pandoc/Readers/Org/Inlines.hs+2−1
@@ -158,7 +158,8 @@ endline = try $ do
158158 decEmphasisNewlinesCount
159159 guard =<< newlinesCountWithinLimits
160160 updateLastPreCharPos
161− returnF B.softbreak
161+ useHardBreaks <- exportPreserveBreaks . orgStateExportSettings <$> getState
162+ returnF (if useHardBreaks then B.linebreak else B.softbreak)
162163
163164
164165--
src/Text/Pandoc/Readers/Org/ParserState.hs+2
@@ -242,6 +242,7 @@ data ExportSettings = ExportSettings
242242 , exportEmphasizedText :: Bool -- ^ Parse emphasized text
243243 , exportHeadlineLevels :: Int
244244 -- ^ Maximum depth of headlines, deeper headlines are convert to list
245+ , exportPreserveBreaks :: Bool -- ^ Whether to preserve linebreaks
245246 , exportSmartQuotes :: Bool -- ^ Parse quotes smartly
246247 , exportSpecialStrings :: Bool -- ^ Parse ellipses and dashes smartly
247248 , exportSubSuperscripts :: Bool -- ^ TeX-like syntax for sub- and superscripts
@@ -261,6 +262,7 @@ defaultExportSettings = ExportSettings
261262 , exportDrawers = Left ["LOGBOOK"]
262263 , exportEmphasizedText = True
263264 , exportHeadlineLevels = 3
265+ , exportPreserveBreaks = False
264266 , exportSmartQuotes = False
265267 , exportSpecialStrings = True
266268 , exportSubSuperscripts = True
test/Tests/Readers/Org.hs+7
@@ -773,6 +773,13 @@ tests =
773773 , para "top-level section 2" ]
774774 ]
775775
776+ , "preserve linebreaks as hard breaks" =:
777+ T.unlines [ "#+OPTIONS: \\n:t"
778+ , "first"
779+ , "second"
780+ ] =?>
781+ para ("first" <> linebreak <> "second")
782+
776783 , "disable author export" =:
777784 T.unlines [ "#+OPTIONS: author:nil"
778785 , "#+AUTHOR: ShyGuy"