summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-03-23 12:05:41 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-03-23 12:05:41 +0100
commit8cf5c55e5e5a9d17cc8bbf57dec64e70e4ba810d (patch)
treec65b1ec40874b964bdc973ecc6c41c6f5a65279f
parent1809f64a4cacdfe4bb7463b52181ceb74502ccd9 (diff)
Ms. writer: don't render links in footnotes as footnotes.
-rw-r--r--src/Text/Pandoc/Writers/Ms.hs20
-rw-r--r--test/writer.ms8
2 files changed, 17 insertions, 11 deletions
diff --git a/src/Text/Pandoc/Writers/Ms.hs b/src/Text/Pandoc/Writers/Ms.hs
index 3315548e2..f45ddede8 100644
--- a/src/Text/Pandoc/Writers/Ms.hs
+++ b/src/Text/Pandoc/Writers/Ms.hs
@@ -34,7 +34,7 @@ TODO:
[x] strong + em doesn't seem to work
[ ] super + subscript don't seem to work
[ ] options for hyperlink rendering (currently footnote)
-[ ] avoid note-in-note (which we currently get easily with
+[x] avoid note-in-note (which we currently get easily with
links in footnotes)
[ ] can we get prettier output using .B, etc. instead of
the inline forms?
@@ -88,12 +88,14 @@ import Text.TeXMath (writeEqn)
data WriterState = WriterState { stHasInlineMath :: Bool
, stNotes :: [Note]
+ , stInNote :: Bool
, stFontFeatures :: Map.Map Char Bool
}
defaultWriterState :: WriterState
defaultWriterState = WriterState{ stHasInlineMath = False
, stNotes = []
+ , stInNote = False
, stFontFeatures = Map.fromList [
('I',False)
, ('B',False)
@@ -419,11 +421,17 @@ inlineToMs opts SoftBreak = handleNotes opts cr
inlineToMs opts Space = handleNotes opts space
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 $ char '<' <> text srcSuffix <> char '>'
- _ -> do
+ return $ char '<' <> text (escapeString srcSuffix) <> char '>'
+ _ | 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])
inlineToMs opts (Image attr alternate (source, tit)) = do
@@ -443,8 +451,10 @@ handleNotes opts fallback = do
if null notes
then return fallback
else do
- modify $ \st -> st{ stNotes = [] }
- vcat <$> mapM (handleNote opts) notes
+ modify $ \st -> st{ stNotes = [], stInNote = True }
+ res <- vcat <$> mapM (handleNote opts) notes
+ modify $ \st -> st{ stInNote = False }
+ return res
handleNote :: PandocMonad m => WriterOptions -> Note -> MS m Doc
handleNote opts bs = do
diff --git a/test/writer.ms b/test/writer.ms
index bfcad9344..17bd033b4 100644
--- a/test/writer.ms
+++ b/test/writer.ms
@@ -846,7 +846,7 @@ In a list?
.IP \[bu] 2
It should.
.LP
-An e\-mail address: <nobody@nowhere.net>
+An e\-mail address: <nobody\@nowhere.net>
.RS
.LP
Blockquoted: <http://example.com/>
@@ -912,11 +912,7 @@ contains a space.[^my note] Here is an inline note.\**
This
is \f[I]easier\f[] to type.
Inline notes may contain
-links\**
-.FS
-http://google.com
-.FE
-and \f[C]]\f[] verbatim characters,
+links (http://google.com) and \f[C]]\f[] verbatim characters,
as well as [bracketed text].
.FE
.RS