git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: Fix awkward soft break movements before abbreviations.
cf82240John MacFarlane
src/Text/Pandoc/Readers/Markdown.hs+10−5
@@ -1717,19 +1717,24 @@ nonEndline = satisfy (/='\n')
1717
1717
1718str :: PandocMonad m => MarkdownParser m (F Inlines)
1718str :: PandocMonad m => MarkdownParser m (F Inlines)
1719str = do
1719str = do
1720+ canRelocateSpace <- notAfterString
1720 result <- many1 (alphaNum <|> try (char '.' <* notFollowedBy (char '.')))
1721 result <- many1 (alphaNum <|> try (char '.' <* notFollowedBy (char '.')))
1721 updateLastStrPos
1722 updateLastStrPos
1722 (do guardEnabled Ext_smart
1723 (do guardEnabled Ext_smart
1723 abbrevs <- getOption readerAbbreviations
1724 abbrevs <- getOption readerAbbreviations
1724 if not (null result) && last result == '.' && result `Set.member` abbrevs
1725 if not (null result) && last result == '.' && result `Set.member` abbrevs
1725 then try (do ils <- whitespace <|> endline
1726 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)
1727 return $ do
1730 return $ do
1728 ils' <- ils
1731 ils' <- ils
1729− if ils' == B.space
1732+ case B.toList ils' of
1733+ [Space] ->
1730− then return (B.str result <> B.str "\160")
1734+ return (B.str result <> B.str "\160")
1731− else -- linebreak or softbreak
1735+ [SoftBreak] | canRelocateSpace ->
1732− return (ils' <> B.str result <> B.str "\160"))
1736+ return (ils' <> B.str result <> B.str "\160")
1737+ _ -> return (B.str result <> ils'))
1733 <|> return (return (B.str result))
1738 <|> return (return (B.str result))
1734 else return (return (B.str result)))
1739 else return (return (B.str result)))
1735 <|> return (return (B.str result))
1740 <|> 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 @@
13 ,[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 "."]]
13 ,[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 "."]]
14 ,[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 "."]]
14 ,[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 "."]]
15 ,[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 "."]]]]
15 ,[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 "."]]]
17,Header 1 ("references",[],[]) [Str "References"]]
17,Header 1 ("references",[],[]) [Str "References"]]