@@ -34,7 +34,7 @@ TODO:
3434[x] strong + em doesn't seem to work
3535[ ] super + subscript don't seem to work
3636[ ] options for hyperlink rendering (currently footnote)
37−[ ] avoid note-in-note (which we currently get easily with
37+[x] avoid note-in-note (which we currently get easily with
3838 links in footnotes)
3939[ ] can we get prettier output using .B, etc. instead of
4040 the inline forms?
@@ -88,12 +88,14 @@ import Text.TeXMath (writeEqn)
8888
8989data WriterState = WriterState { stHasInlineMath :: Bool
9090 , stNotes :: [Note]
91+ , stInNote :: Bool
9192 , stFontFeatures :: Map.Map Char Bool
9293 }
9394
9495defaultWriterState :: WriterState
9596defaultWriterState = WriterState{ stHasInlineMath = False
9697 , stNotes = []
98+ , stInNote = False
9799 , stFontFeatures = Map.fromList [
98100 ('I',False)
99101 , ('B',False)
@@ -419,11 +421,17 @@ inlineToMs opts SoftBreak = handleNotes opts cr
419421inlineToMs opts Space = handleNotes opts space
420422inlineToMs opts (Link _ txt (src, _)) = do
421423 let srcSuffix = fromMaybe src (stripPrefix "mailto:" src)
424+ inNote <- gets stInNote
422425 case txt of
423426 [Str s]
424427 | escapeURI s == srcSuffix ->
425− return $ char '<' <> text srcSuffix <> char '>'
426− _ -> do
428+ return $ char '<' <> text (escapeString srcSuffix) <> char '>'
429+ _ | inNote -> do
430+ -- avoid a note in a note!
431+ contents <- inlineListToMs opts txt
432+ return $ contents <> space <> char '(' <>
433+ text (escapeString src) <> char ')'
434+ | otherwise -> do
427435 let linknote = [Plain [Str src]]
428436 inlineListToMs opts (txt ++ [Note linknote])
429437inlineToMs opts (Image attr alternate (source, tit)) = do
@@ -443,8 +451,10 @@ handleNotes opts fallback = do
443451 if null notes
444452 then return fallback
445453 else do
446− modify $ \st -> st{ stNotes = [] }
447− vcat <$> mapM (handleNote opts) notes
454+ modify $ \st -> st{ stNotes = [], stInNote = True }
455+ res <- vcat <$> mapM (handleNote opts) notes
456+ modify $ \st -> st{ stInNote = False }
457+ return res
448458
449459handleNote :: PandocMonad m => WriterOptions -> Note -> MS m Doc
450460handleNote opts bs = do