diff options
author | John MacFarlane <jgm@berkeley.edu> | 2018-10-14 13:02:36 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-10-14 13:02:36 -0700 |
commit | cf8224045bf927420ce4cb67f6fe703a95645fe6 (patch) | |
tree | 7bf270f84ae88fce05f4d143aa5851b716f8706f | |
parent | 2bc429a57ca87f7d498c1412910eda4ebce2455b (diff) | |
download | pandoc-cf8224045bf927420ce4cb67f6fe703a95645fe6.tar.gz |
Markdown reader: Fix awkward soft break movements before abbreviations.
Closes #4635.
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 15 | ||||
-rw-r--r-- | test/command/4635.md | 31 | ||||
-rw-r--r-- | test/markdown-citations.native | 2 |
3 files changed, 42 insertions, 6 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)) diff --git a/test/command/4635.md b/test/command/4635.md new file mode 100644 index 000000000..320b83956 --- /dev/null +++ b/test/command/4635.md @@ -0,0 +1,31 @@ +``` +% pandoc -f markdown -t native +(cf. +foo) +^D +[Para [Str "(cf.",SoftBreak,Str "foo)"]] +``` + +``` +% pandoc -f markdown -t native +a (cf. +foo) +^D +[Para [Str "a",Space,Str "(cf.",SoftBreak,Str "foo)"]] +``` + +``` +% pandoc -f markdown -t native +cf. +foo +^D +[Para [Str "cf.\160foo"]] +``` + +``` +% pandoc -f markdown -t native +a cf. +foo +^D +[Para [Str "a",SoftBreak,Str "cf.\160foo"]] +``` diff --git a/test/markdown-citations.native b/test/markdown-citations.native index c77ccbbfc..3d37dbae4 100644 --- a/test/markdown-citations.native +++ b/test/markdown-citations.native @@ -13,5 +13,5 @@ ,[Para [Str "Citation",Space,Str "with",Space,Str "a",Space,Str "suffix",Space,Str "and",Space,Str "locator",Space,Cite [Citation {citationId = "item1", citationPrefix = [], citationSuffix = [Space,Str "pp.\160\&33,",Space,Str "35-37,",Space,Str "and",Space,Str "nowhere",Space,Str "else"], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [Str "[@item1",Space,Str "pp.",Space,Str "33,",Space,Str "35-37,",Space,Str "and",Space,Str "nowhere",Space,Str "else]"],Str "."]] ,[Para [Str "Citation",Space,Str "with",Space,Str "suffix",Space,Str "only",Space,Cite [Citation {citationId = "item1", citationPrefix = [], citationSuffix = [Space,Str "and",Space,Str "nowhere",Space,Str "else"], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [Str "[@item1",Space,Str "and",Space,Str "nowhere",Space,Str "else]"],Str "."]] ,[Para [Str "Now",Space,Str "some",Space,Str "modifiers.",Note [Para [Str "Like",Space,Str "a",Space,Str "citation",Space,Str "without",Space,Str "author:",Space,Cite [Citation {citationId = "item1", citationPrefix = [], citationSuffix = [], citationMode = SuppressAuthor, citationNoteNum = 0, citationHash = 0}] [Str "[-@item1]"],Str ",",Space,Str "and",Space,Str "now",Space,Str "Doe",Space,Str "with",Space,Str "a",Space,Str "locator",Space,Cite [Citation {citationId = "item2", citationPrefix = [], citationSuffix = [Space,Str "p.\160\&44"], citationMode = SuppressAuthor, citationNoteNum = 0, citationHash = 0}] [Str "[-@item2",Space,Str "p.",Space,Str "44]"],Str "."]]]] - ,[Para [Str "With",Space,Str "some",Space,Str "markup",Space,Cite [Citation {citationId = "item1", citationPrefix = [Emph [Str "see"]], citationSuffix = [Space,Str "p.",Space,Strong [Str "32"]], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [Str "[*see*",Space,Str "@item1",Space,Str "p.",Space,Str "**32**]"],Str "."]]] + ,[Para [Str "With",Space,Str "some",Space,Str "markup",Space,Cite [Citation {citationId = "item1", citationPrefix = [Emph [Str "see"]], citationSuffix = [Space,Str "p.\160",Strong [Str "32"]], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [Str "[*see*",Space,Str "@item1",Space,Str "p.",Space,Str "**32**]"],Str "."]]] ,Header 1 ("references",[],[]) [Str "References"]] |