fix title splitter

This commit is contained in:
Eshan Ramesh 2020-05-19 16:03:38 -04:00
parent a3e096edfd
commit cd6e532568

View file

@ -26,17 +26,7 @@ RESET_COLOR = colorama.Fore.RESET
# Based on Segtok by Florian Leitner # Based on Segtok by Florian Leitner
# https://github.com/fnl/segtok # https://github.com/fnl/segtok
SENTENCE_SPLITTER = re.compile( SENTENCE_SPLITTER = re.compile("\n")
r"""
( # A sentence ends at one of two sequences:
[\'\u2019\"\u201D]? # an optional right quote,
[\]\)]* # optional closing brackets and
\s+ # a sequence of required spaces.
| # Otherwise,
\n # a sentence also terminates newlines.
)""",
re.VERBOSE,
)
class UserAbort(Exception): class UserAbort(Exception):
@ -262,7 +252,7 @@ def slugify(string):
def split_title(text): def split_title(text):
"""Splits the first sentence off from a text.""" """Splits the first sentence off from a text."""
punkt = SENTENCE_SPLITTER.search(text) punkt = SENTENCE_SPLITTER.search(text.strip())
if not punkt: if not punkt:
return text, "" return text,""
return text[: punkt.end()].strip(), text[punkt.end() :].strip() return text[: punkt.end()].strip(), text[punkt.end() :].strip()