git.iko.soy/typeable/pandoc
on master help sign in
Shared: new export `splitSentences` [API change].
e25c7ceJohn MacFarlane
src/Text/Pandoc/Shared.hs+26
@@ -79,6 +79,7 @@ module Text.Pandoc.Shared (
79 makeMeta,
79 makeMeta,
80 eastAsianLineBreakFilter,
80 eastAsianLineBreakFilter,
81 underlineSpan,
81 underlineSpan,
82+ splitSentences,
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"], [])
584
585
586+-- | Returns the first sentence in a list of inlines, and the rest.
587+breakSentence :: [Inline] -> ([Inline], [Inline])
588+breakSentence [] = ([],[])
589+breakSentence xs =
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
595+ in case bs of
596+ [] -> (as, [])
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
605+
606+-- | Split a list of inlines into sentences.
607+splitSentences :: [Inline] -> [[Inline]]
608+splitSentences xs =
609+ let (sent, rest) = breakSentence xs
610+ in if null rest then [sent] else sent : splitSentences rest
585
611
586--
612--
587-- TagSoup HTML handling
613-- TagSoup HTML handling
src/Text/Pandoc/Writers/Man.hs−26
@@ -154,32 +154,6 @@ escapeCode = intercalate "\n" . map escapeLine . lines where
154-- line. groff/troff treats the line-ending period differently.
154-- line. groff/troff treats the line-ending period differently.
155-- See http://code.google.com/p/pandoc/issues/detail?id=148.
155-- See http://code.google.com/p/pandoc/issues/detail?id=148.
156
156
157−-- | Returns the first sentence in a list of inlines, and the rest.
158−breakSentence :: [Inline] -> ([Inline], [Inline])
159−breakSentence [] = ([],[])
160−breakSentence xs =
161− let isSentenceEndInline (Str ys@(_:_)) | last ys == '.' = True
162− isSentenceEndInline (Str ys@(_:_)) | last ys == '?' = True
163− isSentenceEndInline LineBreak = True
164− isSentenceEndInline _ = False
165− (as, bs) = break isSentenceEndInline xs
166− in case bs of
167− [] -> (as, [])
168− [c] -> (as ++ [c], [])
169− (c:Space:cs) -> (as ++ [c], cs)
170− (c:SoftBreak:cs) -> (as ++ [c], cs)
171− (Str ".":Str (')':ys):cs) -> (as ++ [Str ".", Str (')':ys)], cs)
172− (x@(Str ('.':')':_)):cs) -> (as ++ [x], cs)
173− (LineBreak:x@(Str ('.':_)):cs) -> (as ++[LineBreak], x:cs)
174− (c:cs) -> (as ++ [c] ++ ds, es)
175− where (ds, es) = breakSentence cs
176−
177−-- | Split a list of inlines into sentences.
178−splitSentences :: [Inline] -> [[Inline]]
179−splitSentences xs =
180− let (sent, rest) = breakSentence xs
181− in if null rest then [sent] else sent : splitSentences rest
182−
183-- | Convert Pandoc block element to man.
157-- | Convert Pandoc block element to man.
184blockToMan :: PandocMonad m
158blockToMan :: PandocMonad m
185 => WriterOptions -- ^ Options
159 => WriterOptions -- ^ Options
src/Text/Pandoc/Writers/Ms.hs−26
@@ -190,32 +190,6 @@ escapeCode = intercalate "\n" . map escapeLine . lines
190-- line. groff/troff treats the line-ending period differently.
190-- line. groff/troff treats the line-ending period differently.
191-- See http://code.google.com/p/pandoc/issues/detail?id=148.
191-- See http://code.google.com/p/pandoc/issues/detail?id=148.
192
192
193−-- | Returns the first sentence in a list of inlines, and the rest.
194−breakSentence :: [Inline] -> ([Inline], [Inline])
195−breakSentence [] = ([],[])
196−breakSentence xs =
197− let isSentenceEndInline (Str ys@(_:_)) | last ys == '.' = True
198− isSentenceEndInline (Str ys@(_:_)) | last ys == '?' = True
199− isSentenceEndInline LineBreak = True
200− isSentenceEndInline _ = False
201− (as, bs) = break isSentenceEndInline xs
202− in case bs of
203− [] -> (as, [])
204− [c] -> (as ++ [c], [])
205− (c:Space:cs) -> (as ++ [c], cs)
206− (c:SoftBreak:cs) -> (as ++ [c], cs)
207− (Str ".":Str (')':ys):cs) -> (as ++ [Str ".", Str (')':ys)], cs)
208− (x@(Str ('.':')':_)):cs) -> (as ++ [x], cs)
209− (LineBreak:x@(Str ('.':_)):cs) -> (as ++[LineBreak], x:cs)
210− (c:cs) -> (as ++ [c] ++ ds, es)
211− where (ds, es) = breakSentence cs
212−
213−-- | Split a list of inlines into sentences.
214−splitSentences :: [Inline] -> [[Inline]]
215−splitSentences xs =
216− let (sent, rest) = breakSentence xs
217− in if null rest then [sent] else sent : splitSentences rest
218−
219blockToMs :: PandocMonad m
193blockToMs :: PandocMonad m
220 => WriterOptions -- ^ Options
194 => WriterOptions -- ^ Options
221 -> Block -- ^ Block element
195 -> Block -- ^ Block element