git.iko.soy/typeable/pandoc
on master help sign in
Man writer: updated to use Pretty.
commitfd07db16e901720f1c5a9574786fdb6b097311cf authorJohn MacFarlane <jgm@berkeley.edu> dateWed 22 Dec 2010, 00:21 (16 years ago) parentc904024
3 files changed+42−46
src/Text/Pandoc/Writers/Man.hs+22−18 tests/tables.man+1−1 tests/writer.man+19−27
src/Text/Pandoc/Writers/Man.hs+22−18
@@ -35,7 +35,7 @@ import Text.Pandoc.Shared
3535import Text.Pandoc.Readers.TeXMath
3636import Text.Printf ( printf )
3737import Data.List ( isPrefixOf, intersperse, intercalate )
38−import Text.PrettyPrint.HughesPJ hiding ( Str )
38+import Text.Pandoc.Pretty
3939import Control.Monad.State
4040
4141type Notes = [[Block]]
@@ -52,27 +52,31 @@ pandocToMan opts (Pandoc (Meta title authors date) blocks) = do
5252 titleText <- inlineListToMan opts title
5353 authors' <- mapM (inlineListToMan opts) authors
5454 date' <- inlineListToMan opts date
55− let (cmdName, rest) = break (== ' ') $ render titleText
55+ let colwidth = if writerWrapText opts
56+ then Just $ writerColumns opts
57+ else Nothing
58+ let render' = render colwidth
59+ let (cmdName, rest) = break (== ' ') $ render' titleText
5660 let (title', section) = case reverse cmdName of
5761 (')':d:'(':xs) | d `elem` ['0'..'9'] ->
5862 (text (reverse xs), char d)
59− xs -> (text (reverse xs), doubleQuotes empty)
63+ xs -> (text (reverse xs), doubleQuotes empty)
6064 let description = hsep $
6165 map (doubleQuotes . text . removeLeadingTrailingSpace) $
6266 splitBy (== '|') rest
6367 body <- blockListToMan opts blocks
6468 notes <- liftM stNotes get
6569 notes' <- notesToMan opts (reverse notes)
66− let main = render $ body $$ notes' $$ text ""
70+ let main = render' $ body $$ notes' $$ text ""
6771 hasTables <- liftM stHasTables get
6872 let context = writerVariables opts ++
6973 [ ("body", main)
70− , ("title", render title')
71− , ("section", render section)
72− , ("date", render date')
73− , ("description", render description) ] ++
74+ , ("title", render' title')
75+ , ("section", render' section)
76+ , ("date", render' date')
77+ , ("description", render' description) ] ++
7478 [ ("has-tables", "yes") | hasTables ] ++
75− [ ("author", render a) | a <- authors' ]
79+ [ ("author", render' a) | a <- authors' ]
7680 if writerStandalone opts
7781 then return $ renderTemplate context $ writerTemplate opts
7882 else return main
@@ -89,7 +93,7 @@ notesToMan opts notes =
8993noteToMan :: WriterOptions -> Int -> [Block] -> State WriterState Doc
9094noteToMan opts num note = do
9195 contents <- blockListToMan opts note
92− let marker = text "\n.SS [" <> text (show num) <> char ']'
96+ let marker = cr <> text ".SS " <> brackets (text (show num))
9397 return $ marker $$ contents
9498
9599-- | Association list of characters to escape.
@@ -136,14 +140,13 @@ blockToMan :: WriterOptions -- ^ Options
136140 -> State WriterState Doc
137141blockToMan _ Null = return empty
138142blockToMan opts (Plain inlines) =
139− liftM vcat $ mapM (wrapIfNeeded opts (inlineListToMan opts)) $
140− splitSentences inlines
143+ liftM vcat $ mapM (inlineListToMan opts) $ splitSentences inlines
141144blockToMan opts (Para inlines) = do
142− contents <- liftM vcat $ mapM (wrapIfNeeded opts (inlineListToMan opts)) $
145+ contents <- liftM vcat $ mapM (inlineListToMan opts) $
143146 splitSentences inlines
144147 return $ text ".PP" $$ contents
145148blockToMan _ (RawHtml _) = return empty
146−blockToMan _ HorizontalRule = return $ text $ ".PP\n * * * * *"
149+blockToMan _ HorizontalRule = return $ text ".PP" $$ text " * * * * *"
147150blockToMan opts (Header level inlines) = do
148151 contents <- inlineListToMan opts inlines
149152 let heading = case level of
@@ -256,7 +259,7 @@ definitionListItemToMan opts (label, defs) = do
256259 mapM (\item -> blockToMan opts item) rest
257260 first' <- blockToMan opts first
258261 return $ first' $$ text ".RS" $$ rest' $$ text ".RE"
259− return $ text ".TP\n.B " <> labelText $+$ contents
262+ return $ text ".TP" $$ text ".B " <> labelText $$ contents
260263
261264-- | Convert list of Pandoc block elements to man.
262265blockListToMan :: WriterOptions -- ^ Options
@@ -309,11 +312,12 @@ inlineToMan _ (Str str) = return $ text $ escapeString str
309312inlineToMan opts (Math InlineMath str) = inlineListToMan opts $ readTeXMath str
310313inlineToMan opts (Math DisplayMath str) = do
311314 contents <- inlineListToMan opts $ readTeXMath str
312− return $ text ".RS" $$ contents $$ text ".RE"
315+ return $ cr <> text ".RS" $$ contents $$ text ".RE"
313316inlineToMan _ (TeX _) = return empty
314317inlineToMan _ (HtmlInline _) = return empty
315−inlineToMan _ (LineBreak) = return $ text "\n.PD 0\n.P\n.PD\n"
316−inlineToMan _ Space = return $ char ' '
318+inlineToMan _ (LineBreak) = return $
319+ cr <> text ".PD 0" $$ text ".P" $$ text ".PD" <> cr
320+inlineToMan _ Space = return space
317321inlineToMan opts (Link txt (src, _)) = do
318322 linktext <- inlineListToMan opts txt
319323 let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
tests/tables.man+1−1
@@ -264,4 +264,4 @@ T}@T{
264264Here\[aq]s another one.
265265Note the blank line between rows.
266266T}
267−.TE
267+.TE
tests/writer.man+19−27
@@ -26,8 +26,8 @@ Here's a regular paragraph.
2626In Markdown 1.0.0 and earlier.
2727Version 8.
2828This line turns into a list item.
29−Because a hard-wrapped line in the middle of a paragraph looked
30−like a list item.
29+Because a hard-wrapped line in the middle of a paragraph looked like a list
30+item.
3131.PP
3232Here's one with a bullet.
3333* criminey.
@@ -531,8 +531,8 @@ Superscripts: a^bc^d a^\f[I]hello\f[]^ a^hello\ there^.
531531.PP
532532Subscripts: H~2~O, H~23~O, H~many\ of\ them~O.
533533.PP
534−These should not be superscripts or subscripts, because of the
535−unescaped spaces: a^b c^d, a~b c~d.
534+These should not be superscripts or subscripts, because of the unescaped
535+spaces: a^b c^d, a~b c~d.
536536.PP
537537 * * * * *
538538.SH Smart quotes, ellipses, dashes
@@ -547,8 +547,8 @@ So is `pine.'
547547.PP
548548`He said, \[lq]I want to go.\[rq]' Were you alive in the 70's?
549549.PP
550−Here is some quoted `\f[C]code\f[]' and a
551−\[lq]quoted link (http://example.com/?foo=1&bar=2)\[rq].
550+Here is some quoted `\f[C]code\f[]' and a \[lq]quoted
551+link (http://example.com/?foo=1&bar=2)\[rq].
552552.PP
553553Some dashes: one\[em]two \[em] three\[em]four \[em] five.
554554.PP
@@ -641,7 +641,7 @@ Greater-than: >
641641.PP
642642Hash: #
643643.PP
644−Period: \&.
644+Period: .
645645.PP
646646Bang: !
647647.PP
@@ -701,11 +701,9 @@ Foo bar (/url/).
701701Foo biz (/url/).
702702.SS With ampersands
703703.PP
704−Here's a
705−link with an ampersand in the URL (http://example.com/?foo=1&bar=2).
704+Here's a link with an ampersand in the URL (http://example.com/?foo=1&bar=2).
706705.PP
707−Here's a link with an amersand in the link text:
708−AT&T (http://att.com/).
706+Here's a link with an amersand in the link text: AT&T (http://att.com/).
709707.PP
710708Here's an inline link (/script?foo=1&bar=2).
711709.PP
@@ -746,9 +744,9 @@ Here is a movie [IMAGE: movie (movie.jpg)] icon.
746744 * * * * *
747745.SH Footnotes
748746.PP
749−Here is a footnote reference,[1] and another.[2] This should
750−\f[I]not\f[] be a footnote reference, because it contains a
751−space.[^my note] Here is an inline note.[3]
747+Here is a footnote reference,[1] and another.[2] This should \f[I]not\f[] be a
748+footnote reference, because it contains a space.[^my note] Here is an inline
749+note.[3]
752750.RS
753751.PP
754752Notes can go in quotes.[4]
@@ -756,23 +754,20 @@ Notes can go in quotes.[4]
756754.IP "1." 3
757755And in list items.[5]
758756.PP
759−This paragraph should not be part of the note, as it is not
760−indented.
757+This paragraph should not be part of the note, as it is not indented.
761758.SH NOTES
762−
763759.SS [1]
764760.PP
765761Here is the footnote.
766762It can go anywhere after the footnote reference.
767763It need not be placed at the end of the document.
768−
769764.SS [2]
770765.PP
771766Here's the long note.
772767This one contains multiple blocks.
773768.PP
774−Subsequent blocks are indented to show that they belong to the
775−footnote (as with list items).
769+Subsequent blocks are indented to show that they belong to the footnote (as
770+with list items).
776771.IP
777772.nf
778773\f[C]
@@ -780,19 +775,16 @@ footnote (as with list items).
780775\f[]
781776.fi
782777.PP
783−If you want, you can indent every line, but you can also be lazy
784−and just indent the first line of each block.
785−
778+If you want, you can indent every line, but you can also be lazy and just
779+indent the first line of each block.
786780.SS [3]
787781.PP
788782This is \f[I]easier\f[] to type.
789−Inline notes may contain links (http://google.com) and \f[C]]\f[]
790−verbatim characters, as well as [bracketed text].
791−
783+Inline notes may contain links (http://google.com) and \f[C]]\f[] verbatim
784+characters, as well as [bracketed text].
792785.SS [4]
793786.PP
794787In quote.
795−
796788.SS [5]
797789.PP
798790In list.