@@ -79,6 +79,7 @@ module Text.Pandoc.Shared (
80 eastAsianLineBreakFilter,
80 eastAsianLineBreakFilter,
81 underlineSpan,
81 underlineSpan,
82 -- * TagSoup HTML handling
83 -- * TagSoup HTML handling
83 renderTags',
84 renderTags',
84 -- * File handling
85 -- * File handling
@@ -582,6 +583,31 @@ eastAsianLineBreakFilter = bottomUp go
582underlineSpan :: Inlines -> Inlines
583underlineSpan :: Inlines -> Inlines
583underlineSpan = B.spanWith ("", ["underline"], [])
584underlineSpan = B.spanWith ("", ["underline"], [])
586+-- | Returns the first sentence in a list of inlines, and the rest.
587+breakSentence :: [Inline] -> ([Inline], [Inline])
588+breakSentence [] = ([],[])
590+ let isSentenceEndInline (Str ys@(_:_)) | last ys == '.' = True
591+ isSentenceEndInline (Str ys@(_:_)) | last ys == '?' = True
592+ isSentenceEndInline LineBreak = True
593+ isSentenceEndInline _ = False
594+ (as, bs) = break isSentenceEndInline xs
597+ [c] -> (as ++ [c], [])
598+ (c:Space:cs) -> (as ++ [c], cs)
599+ (c:SoftBreak:cs) -> (as ++ [c], cs)
600+ (Str ".":Str (')':ys):cs) -> (as ++ [Str ".", Str (')':ys)], cs)
601+ (x@(Str ('.':')':_)):cs) -> (as ++ [x], cs)
602+ (LineBreak:x@(Str ('.':_)):cs) -> (as ++[LineBreak], x:cs)
603+ (c:cs) -> (as ++ [c] ++ ds, es)
604+ where (ds, es) = breakSentence cs
606+-- | Split a list of inlines into sentences.
607+splitSentences :: [Inline] -> [[Inline]]
609+ let (sent, rest) = breakSentence xs
610+ in if null rest then [sent] else sent : splitSentences rest
587-- TagSoup HTML handling
613-- TagSoup HTML handling