git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: Fix awkward soft break movements before abbreviations.

Closes #4635.

commitcf8224045bf927420ce4cb67f6fe703a95645fe6 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 14 Oct 2018, 13:02 (8 years ago) parent2bc429a
3 files changed+42−6
src/Text/Pandoc/Readers/Markdown.hs+10−5 test/command/4635.md+31 test/markdown-citations.native+1−1
src/Text/Pandoc/Readers/Markdown.hs+10−5
@@ -1717,19 +1717,24 @@ nonEndline = satisfy (/='\n')
17171717
17181718str :: PandocMonad m => MarkdownParser m (F Inlines)
17191719str = do
1720+ canRelocateSpace <- notAfterString
17201721 result <- many1 (alphaNum <|> try (char '.' <* notFollowedBy (char '.')))
17211722 updateLastStrPos
17221723 (do guardEnabled Ext_smart
17231724 abbrevs <- getOption readerAbbreviations
17241725 if not (null result) && last result == '.' && result `Set.member` abbrevs
17251726 then try (do ils <- whitespace <|> endline
1726− lookAhead alphaNum
1727+ -- ?? lookAhead alphaNum
1728+ -- replace space after with nonbreaking space
1729+ -- if softbreak, move before abbrev if possible (#4635)
17271730 return $ do
17281731 ils' <- ils
1729− if ils' == B.space
1730− then return (B.str result <> B.str "\160")
1731− else -- linebreak or softbreak
1732− return (ils' <> B.str result <> B.str "\160"))
1732+ case B.toList ils' of
1733+ [Space] ->
1734+ return (B.str result <> B.str "\160")
1735+ [SoftBreak] | canRelocateSpace ->
1736+ return (ils' <> B.str result <> B.str "\160")
1737+ _ -> return (B.str result <> ils'))
17331738 <|> return (return (B.str result))
17341739 else return (return (B.str result)))
17351740 <|> return (return (B.str result))
test/command/4635.mdnew file+31
@@ -0,0 +1,31 @@
1+```
2+% pandoc -f markdown -t native
3+(cf.
4+foo)
5+^D
6+[Para [Str "(cf.",SoftBreak,Str "foo)"]]
7+```
8+
9+```
10+% pandoc -f markdown -t native
11+a (cf.
12+foo)
13+^D
14+[Para [Str "a",Space,Str "(cf.",SoftBreak,Str "foo)"]]
15+```
16+
17+```
18+% pandoc -f markdown -t native
19+cf.
20+foo
21+^D
22+[Para [Str "cf.\160foo"]]
23+```
24+
25+```
26+% pandoc -f markdown -t native
27+a cf.
28+foo
29+^D
30+[Para [Str "a",SoftBreak,Str "cf.\160foo"]]
31+```
test/markdown-citations.native+1−1
@@ -13,5 +13,5 @@
1313 ,[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 "."]]
1414 ,[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 "."]]
1515 ,[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 "."]]]]
16− ,[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 "."]]]
16+ ,[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 "."]]]
1717,Header 1 ("references",[],[]) [Str "References"]]