aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-03-26 11:04:33 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-03-26 11:05:23 +0200
commit267e1a13eadec5ae7ca6e951fd9ab650487f0f2a (patch)
treeaf825da4987ceffb9a7c86ca4b6308125d9fcbb5 /src/Text
parentd9e8e84be0fb873b90abc8cc43e66f83f17e0d83 (diff)
downloadpandoc-267e1a13eadec5ae7ca6e951fd9ab650487f0f2a.tar.gz
Ms writer: Support external links.
Also add config options for link color.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/Ms.hs28
1 files changed, 7 insertions, 21 deletions
diff --git a/src/Text/Pandoc/Writers/Ms.hs b/src/Text/Pandoc/Writers/Ms.hs
index 5fbc54543..1978fc429 100644
--- a/src/Text/Pandoc/Writers/Ms.hs
+++ b/src/Text/Pandoc/Writers/Ms.hs
@@ -29,8 +29,6 @@ Conversion of 'Pandoc' documents to groff ms format.
TODO:
-[ ] external links
- http://pipeline.lbl.gov/code/3rd_party/licenses.win/groff/1.19.2/pdf/pdfmark.pdf
[ ] 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
@@ -62,7 +60,6 @@ import Network.URI (isURI)
data WriterState = WriterState { stHasInlineMath :: Bool
, stFirstPara :: Bool
, stNotes :: [Note]
- , stInNote :: Bool
, stSmallCaps :: Bool
, stFontFeatures :: Map.Map Char Bool
}
@@ -71,7 +68,6 @@ defaultWriterState :: WriterState
defaultWriterState = WriterState{ stHasInlineMath = False
, stFirstPara = True
, stNotes = []
- , stInNote = False
, stSmallCaps = False
, stFontFeatures = Map.fromList [
('I',False)
@@ -480,21 +476,12 @@ inlineToMs opts (Link _ txt ('#':ident, _)) = do
doubleQuotes (text "\\c") <> space <> text "\\") <> cr <>
text " -- " <> doubleQuotes (nowrap contents) <> cr <> text "\\&"
inlineToMs opts (Link _ txt (src, _)) = do
- let srcSuffix = fromMaybe src (stripPrefix "mailto:" src)
- inNote <- gets stInNote
- case txt of
- [Str s]
- | escapeURI s == srcSuffix ->
- return $ text (escapeString srcSuffix)
- _ | not (isURI src) -> inlineListToMs opts txt
- | inNote -> do
- -- avoid a note in a note!
- contents <- inlineListToMs opts txt
- return $ contents <> space <> char '(' <>
- text (escapeString src) <> char ')'
- | otherwise -> do
- let linknote = [Plain [Str src]]
- inlineListToMs opts (txt ++ [Note linknote])
+ -- external link
+ contents <- inlineListToMs' opts $ map breakToSpace txt
+ return $ text "\\c" <> cr <> nowrap (text ".pdfhref W -D " <>
+ doubleQuotes (text src) <> text " -A " <>
+ doubleQuotes (text "\\c") <> space <> text "\\") <> cr <>
+ text " -- " <> doubleQuotes (nowrap contents) <> cr <> text "\\&"
inlineToMs opts (Image attr alternate (source, tit)) = do
let alt = if null alternate then [Str "image"] else alternate
linkPart <- inlineToMs opts (Link attr alt (source, tit))
@@ -509,9 +496,8 @@ handleNotes opts fallback = do
if null notes
then return fallback
else do
- modify $ \st -> st{ stNotes = [], stInNote = True }
+ modify $ \st -> st{ stNotes = [] }
res <- vcat <$> mapM (handleNote opts) notes
- modify $ \st -> st{ stInNote = False }
return res
handleNote :: PandocMonad m => WriterOptions -> Note -> MS m Doc