aboutsummaryrefslogtreecommitdiff
path: root/src/Text
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 /src/Text
parent1809f64a4cacdfe4bb7463b52181ceb74502ccd9 (diff)
downloadpandoc-8cf5c55e5e5a9d17cc8bbf57dec64e70e4ba810d.tar.gz
Ms. writer: don't render links in footnotes as footnotes.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/Ms.hs20
1 files changed, 15 insertions, 5 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