git.iko.soy/typeable/pandoc
on master help sign in
Ms writer: font improvements.

* Use `\f[R]` rather than `\f[]` to reset. The latter returns to the previous font, which gives unintended results in some cases. * Use `\f[BI]` and `\f[CB]` in headers, instead of `\f[I]` and `\f[C]`, since the header font is automatically bold. * Use `\f[CB]` rather than `\f[BC]` for monospace bold. Closes #4552.

commit8ca012f139d09d77a878e049cf9972efc026674e authorJohn MacFarlane <jgm@berkeley.edu> dateSun 15 Apr 2018, 22:44 (9 years ago) parent939985e
2 files changed+39−28
src/Text/Pandoc/Writers/Ms.hs+14−3 test/writer.ms+25−25
src/Text/Pandoc/Writers/Ms.hs+14−3
@@ -40,7 +40,7 @@ module Text.Pandoc.Writers.Ms ( writeMs ) where
4040import Prelude
4141import Control.Monad.State.Strict
4242import Data.Char (isLower, isUpper, toUpper, ord)
43−import Data.List (intercalate, intersperse, sort)
43+import Data.List (intercalate, intersperse)
4444import qualified Data.Map as Map
4545import Data.Maybe (catMaybes, fromMaybe)
4646import Data.Text (Text)
@@ -68,6 +68,7 @@ data WriterState = WriterState { stHasInlineMath :: Bool
6868 , stNotes :: [Note]
6969 , stSmallCaps :: Bool
7070 , stHighlighting :: Bool
71+ , stInHeader :: Bool
7172 , stFontFeatures :: Map.Map Char Bool
7273 }
7374
@@ -77,6 +78,7 @@ defaultWriterState = WriterState{ stHasInlineMath = False
7778 , stNotes = []
7879 , stSmallCaps = False
7980 , stHighlighting = False
81+ , stInHeader = False
8082 , stFontFeatures = Map.fromList [
8183 ('I',False)
8284 , ('B',False)
@@ -264,7 +266,9 @@ blockToMs _ HorizontalRule = do
264266 return $ text ".HLINE"
265267blockToMs opts (Header level (ident,classes,_) inlines) = do
266268 setFirstPara
269+ modify $ \st -> st{ stInHeader = True }
267270 contents <- inlineListToMs' opts $ map breakToSpace inlines
271+ modify $ \st -> st{ stInHeader = False }
268272 let (heading, secnum) = if writerNumberSections opts &&
269273 "unnumbered" `notElem` classes
270274 then (".NH", "\\*[SN]")
@@ -559,8 +563,15 @@ handleNote opts bs = do
559563fontChange :: PandocMonad m => MS m Doc
560564fontChange = do
561565 features <- gets stFontFeatures
562− let filling = sort [c | (c,True) <- Map.toList features]
563− return $ text $ "\\f[" ++ filling ++ "]"
566+ inHeader <- gets stInHeader
567+ let filling = ['C' | fromMaybe False $ Map.lookup 'C' features] ++
568+ ['B' | inHeader ||
569+ fromMaybe False (Map.lookup 'B' features)] ++
570+ ['I' | fromMaybe False $ Map.lookup 'I' features]
571+ return $
572+ if null filling
573+ then text "\\f[R]"
574+ else text $ "\\f[" ++ filling ++ "]"
564575
565576withFontFeature :: PandocMonad m => Char -> MS m Doc -> MS m Doc
566577withFontFeature c action = do
test/writer.ms+25−25
@@ -86,7 +86,7 @@ Level 2 with an \c
8686.pdfhref O 2 "Level 2 with an embedded link"
8787.pdfhref M "level-2-with-an-embedded-link"
8888.SH 3
89−Level 3 with \f[I]emphasis\f[]
89+Level 3 with \f[BI]emphasis\f[B]
9090.pdfhref O 3 "Level 3 with emphasis"
9191.pdfhref M "level-3-with-emphasis"
9292.SH 4
@@ -102,7 +102,7 @@ Level 1
102102.pdfhref O 1 "Level 1"
103103.pdfhref M "level-1"
104104.SH 2
105−Level 2 with \f[I]emphasis\f[]
105+Level 2 with \f[BI]emphasis\f[B]
106106.pdfhref O 2 "Level 2 with emphasis"
107107.pdfhref M "level-2-with-emphasis"
108108.SH 3
@@ -481,13 +481,13 @@ yellow fruit
481481.RE
482482.LP
483483Multiple blocks with italics:
484−.IP "\f[I]apple\f[]"
484+.IP "\f[I]apple\f[R]"
485485red fruit
486486.RS
487487.PP
488488contains seeds, crisp, pleasant to taste
489489.RE
490−.IP "\f[I]orange\f[]"
490+.IP "\f[I]orange\f[R]"
491491orange fruit
492492.RS
493493.IP
@@ -564,8 +564,8 @@ foo
564564bar
565565.LP
566566Interpreted markdown in a table:
567−This is \f[I]emphasized\f[]
568−And this is \f[B]strong\f[]
567+This is \f[I]emphasized\f[R]
568+And this is \f[B]strong\f[R]
569569.PP
570570Here’s a simple block:
571571.LP
@@ -621,29 +621,29 @@ Inline Markup
621621.pdfhref O 1 "Inline Markup"
622622.pdfhref M "inline-markup"
623623.LP
624−This is \f[I]emphasized\f[], and so \f[I]is this\f[].
624+This is \f[I]emphasized\f[R], and so \f[I]is this\f[R].
625625.PP
626−This is \f[B]strong\f[], and so \f[B]is this\f[].
626+This is \f[B]strong\f[R], and so \f[B]is this\f[R].
627627.PP
628628An \f[I]\c
629629.pdfhref W -D "/url" -A "\c" \
630630 -- "emphasized link"
631−\&\f[].
631+\&\f[R].
632632.PP
633−\f[B]\f[BI]This is strong and em.\f[B]\f[]
633+\f[B]\f[BI]This is strong and em.\f[B]\f[R]
634634.PP
635−So is \f[B]\f[BI]this\f[B]\f[] word.
635+So is \f[B]\f[BI]this\f[B]\f[R] word.
636636.PP
637−\f[B]\f[BI]This is strong and em.\f[B]\f[]
637+\f[B]\f[BI]This is strong and em.\f[B]\f[R]
638638.PP
639−So is \f[B]\f[BI]this\f[B]\f[] word.
639+So is \f[B]\f[BI]this\f[B]\f[R] word.
640640.PP
641−This is code: \f[C]>\f[], \f[C]$\f[], \f[C]\\\f[], \f[C]\\$\f[],
642−\f[C]<html>\f[].
641+This is code: \f[C]>\f[R], \f[C]$\f[R], \f[C]\\\f[R], \f[C]\\$\f[R],
642+\f[C]<html>\f[R].
643643.PP
644−\m[strikecolor]This is \f[I]strikeout\f[].\m[]
644+\m[strikecolor]This is \f[I]strikeout\f[R].\m[]
645645.PP
646−Superscripts: a\*{bc\*}d a\*{\f[I]hello\f[]\*} a\*{hello\~there\*}.
646+Superscripts: a\*{bc\*}d a\*{\f[I]hello\f[R]\*} a\*{hello\~there\*}.
647647.PP
648648Subscripts: H\*<2\*>O, H\*<23\*>O, H\*<many\~of\~them\*>O.
649649.PP
@@ -665,7 +665,7 @@ So is `pine.'
665665.PP
666666`He said, \[lq]I want to go.\[rq]' Were you alive in the 70’s?
667667.PP
668−Here is some quoted `\f[C]code\f[]' and a \[lq]\c
668+Here is some quoted `\f[C]code\f[R]' and a \[lq]\c
669669.pdfhref W -D "http://example.com/?foo=1&bar=2" -A "\c" \
670670 -- "quoted link"
671671\&\[rq].
@@ -701,15 +701,15 @@ Here’s one that has a line break in it: @alpha + omega times x sup 2@.
701701.LP
702702These shouldn’t be math:
703703.IP \[bu] 3
704−To get the famous equation, write \f[C]$e\ =\ mc\[ha]2$\f[].
704+To get the famous equation, write \f[C]$e\ =\ mc\[ha]2$\f[R].
705705.IP \[bu] 3
706−$22,000 is a \f[I]lot\f[] of money.
706+$22,000 is a \f[I]lot\f[R] of money.
707707So is $34,000.
708708(It worked if \[lq]lot\[rq] is emphasized.)
709709.IP \[bu] 3
710710Shoes ($20) and socks ($5).
711711.IP \[bu] 3
712−Escaped \f[C]$\f[]: $73 \f[I]this should be emphasized\f[] 23$.
712+Escaped \f[C]$\f[R]: $73 \f[I]this should be emphasized\f[R] 23$.
713713.LP
714714Here’s a LaTeX table:
715715.HLINE
@@ -932,7 +932,7 @@ Blockquoted: \c
932932\&
933933.RE
934934.LP
935−Auto-links should not occur here: \f[C]<http://example.com/>\f[]
935+Auto-links should not occur here: \f[C]<http://example.com/>\f[R]
936936.IP
937937.nf
938938\f[C]
@@ -979,14 +979,14 @@ with list items).
979979If you want, you can indent every line, but you can also be lazy and just
980980indent the first line of each block.
981981.FE
982−This should \f[I]not\f[] be a footnote reference, because it contains a
982+This should \f[I]not\f[R] be a footnote reference, because it contains a
983983space.[\[ha]my note] Here is an inline note.\**
984984.FS
985−This is \f[I]easier\f[] to type.
985+This is \f[I]easier\f[R] to type.
986986Inline notes may contain \c
987987.pdfhref W -D "http://google.com" -A "\c" \
988988 -- "links"
989−\& and \f[C]]\f[] verbatim characters, as well as [bracketed text].
989+\& and \f[C]]\f[R] verbatim characters, as well as [bracketed text].
990990.FE
991991.RS
992992.LP