git.iko.soy/typeable/pandoc
on master help sign in
Ms writer: Add PDF outline bookmarks.
commitbd99d9f6affedd476d5fe14bef267197cb3e5f55 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 26 Mar 2017, 18:06 (10 years ago) parent5354b44
2 files changed+34
src/Text/Pandoc/Writers/Ms.hs+3 test/writer.ms+31
src/Text/Pandoc/Writers/Ms.hs+3
@@ -249,6 +249,8 @@ blockToMs opts (Header level (ident,classes,_) inlines) = do
249249 then empty
250250 else nowrap $
251251 text ".pdfhref M " <> doubleQuotes (text ident)
252+ let bookmark = text ".pdfhref O " <> text (show level ++ " ") <>
253+ doubleQuotes (text (escapeString (stringify inlines)))
252254 let tocEntry = if writerTableOfContents opts &&
253255 level <= writerTOCDepth opts
254256 then text ".XS" $$
@@ -262,6 +264,7 @@ blockToMs opts (Header level (ident,classes,_) inlines) = do
262264 modify $ \st -> st{ stFirstPara = True }
263265 return $ (text heading <> space <> text (show level)) $$
264266 contents $$
267+ bookmark $$
265268 anchor $$
266269 tocEntry
267270blockToMs _ (CodeBlock _ str) = do
test/writer.ms+31
@@ -66,41 +66,51 @@ John Gruber's markdown test suite.
6666.HLINE
6767.SH 1
6868Headers
69+.pdfhref O 1 "Headers"
6970.pdfhref M "headers"
7071.SH 2
7172Level 2 with an \c
7273.pdfhref W -D "/url" -A "\c" \
7374 -- "embedded link"
7475\&
76+.pdfhref O 2 "Level 2 with an embedded link"
7577.pdfhref M "level-2-with-an-embedded-link"
7678.SH 3
7779Level 3 with \f[I]emphasis\f[]
80+.pdfhref O 3 "Level 3 with emphasis"
7881.pdfhref M "level-3-with-emphasis"
7982.SH 4
8083Level 4
84+.pdfhref O 4 "Level 4"
8185.pdfhref M "level-4"
8286.SH 5
8387Level 5
88+.pdfhref O 5 "Level 5"
8489.pdfhref M "level-5"
8590.SH 1
8691Level 1
92+.pdfhref O 1 "Level 1"
8793.pdfhref M "level-1"
8894.SH 2
8995Level 2 with \f[I]emphasis\f[]
96+.pdfhref O 2 "Level 2 with emphasis"
9097.pdfhref M "level-2-with-emphasis"
9198.SH 3
9299Level 3
100+.pdfhref O 3 "Level 3"
93101.pdfhref M "level-3"
94102.LP
95103with no blank line
96104.SH 2
97105Level 2
106+.pdfhref O 2 "Level 2"
98107.pdfhref M "level-2"
99108.LP
100109with no blank line
101110.HLINE
102111.SH 1
103112Paragraphs
113+.pdfhref O 1 "Paragraphs"
104114.pdfhref M "paragraphs"
105115.LP
106116Here's a regular paragraph.
@@ -122,6 +132,7 @@ here.
122132.HLINE
123133.SH 1
124134Block Quotes
135+.pdfhref O 1 "Block Quotes"
125136.pdfhref M "block-quotes"
126137.LP
127138E\-mail style:
@@ -166,6 +177,7 @@ And a following paragraph.
166177.HLINE
167178.SH 1
168179Code Blocks
180+.pdfhref O 1 "Code Blocks"
169181.pdfhref M "code-blocks"
170182.LP
171183Code:
@@ -194,9 +206,11 @@ These\ should\ not\ be\ escaped:\ \ \\$\ \\\\\ \\>\ \\[\ \\{
194206.HLINE
195207.SH 1
196208Lists
209+.pdfhref O 1 "Lists"
197210.pdfhref M "lists"
198211.SH 2
199212Unordered
213+.pdfhref O 2 "Unordered"
200214.pdfhref M "unordered"
201215.LP
202216Asterisks tight:
@@ -248,6 +262,7 @@ Minus 2
248262Minus 3
249263.SH 2
250264Ordered
265+.pdfhref O 2 "Ordered"
251266.pdfhref M "ordered"
252267.LP
253268Tight:
@@ -298,6 +313,7 @@ Item 2.
298313Item 3.
299314.SH 2
300315Nested
316+.pdfhref O 2 "Nested"
301317.pdfhref M "nested"
302318.IP \[bu] 2
303319Tab
@@ -343,6 +359,7 @@ Foe
343359Third
344360.SH 2
345361Tabs and spaces
362+.pdfhref O 2 "Tabs and spaces"
346363.pdfhref M "tabs-and-spaces"
347364.IP \[bu] 2
348365this is a list item
@@ -360,6 +377,7 @@ indented with spaces
360377.RE
361378.SH 2
362379Fancy list markers
380+.pdfhref O 2 "Fancy list markers"
363381.pdfhref M "fancy-list-markers"
364382.IP "(2)" 4
365383begins with 2
@@ -416,6 +434,7 @@ Williams
416434.HLINE
417435.SH 1
418436Definition Lists
437+.pdfhref O 1 "Definition Lists"
419438.pdfhref M "definition-lists"
420439.LP
421440Tight using spaces:
@@ -533,6 +552,7 @@ sublist
533552.RE
534553.SH 1
535554HTML Blocks
555+.pdfhref O 1 "HTML Blocks"
536556.pdfhref M "html-blocks"
537557.LP
538558Simple block on one line:
@@ -598,6 +618,7 @@ Hr's:
598618.HLINE
599619.SH 1
600620Inline Markup
621+.pdfhref O 1 "Inline Markup"
601622.pdfhref M "inline-markup"
602623.LP
603624This is \f[I]emphasized\f[], and so \f[I]is this\f[].
@@ -631,6 +652,7 @@ because of the unescaped spaces: a\[ha]b c\[ha]d, a\[ti]b c\[ti]d.
631652.HLINE
632653.SH 1
633654Smart quotes, ellipses, dashes
655+.pdfhref O 1 "Smart quotes, ellipses, dashes"
634656.pdfhref M "smart-quotes-ellipses-dashes"
635657.LP
636658\[lq]Hello,\[rq] said the spider.
@@ -657,6 +679,7 @@ Ellipses\&...and\&...and\&....
657679.HLINE
658680.SH 1
659681LaTeX
682+.pdfhref O 1 "LaTeX"
660683.pdfhref M "latex"
661684.IP \[bu] 2
662685.IP \[bu] 2
@@ -693,6 +716,7 @@ Here's a LaTeX table:
693716.HLINE
694717.SH 1
695718Special Characters
719+.pdfhref O 1 "Special Characters"
696720.pdfhref M "special-characters"
697721.LP
698722Here is some unicode:
@@ -751,9 +775,11 @@ Minus: \-
751775.HLINE
752776.SH 1
753777Links
778+.pdfhref O 1 "Links"
754779.pdfhref M "links"
755780.SH 2
756781Explicit
782+.pdfhref O 2 "Explicit"
757783.pdfhref M "explicit"
758784.LP
759785Just a \c
@@ -802,6 +828,7 @@ Just a \c
802828\&.
803829.SH 2
804830Reference
831+.pdfhref O 2 "Reference"
805832.pdfhref M "reference"
806833.LP
807834Foo \c
@@ -863,6 +890,7 @@ Foo \c
863890\&.
864891.SH 2
865892With ampersands
893+.pdfhref O 2 "With ampersands"
866894.pdfhref M "with-ampersands"
867895.LP
868896Here's a \c
@@ -886,6 +914,7 @@ Here's an \c
886914\&.
887915.SH 2
888916Autolinks
917+.pdfhref O 2 "Autolinks"
889918.pdfhref M "autolinks"
890919.LP
891920With an ampersand: \c
@@ -924,6 +953,7 @@ or\ here:\ <http://example.com/>
924953.HLINE
925954.SH 1
926955Images
956+.pdfhref O 1 "Images"
927957.pdfhref M "images"
928958.LP
929959From \[lq]Voyage dans la Lune\[rq] by Georges Melies (1902):
@@ -940,6 +970,7 @@ Here is a movie [IMAGE: \c
940970.HLINE
941971.SH 1
942972Footnotes
973+.pdfhref O 1 "Footnotes"
943974.pdfhref M "footnotes"
944975.LP
945976Here is a footnote reference,\**