git.iko.soy/typeable/pandoc
on master help sign in
Ms writer: Support external links.
267e1a1John MacFarlane
data/templates/default.ms+4
@@ -38,6 +38,10 @@
38.nr FPS (\n[PS] - 2000)
38.nr FPS (\n[PS] - 2000)
39.\" color used for strikeout
39.\" color used for strikeout
40.defcolor strikecolor rgb 0.7 0.7 0.7
40.defcolor strikecolor rgb 0.7 0.7 0.7
41+.\" color for links (rgb)
42+.ds PDFHREF.COLOUR 0.35 0.00 0.60
43+.\" border for links (default none)
44+.ds PDFHREF.BORDER 0 0 0
41.\" ***************************************************************
45.\" ***************************************************************
42.\" PDF metadata
46.\" PDF metadata
43.pdfinfo /Title "$title-meta$"
47.pdfinfo /Title "$title-meta$"
src/Text/Pandoc/Writers/Ms.hs+7−21
@@ -29,8 +29,6 @@ Conversion of 'Pandoc' documents to groff ms format.
29
29
30TODO:
30TODO:
31
31
32−[ ] external links
33− http://pipeline.lbl.gov/code/3rd_party/licenses.win/groff/1.19.2/pdf/pdfmark.pdf
34[ ] manually create TOC including internal links and pdf outline
32[ ] manually create TOC including internal links and pdf outline
35 bookmarks? See
33 bookmarks? See
36 http://pipeline.lbl.gov/code/3rd_party/licenses.win/groff/1.19.2/pdf/pdfmark.pdf
34 http://pipeline.lbl.gov/code/3rd_party/licenses.win/groff/1.19.2/pdf/pdfmark.pdf
@@ -62,7 +60,6 @@ import Network.URI (isURI)
62data WriterState = WriterState { stHasInlineMath :: Bool
60data WriterState = WriterState { stHasInlineMath :: Bool
63 , stFirstPara :: Bool
61 , stFirstPara :: Bool
64 , stNotes :: [Note]
62 , stNotes :: [Note]
65− , stInNote :: Bool
66 , stSmallCaps :: Bool
63 , stSmallCaps :: Bool
67 , stFontFeatures :: Map.Map Char Bool
64 , stFontFeatures :: Map.Map Char Bool
68 }
65 }
@@ -71,7 +68,6 @@ defaultWriterState :: WriterState
71defaultWriterState = WriterState{ stHasInlineMath = False
68defaultWriterState = WriterState{ stHasInlineMath = False
72 , stFirstPara = True
69 , stFirstPara = True
73 , stNotes = []
70 , stNotes = []
74− , stInNote = False
75 , stSmallCaps = False
71 , stSmallCaps = False
76 , stFontFeatures = Map.fromList [
72 , stFontFeatures = Map.fromList [
77 ('I',False)
73 ('I',False)
@@ -480,21 +476,12 @@ inlineToMs opts (Link _ txt ('#':ident, _)) = do
480 doubleQuotes (text "\\c") <> space <> text "\\") <> cr <>
476 doubleQuotes (text "\\c") <> space <> text "\\") <> cr <>
481 text " -- " <> doubleQuotes (nowrap contents) <> cr <> text "\\&"
477 text " -- " <> doubleQuotes (nowrap contents) <> cr <> text "\\&"
482inlineToMs opts (Link _ txt (src, _)) = do
478inlineToMs opts (Link _ txt (src, _)) = do
483− let srcSuffix = fromMaybe src (stripPrefix "mailto:" src)
479+ -- external link
484− inNote <- gets stInNote
480+ contents <- inlineListToMs' opts $ map breakToSpace txt
485− case txt of
481+ return $ text "\\c" <> cr <> nowrap (text ".pdfhref W -D " <>
486− [Str s]
482+ doubleQuotes (text src) <> text " -A " <>
487− | escapeURI s == srcSuffix ->
483+ doubleQuotes (text "\\c") <> space <> text "\\") <> cr <>
488− return $ text (escapeString srcSuffix)
484+ text " -- " <> doubleQuotes (nowrap contents) <> cr <> text "\\&"
489− _ | not (isURI src) -> inlineListToMs opts txt
490− | inNote -> do
491− -- avoid a note in a note!
492− contents <- inlineListToMs opts txt
493− return $ contents <> space <> char '(' <>
494− text (escapeString src) <> char ')'
495− | otherwise -> do
496− let linknote = [Plain [Str src]]
497− inlineListToMs opts (txt ++ [Note linknote])
498inlineToMs opts (Image attr alternate (source, tit)) = do
485inlineToMs opts (Image attr alternate (source, tit)) = do
499 let alt = if null alternate then [Str "image"] else alternate
486 let alt = if null alternate then [Str "image"] else alternate
500 linkPart <- inlineToMs opts (Link attr alt (source, tit))
487 linkPart <- inlineToMs opts (Link attr alt (source, tit))
@@ -509,9 +496,8 @@ handleNotes opts fallback = do
509 if null notes
496 if null notes
510 then return fallback
497 then return fallback
511 else do
498 else do
512− modify $ \st -> st{ stNotes = [], stInNote = True }
499+ modify $ \st -> st{ stNotes = [] }
513 res <- vcat <$> mapM (handleNote opts) notes
500 res <- vcat <$> mapM (handleNote opts) notes
514− modify $ \st -> st{ stInNote = False }
515 return res
501 return res
516
502
517handleNote :: PandocMonad m => WriterOptions -> Note -> MS m Doc
503handleNote :: PandocMonad m => WriterOptions -> Note -> MS m Doc
test/writer.ms+154−63
@@ -38,6 +38,10 @@
38.nr FPS (\n[PS] - 2000)
38.nr FPS (\n[PS] - 2000)
39.\" color used for strikeout
39.\" color used for strikeout
40.defcolor strikecolor rgb 0.7 0.7 0.7
40.defcolor strikecolor rgb 0.7 0.7 0.7
41+.\" color for links (rgb)
42+.ds PDFHREF.COLOUR 0.35 0.00 0.60
43+.\" border for links (default none)
44+.ds PDFHREF.BORDER 0 0 0
41.\" ***************************************************************
45.\" ***************************************************************
42.\" PDF metadata
46.\" PDF metadata
43.pdfinfo /Title "Pandoc Test Suite"
47.pdfinfo /Title "Pandoc Test Suite"
@@ -64,7 +68,10 @@ John Gruber's markdown test suite.
64Headers
68Headers
65.pdfhref M "headers"
69.pdfhref M "headers"
66.SH 2
70.SH 2
71+Level 2 with an \c
72+.pdfhref W -D "/url" -A "\c" \
67−Level 2 with an embedded link
73+ -- "embedded link"
74+\&
68.pdfhref M "level-2-with-an-embedded-link"
75.pdfhref M "level-2-with-an-embedded-link"
69.SH 3
76.SH 3
70Level 3 with \f[I]emphasis\f[]
77Level 3 with \f[I]emphasis\f[]
@@ -597,7 +604,10 @@ This is \f[I]emphasized\f[], and so \f[I]is this\f[].
597.PP
604.PP
598This is \f[B]strong\f[], and so \f[B]is this\f[].
605This is \f[B]strong\f[], and so \f[B]is this\f[].
599.PP
606.PP
607+An \f[I]\c
608+.pdfhref W -D "/url" -A "\c" \
600−An \f[I]emphasized link\f[].
609+ -- "emphasized link"
610+\&\f[].
601.PP
611.PP
602\f[B]\f[BI]This is strong and em.\f[B]\f[]
612\f[B]\f[BI]This is strong and em.\f[B]\f[]
603.PP
613.PP
@@ -634,10 +644,10 @@ So is `pine.'
634`He said, \[lq]I want to go.\[rq]' Were you alive in the
644`He said, \[lq]I want to go.\[rq]' Were you alive in the
63570's?
64570's?
636.PP
646.PP
637−Here is some quoted `\f[C]code\f[]' and a \[lq]quoted link\**\[rq].
647+Here is some quoted `\f[C]code\f[]' and a \[lq]\c
638−.FS
639−http://example.com/?foo=1&bar=2
648+.pdfhref W -D "http://example.com/?foo=1&bar=2" -A "\c" \
640−.FE
649+ -- "quoted link"
650+\&\[rq].
641.PP
651.PP
642Some dashes: one\[em]two \[em] three\[em]four \[em] five.
652Some dashes: one\[em]two \[em] three\[em]four \[em] five.
643.PP
653.PP
@@ -746,45 +756,93 @@ Links
746Explicit
756Explicit
747.pdfhref M "explicit"
757.pdfhref M "explicit"
748.LP
758.LP
749−Just a URL.
759+Just a \c
760+.pdfhref W -D "/url/" -A "\c" \
761+ -- "URL"
762+\&.
750−.PP
763+.PP
764+\c
765+.pdfhref W -D "/url/" -A "\c" \
751−URL and title.
766+ -- "URL and title"
767+\&.
752−.PP
768+.PP
769+\c
770+.pdfhref W -D "/url/" -A "\c" \
753−URL and title.
771+ -- "URL and title"
772+\&.
754−.PP
773+.PP
774+\c
775+.pdfhref W -D "/url/" -A "\c" \
755−URL and title.
776+ -- "URL and title"
777+\&.
756−.PP
778+.PP
779+\c
780+.pdfhref W -D "/url/" -A "\c" \
757−URL and title
781+ -- "URL and title"
782+\&
758−.PP
783+.PP
784+\c
785+.pdfhref W -D "/url/" -A "\c" \
759−URL and title
786+ -- "URL and title"
787+\&
760−.PP
788+.PP
761−with_underscore
789+\c
762−.PP
790+.pdfhref W -D "/url/with_underscore" -A "\c" \
763−Email link\**
791+ -- "with_underscore"
764−.FS
792+\&
793+.PP
794+\c
765−mailto:nobody\@nowhere.net
795+.pdfhref W -D "mailto:nobody@nowhere.net" -A "\c" \
766−.FE
796+ -- "Email link"
767−.PP
797+\&
798+.PP
799+\c
800+.pdfhref W -D "" -A "\c" \
768−Empty.
801+ -- "Empty"
802+\&.
769.SH 2
803.SH 2
770Reference
804Reference
771.pdfhref M "reference"
805.pdfhref M "reference"
772.LP
806.LP
807+Foo \c
808+.pdfhref W -D "/url/" -A "\c" \
773−Foo bar.
809+ -- "bar"
810+\&.
774−.PP
811+.PP
812+Foo \c
813+.pdfhref W -D "/url/" -A "\c" \
775−Foo bar.
814+ -- "bar"
815+\&.
776−.PP
816+.PP
817+Foo \c
818+.pdfhref W -D "/url/" -A "\c" \
777−Foo bar.
819+ -- "bar"
820+\&.
778−.PP
821+.PP
822+With \c
823+.pdfhref W -D "/url/" -A "\c" \
779−With embedded [brackets].
824+ -- "embedded [brackets]"
825+\&.
780−.PP
826+.PP
827+\c
828+.pdfhref W -D "/url/" -A "\c" \
829+ -- "b"
781−b by itself should be a link.
830+\& by itself should be a link.
782−.PP
831+.PP
783−Indented once.
832+Indented \c
833+.pdfhref W -D "/url" -A "\c" \
834+ -- "once"
835+\&.
784−.PP
836+.PP
785−Indented twice.
837+Indented \c
838+.pdfhref W -D "/url" -A "\c" \
839+ -- "twice"
840+\&.
786−.PP
841+.PP
787−Indented thrice.
842+Indented \c
843+.pdfhref W -D "/url" -A "\c" \
844+ -- "thrice"
845+\&.
788.PP
846.PP
789This should [not][] be a link.
847This should [not][] be a link.
790.IP
848.IP
@@ -794,42 +852,66 @@ This should [not][] be a link.
794\f[]
852\f[]
795.fi
853.fi
796.LP
854.LP
855+Foo \c
856+.pdfhref W -D "/url/" -A "\c" \
797−Foo bar.
857+ -- "bar"
858+\&.
798.PP
859.PP
860+Foo \c
861+.pdfhref W -D "/url/" -A "\c" \
799−Foo biz.
862+ -- "biz"
863+\&.
800.SH 2
864.SH 2
801With ampersands
865With ampersands
802.pdfhref M "with-ampersands"
866.pdfhref M "with-ampersands"
803.LP
867.LP
804−Here's a link with an ampersand in the URL\**.
868+Here's a \c
805−.FS
806−http://example.com/?foo=1&bar=2
869+.pdfhref W -D "http://example.com/?foo=1&bar=2" -A "\c" \
807−.FE
870+ -- "link with an ampersand in the URL"
871+\&.
808−.PP
872+.PP
809−Here's a link with an amersand in the link text: AT&T\**.
873+Here's a link with an amersand in the link text: \c
810−.FS
874+.pdfhref W -D "http://att.com/" -A "\c" \
811−http://att.com/
875+ -- "AT&T"
812−.FE
876+\&.
813−.PP
877+.PP
878+Here's an \c
879+.pdfhref W -D "/script?foo=1&bar=2" -A "\c" \
814−Here's an inline link.
880+ -- "inline link"
881+\&.
815−.PP
882+.PP
883+Here's an \c
884+.pdfhref W -D "/script?foo=1&bar=2" -A "\c" \
816−Here's an inline link in pointy braces.
885+ -- "inline link in pointy braces"
886+\&.
817.SH 2
887.SH 2
818Autolinks
888Autolinks
819.pdfhref M "autolinks"
889.pdfhref M "autolinks"
820.LP
890.LP
891+With an ampersand: \c
821−With an ampersand: http://example.com/?foo=1&bar=2
892+.pdfhref W -D "http://example.com/?foo=1&bar=2" -A "\c" \
893+ -- "http://example.com/?foo=1&bar=2"
894+\&
822.IP \[bu] 2
895.IP \[bu] 2
823In a list?
896In a list?
824.IP \[bu] 2
897.IP \[bu] 2
898+\c
899+.pdfhref W -D "http://example.com/" -A "\c" \
825−http://example.com/
900+ -- "http://example.com/"
901+\&
826.IP \[bu] 2
902.IP \[bu] 2
827It should.
903It should.
828.LP
904.LP
829−An e\-mail address: nobody\@nowhere.net
905+An e\-mail address: \c
906+.pdfhref W -D "mailto:nobody@nowhere.net" -A "\c" \
907+ -- "nobody\@nowhere.net"
908+\&
830.RS
909.RS
831.LP
910.LP
911+Blockquoted: \c
912+.pdfhref W -D "http://example.com/" -A "\c" \
832−Blockquoted: http://example.com/
913+ -- "http://example.com/"
914+\&
833.RE
915.RE
834.LP
916.LP
835Auto\-links should not occur here: \f[C]<http://example.com/>\f[]
917Auto\-links should not occur here: \f[C]<http://example.com/>\f[]
@@ -846,9 +928,15 @@ Images
846.LP
928.LP
847From \[lq]Voyage dans la Lune\[rq] by Georges Melies (1902):
929From \[lq]Voyage dans la Lune\[rq] by Georges Melies (1902):
848.PP
930.PP
849−[IMAGE: lalune]
931+[IMAGE: \c
932+.pdfhref W -D "lalune.jpg" -A "\c" \
933+ -- "lalune"
934+\&]
850.PP
935.PP
851−Here is a movie [IMAGE: movie] icon.
936+Here is a movie [IMAGE: \c
937+.pdfhref W -D "movie.jpg" -A "\c" \
938+ -- "movie"
939+\&] icon.
852.HLINE
940.HLINE
853.SH 1
941.SH 1
854Footnotes
942Footnotes
@@ -885,7 +973,10 @@ contains a space.[^my note] Here is an inline note.\**
885This
973This
886is \f[I]easier\f[] to type.
974is \f[I]easier\f[] to type.
887Inline notes may contain
975Inline notes may contain
976+\c
977+.pdfhref W -D "http://google.com" -A "\c" \
978+ -- "links"
888−links (http://google.com) and \f[C]]\f[] verbatim characters,
979+\& and \f[C]]\f[] verbatim characters,
889as well as [bracketed text].
980as well as [bracketed text].
890.FE
981.FE
891.RS
982.RS