git.iko.soy/typeable/pandoc
on master help sign in
Ms writer: Hyperlink table of contents and other improvements.
commit0eb62f03fe5cc65534a30bb1f66362e85992c55a authorJohn MacFarlane <jgm@berkeley.edu> dateSun 26 Mar 2017, 20:01 (10 years ago) parent0ae448e
3 files changed+46−13
data/templates/default.ms+11−1 src/Text/Pandoc/Writers/Ms.hs+21−9 test/writer.ms+14−3
data/templates/default.ms+11−1
@@ -42,6 +42,17 @@
4242.ds PDFHREF.COLOUR 0.35 0.00 0.60
4343.\" border for links (default none)
4444.ds PDFHREF.BORDER 0 0 0
45+.\" point size difference between heading levels
46+.nr PSINCR 1p
47+.\" heading level above which point size no longer changes
48+.nr GROWPS 2
49+.\" comment these out if you want a dot after section numbers:
50+.als SN SN-NO-DOT
51+.als SN-STYLE SN-NO-DOT
52+.\" pdf outline fold level
53+.nr PDFOUTLINE.FOLDLEVEL 3
54+.\" start out in outline view
55+.pdfview /PageMode /UseOutlines
4556.\" ***************************************************************
4657.\" PDF metadata
4758.pdfinfo /Title "$title-meta$"
@@ -85,7 +96,6 @@ $endfor$
8596.1C
8697$body$
8798$if(toc)$
88−$toc$
8999.TC
90100$endif$
91101$for(include-after)$
src/Text/Pandoc/Writers/Ms.hs+21−9
@@ -116,7 +116,7 @@ pandocToMs opts (Pandoc meta blocks) = do
116116-- | Association list of characters to escape.
117117msEscapes :: Map.Map Char String
118118msEscapes = Map.fromList $
119− [ ('\160', "\\ ")
119+ [ ('\160', "\\~")
120120 , ('\'', "\\[aq]")
121121 , ('`', "\\`")
122122 , ('\8217', "'")
@@ -245,22 +245,34 @@ blockToMs _ HorizontalRule = do
245245blockToMs opts (Header level (ident,classes,_) inlines) = do
246246 setFirstPara
247247 contents <- inlineListToMs' opts $ map breakToSpace inlines
248+ let (heading, secnum) = if writerNumberSections opts &&
249+ "unnumbered" `notElem` classes
250+ then (".NH", "\\*[SN]")
251+ else (".SH", "")
248252 let anchor = if null ident
249253 then empty
250254 else nowrap $
251255 text ".pdfhref M " <> doubleQuotes (text ident)
252256 let bookmark = text ".pdfhref O " <> text (show level ++ " ") <>
253− doubleQuotes (text (escapeString (stringify inlines)))
257+ doubleQuotes (text $ secnum ++
258+ (if null secnum
259+ then ""
260+ else " ") ++
261+ escapeString (stringify inlines))
262+ let backlink = nowrap (text ".pdfhref L -D " <>
263+ doubleQuotes (text ident) <> space <> text "\\") <> cr <>
264+ text " -- "
254265 let tocEntry = if writerTableOfContents opts &&
255266 level <= writerTOCDepth opts
256− then text ".XS" $$
257− (text (replicate level '\t') <> contents) $$
258− text ".XE"
267+ then text ".XS"
268+ $$ backlink <> doubleQuotes (
269+ nowrap ((text (replicate level '\t') <>
270+ (if null secnum
271+ then empty
272+ else text secnum <> text "\\~\\~")
273+ <> contents)))
274+ $$ text ".XE"
259275 else empty
260− let heading = if writerNumberSections opts &&
261− "unnumbered" `notElem` classes
262− then ".NH"
263− else ".SH"
264276 modify $ \st -> st{ stFirstPara = True }
265277 return $ (text heading <> space <> text (show level)) $$
266278 contents $$
test/writer.ms+14−3
@@ -42,6 +42,17 @@
4242.ds PDFHREF.COLOUR 0.35 0.00 0.60
4343.\" border for links (default none)
4444.ds PDFHREF.BORDER 0 0 0
45+.\" point size difference between heading levels
46+.nr PSINCR 1p
47+.\" heading level above which point size no longer changes
48+.nr GROWPS 2
49+.\" comment these out if you want a dot after section numbers:
50+.als SN SN-NO-DOT
51+.als SN-STYLE SN-NO-DOT
52+.\" pdf outline fold level
53+.nr PDFOUTLINE.FOLDLEVEL 3
54+.\" start out in outline view
55+.pdfview /PageMode /UseOutlines
4556.\" ***************************************************************
4657.\" PDF metadata
4758.pdfinfo /Title "Pandoc Test Suite"
@@ -427,7 +438,7 @@ Nested.
427438.LP
428439Should not be a list item:
429440.PP
430−M.A.\ 2007
441+M.A.\~2007
431442.PP
432443B.
433444Williams
@@ -643,9 +654,9 @@ This is code: \f[C]>\f[], \f[C]$\f[], \f[C]\\\f[], \f[C]\\$\f[],
643654.PP
644655\m[strikecolor]This is \f[I]strikeout\f[].\m[]
645656.PP
646−Superscripts: a\*{bc\*}d a\*{\f[I]hello\f[]\*} a\*{hello\ there\*}.
657+Superscripts: a\*{bc\*}d a\*{\f[I]hello\f[]\*} a\*{hello\~there\*}.
647658.PP
648−Subscripts: H\*<2\*>O, H\*<23\*>O, H\*<many\ of\ them\*>O.
659+Subscripts: H\*<2\*>O, H\*<23\*>O, H\*<many\~of\~them\*>O.
649660.PP
650661These should not be superscripts or subscripts,
651662because of the unescaped spaces: a\[ha]b c\[ha]d, a\[ti]b c\[ti]d.