src/eric7/ThirdParty/Jasy/jasy/script/api/Text.py

branch
eric7
changeset 9955
aa02420279fe
parent 9954
7c5fa3eef082
child 9956
5b138f996a1e
equal deleted inserted replaced
9954:7c5fa3eef082 9955:aa02420279fe
1 #
2 # Jasy - Web Tooling Framework
3 # Copyright 2010-2012 Zynga Inc.
4 # Copyright 2013-2014 Sebastian Werner
5 #
6
7 from __future__ import unicode_literals
8
9 import re
10 import jasy.core.Console as Console
11
12
13 # Used to filter first paragraph from HTML
14 paragraphExtract = re.compile(r"^(.*?)(\. |\? |\! |$)")
15 newlineMatcher = re.compile(r"\n")
16
17 # Used to remove markup sequences after doc processing of comment text
18 stripMarkup = re.compile(r"<.*?>")
19
20 def extractSummary(text):
21 try:
22 text = stripMarkup.sub("", newlineMatcher.sub(" ", text))
23 matched = paragraphExtract.match(text)
24 except TypeError:
25 matched = None
26
27 if matched:
28 summary = matched.group(1)
29 if summary is not None:
30 if not summary.endswith((".", "!", "?")):
31 summary = summary.strip() + "."
32 return summary
33
34 else:
35 Console.warn("Unable to extract summary for: %s", text)
36
37 return None
38

eric ide

mercurial