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