git.iko.soy/typeable/pandoc
on master help sign in
Added a writer option for wrapped text and a command-line option

'--no-wrap', which disables text wrapping. (Resolves Issue #26.) + Added support for '--no-wrap' to Main.hs. + Added wrapIfNeeded function to Text.Pandoc.Shared. + Use wrapIfNeeded instead of wrapped in the RST, Man, Docbook, and Markdown writers. + Note: Not yet implemented in HTML, LaTeX, or ConTeXt writers. No documentation yet. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1034 788f1e2b-df1e-0410-8736-df70ead52e1b

commit5b888e8b3be01aebb8ecf7ba4ebee61d2a3d3f31 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateThu 27 Sep 2007, 01:23 (19 years ago) parentfa45b97
6 files changed+44−23
src/Main.hs+10−1 src/Text/Pandoc/Shared.hs+25−15 src/Text/Pandoc/Writers/Docbook.hs+3−1 src/Text/Pandoc/Writers/Man.hs+3−2 src/Text/Pandoc/Writers/Markdown.hs+1−1 src/Text/Pandoc/Writers/RST.hs+2−3
src/Main.hs+10−1
@@ -107,6 +107,7 @@ data Opt = Opt
107107 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
108108 , optStrict :: Bool -- ^ Use strict markdown syntax
109109 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
110+ , optWrapText :: Bool -- ^ Wrap text
110111 }
111112
112113-- | Defaults for command-line options.
@@ -135,6 +136,7 @@ defaultOpts = Opt
135136 , optIgnoreArgs = False
136137 , optStrict = False
137138 , optReferenceLinks = False
139+ , optWrapText = True
138140 }
139141
140142-- | A list of functions, each transforming the options data structure
@@ -213,6 +215,11 @@ options =
213215 (\opt -> return opt { optNumberSections = True }))
214216 "" -- "Number sections in LaTeX"
215217
218+ , Option "" ["no-wrap"]
219+ (NoArg
220+ (\opt -> return opt { optWrapText = False }))
221+ "" -- "Do not wrap text in output"
222+
216223 , Option "" ["toc", "table-of-contents"]
217224 (NoArg
218225 (\opt -> return opt { optTableOfContents = True }))
@@ -408,6 +415,7 @@ main = do
408415 , optIgnoreArgs = ignoreArgs
409416 , optStrict = strict
410417 , optReferenceLinks = referenceLinks
418+ , optWrapText = wrap
411419 } = opts
412420
413421 if dumpArgs
@@ -491,7 +499,8 @@ main = do
491499 writerIncludeBefore = includeBefore,
492500 writerIncludeAfter = includeAfter,
493501 writerStrictMarkdown = strict,
494− writerReferenceLinks = referenceLinks }
502+ writerReferenceLinks = referenceLinks,
503+ writerWrapText = wrap }
495504
496505 (readSources sources) >>= (hPutStrLn output . toUTF8 .
497506 (writer writerOptions) .
src/Text/Pandoc/Shared.hs+25−15
@@ -44,6 +44,7 @@ module Text.Pandoc.Shared (
4444 camelCaseToHyphenated,
4545 toRomanNumeral,
4646 wrapped,
47+ wrapIfNeeded,
4748 -- * Parsing
4849 (>>~),
4950 anyLine,
@@ -210,6 +211,12 @@ wrapped :: Monad m => ([Inline] -> m Doc) -> [Inline] -> m Doc
210211wrapped listWriter sect = (mapM listWriter $ splitBy Space sect) >>=
211212 return . fsep
212213
214+wrapIfNeeded :: Monad m => WriterOptions -> ([Inline] -> m Doc) ->
215+ [Inline] -> m Doc
216+wrapIfNeeded opts = if writerWrapText opts
217+ then wrapped
218+ else ($)
219+
213220--
214221-- Parsing
215222--
@@ -760,23 +767,26 @@ data WriterOptions = WriterOptions
760767 , writerIncludeAfter :: String -- ^ String to include after the body
761768 , writerStrictMarkdown :: Bool -- ^ Use strict markdown syntax
762769 , writerReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
770+ , writerWrapText :: Bool -- ^ Wrap text to line length
763771 } deriving Show
764772
765773-- | Default writer options.
766774defaultWriterOptions :: WriterOptions
767775defaultWriterOptions =
768− WriterOptions { writerStandalone = False,
769− writerHeader = "",
770− writerTitlePrefix = "",
771− writerTabStop = 4,
772− writerTableOfContents = False,
773− writerS5 = False,
774− writerUseASCIIMathML = False,
775− writerASCIIMathMLURL = Nothing,
776− writerIgnoreNotes = False,
777− writerIncremental = False,
778− writerNumberSections = False,
779− writerIncludeBefore = "",
780− writerIncludeAfter = "",
781− writerStrictMarkdown = False,
782− writerReferenceLinks = False }
776+ WriterOptions { writerStandalone = False
777+ , writerHeader = ""
778+ , writerTitlePrefix = ""
779+ , writerTabStop = 4
780+ , writerTableOfContents = False
781+ , writerS5 = False
782+ , writerUseASCIIMathML = False
783+ , writerASCIIMathMLURL = Nothing
784+ , writerIgnoreNotes = False
785+ , writerIncremental = False
786+ , writerNumberSections = False
787+ , writerIncludeBefore = ""
788+ , writerIncludeAfter = ""
789+ , writerStrictMarkdown = 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 =
244244
245245-- | Take list of inline elements and return wrapped doc.
246246wrap :: WriterOptions -> [Inline] -> Doc
247−wrap opts lst = fsep $ map (inlinesToDocbook opts) (splitBy Space lst)
247+wrap opts lst = if writerWrapText opts
248+ then fsep $ map (inlinesToDocbook opts) (splitBy Space lst)
249+ else inlinesToDocbook opts lst
248250
249251-- | Convert a list of inline elements to Docbook.
250252inlinesToDocbook :: WriterOptions -> [Inline] -> Doc
src/Text/Pandoc/Writers/Man.hs+3−2
@@ -115,9 +115,10 @@ blockToMan :: WriterOptions -- ^ Options
115115 -> Block -- ^ Block element
116116 -> State WriterState Doc
117117blockToMan opts Null = return empty
118−blockToMan opts (Plain inlines) = wrapped (inlineListToMan opts) inlines
118+blockToMan opts (Plain inlines) =
119+ wrapIfNeeded opts (inlineListToMan opts) inlines
119120blockToMan opts (Para inlines) = do
120− contents <- wrapped (inlineListToMan opts) inlines
121+ contents <- wrapIfNeeded opts (inlineListToMan opts) inlines
121122 return $ text ".PP" $$ contents
122123blockToMan opts (RawHtml str) = return $ text str
123124blockToMan opts HorizontalRule = return $ text $ ".PP\n * * * * *"
src/Text/Pandoc/Writers/Markdown.hs+1−1
@@ -162,7 +162,7 @@ wrappedMarkdown opts inlines = do
162162 let chunks' = if null chunks
163163 then []
164164 else (map (++ [Str " "]) $ init chunks) ++ [last chunks]
165− lns <- mapM (wrapped (inlineListToMarkdown opts)) chunks'
165+ lns <- mapM (wrapIfNeeded opts (inlineListToMarkdown opts)) chunks'
166166 return $ vcat lns
167167
168168-- | Convert Pandoc block element to markdown.
src/Text/Pandoc/Writers/RST.hs+2−3
@@ -109,9 +109,8 @@ pictToRST opts (label, (src, _)) = do
109109
110110-- | Take list of inline elements and return wrapped doc.
111111wrappedRST :: WriterOptions -> [Inline] -> State WriterState Doc
112−wrappedRST opts inlines =
113− mapM (wrapped (inlineListToRST opts)) (splitBy LineBreak inlines) >>=
114− return . vcat
112+wrappedRST opts inlines = mapM (wrapIfNeeded opts (inlineListToRST opts))
113+ (splitBy LineBreak inlines) >>= return . vcat
115114
116115-- | Escape special characters for RST.
117116escapeString :: String -> String