git.iko.soy/typeable/pandoc
on master help sign in
Added a writer option for wrapped text and a command-line option
5b888e8fiddlosopher
src/Main.hs+10−1
@@ -107,6 +107,7 @@ data Opt = Opt
107 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
107 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
108 , optStrict :: Bool -- ^ Use strict markdown syntax
108 , optStrict :: Bool -- ^ Use strict markdown syntax
109 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
109 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
110+ , optWrapText :: Bool -- ^ Wrap text
110 }
111 }
111
112
112-- | Defaults for command-line options.
113-- | Defaults for command-line options.
@@ -135,6 +136,7 @@ defaultOpts = Opt
135 , optIgnoreArgs = False
136 , optIgnoreArgs = False
136 , optStrict = False
137 , optStrict = False
137 , optReferenceLinks = False
138 , optReferenceLinks = False
139+ , optWrapText = True
138 }
140 }
139
141
140-- | A list of functions, each transforming the options data structure
142-- | A list of functions, each transforming the options data structure
@@ -213,6 +215,11 @@ options =
213 (\opt -> return opt { optNumberSections = True }))
215 (\opt -> return opt { optNumberSections = True }))
214 "" -- "Number sections in LaTeX"
216 "" -- "Number sections in LaTeX"
215
217
218+ , Option "" ["no-wrap"]
219+ (NoArg
220+ (\opt -> return opt { optWrapText = False }))
221+ "" -- "Do not wrap text in output"
222+
216 , Option "" ["toc", "table-of-contents"]
223 , Option "" ["toc", "table-of-contents"]
217 (NoArg
224 (NoArg
218 (\opt -> return opt { optTableOfContents = True }))
225 (\opt -> return opt { optTableOfContents = True }))
@@ -408,6 +415,7 @@ main = do
408 , optIgnoreArgs = ignoreArgs
415 , optIgnoreArgs = ignoreArgs
409 , optStrict = strict
416 , optStrict = strict
410 , optReferenceLinks = referenceLinks
417 , optReferenceLinks = referenceLinks
418+ , optWrapText = wrap
411 } = opts
419 } = opts
412
420
413 if dumpArgs
421 if dumpArgs
@@ -491,7 +499,8 @@ main = do
491 writerIncludeBefore = includeBefore,
499 writerIncludeBefore = includeBefore,
492 writerIncludeAfter = includeAfter,
500 writerIncludeAfter = includeAfter,
493 writerStrictMarkdown = strict,
501 writerStrictMarkdown = strict,
494− writerReferenceLinks = referenceLinks }
502+ writerReferenceLinks = referenceLinks,
503+ writerWrapText = wrap }
495
504
496 (readSources sources) >>= (hPutStrLn output . toUTF8 .
505 (readSources sources) >>= (hPutStrLn output . toUTF8 .
497 (writer writerOptions) .
506 (writer writerOptions) .
src/Text/Pandoc/Shared.hs+25−15
@@ -44,6 +44,7 @@ module Text.Pandoc.Shared (
44 camelCaseToHyphenated,
44 camelCaseToHyphenated,
45 toRomanNumeral,
45 toRomanNumeral,
46 wrapped,
46 wrapped,
47+ wrapIfNeeded,
47 -- * Parsing
48 -- * Parsing
48 (>>~),
49 (>>~),
49 anyLine,
50 anyLine,
@@ -210,6 +211,12 @@ wrapped :: Monad m => ([Inline] -> m Doc) -> [Inline] -> m Doc
210wrapped listWriter sect = (mapM listWriter $ splitBy Space sect) >>=
211wrapped listWriter sect = (mapM listWriter $ splitBy Space sect) >>=
211 return . fsep
212 return . fsep
212
213
214+wrapIfNeeded :: Monad m => WriterOptions -> ([Inline] -> m Doc) ->
215+ [Inline] -> m Doc
216+wrapIfNeeded opts = if writerWrapText opts
217+ then wrapped
218+ else ($)
219+
213--
220--
214-- Parsing
221-- Parsing
215--
222--
@@ -760,23 +767,26 @@ data WriterOptions = WriterOptions
760 , writerIncludeAfter :: String -- ^ String to include after the body
767 , writerIncludeAfter :: String -- ^ String to include after the body
761 , writerStrictMarkdown :: Bool -- ^ Use strict markdown syntax
768 , writerStrictMarkdown :: Bool -- ^ Use strict markdown syntax
762 , writerReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
769 , writerReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
770+ , writerWrapText :: Bool -- ^ Wrap text to line length
763 } deriving Show
771 } deriving Show
764
772
765-- | Default writer options.
773-- | Default writer options.
766defaultWriterOptions :: WriterOptions
774defaultWriterOptions :: WriterOptions
767defaultWriterOptions =
775defaultWriterOptions =
768− WriterOptions { writerStandalone = False,
776+ WriterOptions { writerStandalone = False
769− writerHeader = "",
777+ , writerHeader = ""
770− writerTitlePrefix = "",
778+ , writerTitlePrefix = ""
771− writerTabStop = 4,
779+ , writerTabStop = 4
772− writerTableOfContents = False,
780+ , writerTableOfContents = False
773− writerS5 = False,
781+ , writerS5 = False
774− writerUseASCIIMathML = False,
782+ , writerUseASCIIMathML = False
775− writerASCIIMathMLURL = Nothing,
783+ , writerASCIIMathMLURL = Nothing
776− writerIgnoreNotes = False,
784+ , writerIgnoreNotes = False
777− writerIncremental = False,
785+ , writerIncremental = False
778− writerNumberSections = False,
786+ , writerNumberSections = False
779− writerIncludeBefore = "",
787+ , writerIncludeBefore = ""
780− writerIncludeAfter = "",
788+ , writerIncludeAfter = ""
781− writerStrictMarkdown = False,
789+ , writerStrictMarkdown = False
782− writerReferenceLinks = False }
790+ , writerReferenceLinks = False
791+ , writerWrapText = True
792+ }
src/Text/Pandoc/Writers/Docbook.hs+3−1
@@ -244,7 +244,9 @@ tableItemToDocbook opts tag align width item =
244
244
245-- | Take list of inline elements and return wrapped doc.
245-- | Take list of inline elements and return wrapped doc.
246wrap :: WriterOptions -> [Inline] -> Doc
246wrap :: WriterOptions -> [Inline] -> Doc
247+wrap opts lst = if writerWrapText opts
247−wrap opts lst = fsep $ map (inlinesToDocbook opts) (splitBy Space lst)
248+ then fsep $ map (inlinesToDocbook opts) (splitBy Space lst)
249+ else inlinesToDocbook opts lst
248
250
249-- | Convert a list of inline elements to Docbook.
251-- | Convert a list of inline elements to Docbook.
250inlinesToDocbook :: WriterOptions -> [Inline] -> Doc
252inlinesToDocbook :: WriterOptions -> [Inline] -> Doc
src/Text/Pandoc/Writers/Man.hs+3−2
@@ -115,9 +115,10 @@ blockToMan :: WriterOptions -- ^ Options
115 -> Block -- ^ Block element
115 -> Block -- ^ Block element
116 -> State WriterState Doc
116 -> State WriterState Doc
117blockToMan opts Null = return empty
117blockToMan opts Null = return empty
118−blockToMan opts (Plain inlines) = wrapped (inlineListToMan opts) inlines
118+blockToMan opts (Plain inlines) =
119+ wrapIfNeeded opts (inlineListToMan opts) inlines
119blockToMan opts (Para inlines) = do
120blockToMan opts (Para inlines) = do
120− contents <- wrapped (inlineListToMan opts) inlines
121+ contents <- wrapIfNeeded opts (inlineListToMan opts) inlines
121 return $ text ".PP" $$ contents
122 return $ text ".PP" $$ contents
122blockToMan opts (RawHtml str) = return $ text str
123blockToMan opts (RawHtml str) = return $ text str
123blockToMan opts HorizontalRule = return $ text $ ".PP\n * * * * *"
124blockToMan opts HorizontalRule = return $ text $ ".PP\n * * * * *"
src/Text/Pandoc/Writers/Markdown.hs+1−1
@@ -162,7 +162,7 @@ wrappedMarkdown opts inlines = do
162 let chunks' = if null chunks
162 let chunks' = if null chunks
163 then []
163 then []
164 else (map (++ [Str " "]) $ init chunks) ++ [last chunks]
164 else (map (++ [Str " "]) $ init chunks) ++ [last chunks]
165− lns <- mapM (wrapped (inlineListToMarkdown opts)) chunks'
165+ lns <- mapM (wrapIfNeeded opts (inlineListToMarkdown opts)) chunks'
166 return $ vcat lns
166 return $ vcat lns
167
167
168-- | Convert Pandoc block element to markdown.
168-- | Convert Pandoc block element to markdown.
src/Text/Pandoc/Writers/RST.hs+2−3
@@ -109,9 +109,8 @@ pictToRST opts (label, (src, _)) = do
109
109
110-- | Take list of inline elements and return wrapped doc.
110-- | Take list of inline elements and return wrapped doc.
111wrappedRST :: WriterOptions -> [Inline] -> State WriterState Doc
111wrappedRST :: WriterOptions -> [Inline] -> State WriterState Doc
112−wrappedRST opts inlines =
112+wrappedRST opts inlines = mapM (wrapIfNeeded opts (inlineListToRST opts))
113− mapM (wrapped (inlineListToRST opts)) (splitBy LineBreak inlines) >>=
113+ (splitBy LineBreak inlines) >>= return . vcat
114− return . vcat
115
114
116-- | Escape special characters for RST.
115-- | Escape special characters for RST.
117escapeString :: String -> String
116escapeString :: String -> String