summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/templates/default.ms1
-rw-r--r--src/Text/Pandoc/PDF.hs2
-rw-r--r--src/Text/Pandoc/Writers/Ms.hs36
-rw-r--r--test/writer.ms34
4 files changed, 60 insertions, 13 deletions
diff --git a/data/templates/default.ms b/data/templates/default.ms
index f8175e97d..6cbece05b 100644
--- a/data/templates/default.ms
+++ b/data/templates/default.ms
@@ -40,7 +40,6 @@
.defcolor strikecolor rgb 0.7 0.7 0.7
.\" ***************************************************************
.\" PDF metadata
-.mso pdfmark.tmac
.pdfinfo /Title "$title-meta$"
.pdfinfo /Author "$author-meta$"
$if(adjusting)$
diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs
index 164ab0244..7e44adeda 100644
--- a/src/Text/Pandoc/PDF.hs
+++ b/src/Text/Pandoc/PDF.hs
@@ -110,7 +110,7 @@ makePDF "pdfroff" writer opts verbosity _mediabag doc = liftIO $ do
source <- runIOorExplode $ do
setVerbosity verbosity
writer opts doc
- let args = ["-ms", "-e", "-t", "-k", "-KUTF-8", "-i"]
+ let args = ["-ms", "-mpdfmark", "-e", "-t", "-k", "-KUTF-8", "-i"]
ms2pdf verbosity args source
makePDF program writer opts verbosity mediabag doc = do
let withTemp = if takeBaseName program == "context"
diff --git a/src/Text/Pandoc/Writers/Ms.hs b/src/Text/Pandoc/Writers/Ms.hs
index b95878c30..2ff83ed96 100644
--- a/src/Text/Pandoc/Writers/Ms.hs
+++ b/src/Text/Pandoc/Writers/Ms.hs
@@ -29,11 +29,14 @@ Conversion of 'Pandoc' documents to groff ms format.
TODO:
+[ ] is there a way to avoid the extra space between internal links
+ and following punctuation?
+[ ] manually create TOC including internal links and pdf outline
+ bookmarks? See
+ http://pipeline.lbl.gov/code/3rd_party/licenses.win/groff/1.19.2/pdf/pdfmark.pdf
[ ] is there a better way to do strikeout?
[ ] options for hyperlink rendering (currently footnote)
[ ] tight/loose list distinction
-[ ] internal hyperlinks (this seems to be possible since
- they exist in the groff manual PDF version)
-}
module Text.Pandoc.Writers.Ms ( writeMs ) where
@@ -242,20 +245,28 @@ blockToMs _ b@(RawBlock f str)
blockToMs _ HorizontalRule = do
resetFirstPara
return $ text ".HLINE"
-blockToMs opts (Header level _ inlines) = do
+blockToMs opts (Header level (ident,classes,_) inlines) = do
setFirstPara
contents <- inlineListToMs' opts inlines
+ let anchor = if null ident
+ then empty
+ else nowrap $
+ text ".pdfhref M " <> doubleQuotes (text ident)
let tocEntry = if writerTableOfContents opts &&
level <= writerTOCDepth opts
then text ".XS" $$
(text (replicate level '\t') <> contents) $$
text ".XE"
else empty
- let heading = if writerNumberSections opts
+ let heading = if writerNumberSections opts &&
+ "unnumbered" `notElem` classes
then ".NH"
else ".SH"
modify $ \st -> st{ stFirstPara = True }
- return $ text heading <> space <> text (show level) $$ contents $$ tocEntry
+ return $ anchor $$
+ (text heading <> space <> text (show level)) $$
+ contents $$
+ tocEntry
blockToMs _ (CodeBlock _ str) = do
setFirstPara
return $
@@ -388,8 +399,6 @@ blockListToMs opts blocks =
inlineListToMs :: PandocMonad m => WriterOptions -> [Inline] -> MS m Doc
-- if list starts with ., insert a zero-width character \& so it
-- won't be interpreted as markup if it falls at the beginning of a line.
-inlineListToMs opts lst@(Str ('.':_) : _) = mapM (inlineToMs opts) lst >>=
- (return . (text "\\&" <>) . hcat)
inlineListToMs opts lst = hcat <$> mapM (inlineToMs opts) lst
-- This version to be used when there is no further inline content;
@@ -435,10 +444,13 @@ inlineToMs opts (Cite _ lst) =
inlineToMs _ (Code _ str) =
withFontFeature 'C' (return $ text $ escapeCode str)
inlineToMs _ (Str str) = do
+ let shim = case str of
+ '.':_ -> afterBreak "\\&"
+ _ -> empty
smallcaps <- gets stSmallCaps
if smallcaps
- then return $ text $ toSmallCaps str
- else return $ text $ escapeString str
+ then return $ shim <> text (toSmallCaps str)
+ else return $ shim <> text (escapeString str)
inlineToMs opts (Math InlineMath str) = do
modify $ \st -> st{ stHasInlineMath = True }
res <- convertMath writeEqn InlineMath str
@@ -461,6 +473,12 @@ inlineToMs _ il@(RawInline f str)
inlineToMs _ (LineBreak) = return $ cr <> text ".br" <> cr
inlineToMs opts SoftBreak = handleNotes opts cr
inlineToMs opts Space = handleNotes opts space
+inlineToMs opts (Link _ txt ('#':ident, _)) = do
+ -- internal link
+ contents <- inlineListToMs' opts{ writerWrapText = WrapNone } txt
+ return $ text "\\c" <> cr <> nowrap (text ".pdfhref L -D " <>
+ doubleQuotes (text ident) <> space <>
+ doubleQuotes contents) <> cr
inlineToMs opts (Link _ txt (src, _)) = do
let srcSuffix = fromMaybe src (stripPrefix "mailto:" src)
inNote <- gets stInNote
diff --git a/test/writer.ms b/test/writer.ms
index 0ce199fba..55f354d22 100644
--- a/test/writer.ms
+++ b/test/writer.ms
@@ -37,10 +37,9 @@
.\" footnote point size
.nr FPS (\n[PS] - 2000)
.\" color used for strikeout
-.defcolor strikecolor rgb 0.2 0.2 0.2
+.defcolor strikecolor rgb 0.7 0.7 0.7
.\" ***************************************************************
.\" PDF metadata
-.mso pdfmark.tmac
.pdfinfo /Title "Pandoc Test Suite"
.pdfinfo /Author "John MacFarlane; Anonymous"
.hy
@@ -61,29 +60,39 @@ This is a set of tests for pandoc.
Most of them are adapted from
John Gruber's markdown test suite.
.HLINE
+.pdfhref M "headers"
.SH 1
Headers
+.pdfhref M "level-2-with-an-embedded-link"
.SH 2
Level 2 with an embedded link
+.pdfhref M "level-3-with-emphasis"
.SH 3
Level 3 with \f[I]emphasis\f[]
+.pdfhref M "level-4"
.SH 4
Level 4
+.pdfhref M "level-5"
.SH 5
Level 5
+.pdfhref M "level-1"
.SH 1
Level 1
+.pdfhref M "level-2-with-emphasis"
.SH 2
Level 2 with \f[I]emphasis\f[]
+.pdfhref M "level-3"
.SH 3
Level 3
.LP
with no blank line
+.pdfhref M "level-2"
.SH 2
Level 2
.LP
with no blank line
.HLINE
+.pdfhref M "paragraphs"
.SH 1
Paragraphs
.LP
@@ -104,6 +113,7 @@ There should be a hard line break
.br
here.
.HLINE
+.pdfhref M "block-quotes"
.SH 1
Block Quotes
.LP
@@ -147,6 +157,7 @@ This should not be a block quote: 2
.PP
And a following paragraph.
.HLINE
+.pdfhref M "code-blocks"
.SH 1
Code Blocks
.LP
@@ -174,8 +185,10 @@ These\ should\ not\ be\ escaped:\ \ \\$\ \\\\\ \\>\ \\[\ \\{
\f[]
.fi
.HLINE
+.pdfhref M "lists"
.SH 1
Lists
+.pdfhref M "unordered"
.SH 2
Unordered
.LP
@@ -226,6 +239,7 @@ Minus 1
Minus 2
.IP \[bu] 2
Minus 3
+.pdfhref M "ordered"
.SH 2
Ordered
.LP
@@ -275,6 +289,7 @@ back.
Item 2.
.IP "3." 3
Item 3.
+.pdfhref M "nested"
.SH 2
Nested
.IP \[bu] 2
@@ -319,6 +334,7 @@ Foe
.RE
.IP "3." 3
Third
+.pdfhref M "tabs-and-spaces"
.SH 2
Tabs and spaces
.IP \[bu] 2
@@ -335,6 +351,7 @@ indented with tabs
this is an example list item
indented with spaces
.RE
+.pdfhref M "fancy-list-markers"
.SH 2
Fancy list markers
.IP "(2)" 4
@@ -390,6 +407,7 @@ M.A.\ 2007
B.
Williams
.HLINE
+.pdfhref M "definition-lists"
.SH 1
Definition Lists
.LP
@@ -506,6 +524,7 @@ sublist
.IP "2." 3
sublist
.RE
+.pdfhref M "html-blocks"
.SH 1
HTML Blocks
.LP
@@ -570,6 +589,7 @@ Code:
.LP
Hr's:
.HLINE
+.pdfhref M "inline-markup"
.SH 1
Inline Markup
.LP
@@ -599,6 +619,7 @@ Subscripts: H\*<2\*>O, H\*<23\*>O, H\*<many\ of\ them\*>O.
These should not be superscripts or subscripts,
because of the unescaped spaces: a^b c^d, a~b c~d.
.HLINE
+.pdfhref M "smart-quotes-ellipses-dashes"
.SH 1
Smart quotes, ellipses, dashes
.LP
@@ -624,6 +645,7 @@ Dashes between numbers: 5\[en]7, 255\[en]66, 1987\[en]1999.
.PP
Ellipses\&...and\&...and\&....
.HLINE
+.pdfhref M "latex"
.SH 1
LaTeX
.IP \[bu] 2
@@ -659,6 +681,7 @@ Escaped \f[C]$\f[]: $73 \f[I]this should be emphasized\f[] 23$.
.LP
Here's a LaTeX table:
.HLINE
+.pdfhref M "special-characters"
.SH 1
Special Characters
.LP
@@ -716,8 +739,10 @@ Plus: +
.PP
Minus: \-
.HLINE
+.pdfhref M "links"
.SH 1
Links
+.pdfhref M "explicit"
.SH 2
Explicit
.LP
@@ -741,6 +766,7 @@ mailto:nobody\@nowhere.net
.FE
.PP
Empty.
+.pdfhref M "reference"
.SH 2
Reference
.LP
@@ -771,6 +797,7 @@ This should [not][] be a link.
Foo bar.
.PP
Foo biz.
+.pdfhref M "with-ampersands"
.SH 2
With ampersands
.LP
@@ -787,6 +814,7 @@ http://att.com/
Here's an inline link.
.PP
Here's an inline link in pointy braces.
+.pdfhref M "autolinks"
.SH 2
Autolinks
.LP
@@ -812,6 +840,7 @@ or\ here:\ <http://example.com/>
\f[]
.fi
.HLINE
+.pdfhref M "images"
.SH 1
Images
.LP
@@ -821,6 +850,7 @@ From \[lq]Voyage dans la Lune\[rq] by Georges Melies (1902):
.PP
Here is a movie [IMAGE: movie] icon.
.HLINE
+.pdfhref M "footnotes"
.SH 1
Footnotes
.LP