aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-10-14 13:02:36 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-10-14 13:02:36 -0700
commitcf8224045bf927420ce4cb67f6fe703a95645fe6 (patch)
tree7bf270f84ae88fce05f4d143aa5851b716f8706f /src/Text
parent2bc429a57ca87f7d498c1412910eda4ebce2455b (diff)
downloadpandoc-cf8224045bf927420ce4cb67f6fe703a95645fe6.tar.gz
Markdown reader: Fix awkward soft break movements before abbreviations.
Closes #4635.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 81c7cbaf9..5944ecf82 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1717,19 +1717,24 @@ nonEndline = satisfy (/='\n')
str :: PandocMonad m => MarkdownParser m (F Inlines)
str = do
+ canRelocateSpace <- notAfterString
result <- many1 (alphaNum <|> try (char '.' <* notFollowedBy (char '.')))
updateLastStrPos
(do guardEnabled Ext_smart
abbrevs <- getOption readerAbbreviations
if not (null result) && last result == '.' && result `Set.member` abbrevs
then try (do ils <- whitespace <|> endline
- lookAhead alphaNum
+ -- ?? lookAhead alphaNum
+ -- replace space after with nonbreaking space
+ -- if softbreak, move before abbrev if possible (#4635)
return $ do
ils' <- ils
- if ils' == B.space
- then return (B.str result <> B.str "\160")
- else -- linebreak or softbreak
- return (ils' <> B.str result <> B.str "\160"))
+ case B.toList ils' of
+ [Space] ->
+ return (B.str result <> B.str "\160")
+ [SoftBreak] | canRelocateSpace ->
+ return (ils' <> B.str result <> B.str "\160")
+ _ -> return (B.str result <> ils'))
<|> return (return (B.str result))
else return (return (B.str result)))
<|> return (return (B.str result))