summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-03-24 17:24:25 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-03-24 17:25:09 +0100
commita7ae4b1ee2a164c916d1ded7d393d18f71e0fc86 (patch)
treea7c2b8da04126ad62a980a6ef44f94e358d93600
parent6dd7be72500326a14701efae6a63b4982a93350a (diff)
Ms writer: support --toc, date, abstract.
-rw-r--r--MANUAL.txt7
-rw-r--r--data/templates/default.ms12
-rw-r--r--src/Text/Pandoc/Writers/Ms.hs32
-rw-r--r--test/writer.ms1
4 files changed, 28 insertions, 24 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index b224ae761..1bc5c79cc 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -612,9 +612,10 @@ General writer options
`--toc`, `--table-of-contents`
: Include an automatically generated table of contents (or, in
- the case of `latex`, `context`, `docx`, and `rst`, an instruction to create
- one) in the output document. This option has no effect on `man`,
- `docbook4`, `docbook5`, `slidy`, `slideous`, `s5`, or `odt` output.
+ the case of `latex`, `context`, `docx`, `rst`, or `ms`,
+ an instruction to create one) in the output document. This
+ option has no effect on `man`, `docbook4`, `docbook5`, `slidy`,
+ `slideous`, `s5`, or `odt` output.
`--toc-depth=`*NUMBER*
diff --git a/data/templates/default.ms b/data/templates/default.ms
index 17f0883b8..16c179235 100644
--- a/data/templates/default.ms
+++ b/data/templates/default.ms
@@ -33,6 +33,14 @@ $for(author)$
.AU
$author$
$endfor$
+$if(date)$
+.ND "$date$"
+$endif$
+$if(abstract)$
+.AB
+$abstract$
+.AE
+$endif$
$for(header-includes)$
$header-includes$
$endfor$
@@ -40,6 +48,10 @@ $for(include-before)$
$include-before$
$endfor$
$body$
+$if(toc)$
+$toc$
+.TC
+$endif$
$for(include-after)$
$include-after$
$endfor$
diff --git a/src/Text/Pandoc/Writers/Ms.hs b/src/Text/Pandoc/Writers/Ms.hs
index a9b73b1ec..40a33b423 100644
--- a/src/Text/Pandoc/Writers/Ms.hs
+++ b/src/Text/Pandoc/Writers/Ms.hs
@@ -40,7 +40,7 @@ TODO:
[ ] tight/loose list distinction
[ ] internal hyperlinks (this seems to be possible since
they exist in the groff manual PDF version)
-[ ] better template, with configurable page number, table of contents,
+[ ] better template, with configurable page number,
columns, etc.
[ ] support for images? gropdf (and maybe pdfroff) supports the tag
\X'pdf: pdfpic file alignment width height line-length'
@@ -64,11 +64,10 @@ import qualified Data.Map as Map
import Data.List ( stripPrefix, intersperse, intercalate, sort )
import Data.Maybe (fromMaybe)
import Text.Pandoc.Pretty
-import Text.Pandoc.Builder (deleteMeta)
import Text.Pandoc.Class (PandocMonad, report)
import Text.Pandoc.Logging
import Control.Monad.State
-import Data.Char ( isDigit, isLower, isUpper, toUpper )
+import Data.Char ( isLower, isUpper, toUpper )
import Text.TeXMath (writeEqn)
data WriterState = WriterState { stHasInlineMath :: Bool
@@ -106,33 +105,18 @@ pandocToMs opts (Pandoc meta blocks) = do
then Just $ writerColumns opts
else Nothing
let render' = render colwidth
- titleText <- inlineListToMs' opts $ docTitle meta
- let title' = render' titleText
- let setFieldsFromTitle =
- case break (== ' ') title' of
- (cmdName, rest) -> case reverse cmdName of
- (')':d:'(':xs) | isDigit d ->
- defField "title" (reverse xs) .
- defField "section" [d] .
- case splitBy (=='|') rest of
- (ft:hds) ->
- defField "footer" (trim ft) .
- defField "header"
- (trim $ concat hds)
- [] -> id
- _ -> defField "title" title'
metadata <- metaToJSON opts
(fmap (render colwidth) . blockListToMs opts)
(fmap (render colwidth) . inlineListToMs' opts)
- $ deleteMeta "title" meta
+ meta
body <- blockListToMs opts blocks
let main = render' body
hasInlineMath <- gets stHasInlineMath
let context = defField "body" main
- $ setFieldsFromTitle
$ defField "has-inline-math" hasInlineMath
$ defField "hyphenate" True
$ defField "pandoc-version" pandocVersion
+ $ defField "toc" (writerTableOfContents opts)
$ metadata
case writerTemplate opts of
Nothing -> return main
@@ -241,10 +225,16 @@ blockToMs _ HorizontalRule =
return $ text ".HLINE"
blockToMs opts (Header level _ inlines) = do
contents <- inlineListToMs' opts inlines
+ 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
then ".NH"
else ".SH"
- return $ text heading <> space <> text (show level) $$ contents
+ return $ text heading <> space <> text (show level) $$ contents $$ tocEntry
blockToMs _ (CodeBlock _ str) = return $
text ".IP" $$
text ".nf" $$
diff --git a/test/writer.ms b/test/writer.ms
index 818b88f5b..223fbd525 100644
--- a/test/writer.ms
+++ b/test/writer.ms
@@ -22,6 +22,7 @@ Pandoc Test Suite
John MacFarlane
.AU
Anonymous
+.ND "July 17, 2006"
.LP
This is a set of tests for pandoc.
Most of them are adapted from