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

changeset 6650
1dd52aa8897c
parent 5843
76eee727ccd9
diff -r f1b3a73831c9 -r 1dd52aa8897c ThirdParty/Jasy/jasy/script/api/Text.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ThirdParty/Jasy/jasy/script/api/Text.py	Sat Jan 12 12:11:42 2019 +0100
@@ -0,0 +1,38 @@
+#
+# Jasy - Web Tooling Framework
+# Copyright 2010-2012 Zynga Inc.
+# Copyright 2013-2014 Sebastian Werner
+#
+
+from __future__ import unicode_literals
+
+import re
+import jasy.core.Console as Console
+
+
+# Used to filter first paragraph from HTML
+paragraphExtract = re.compile(r"^(.*?)(\. |\? |\! |$)")
+newlineMatcher = re.compile(r"\n")
+
+# Used to remove markup sequences after doc processing of comment text
+stripMarkup = re.compile(r"<.*?>")
+
+def extractSummary(text):
+    try:
+        text = stripMarkup.sub("", newlineMatcher.sub(" ", text))
+        matched = paragraphExtract.match(text)
+    except TypeError:
+        matched = None
+
+    if matched:
+        summary = matched.group(1)
+        if summary is not None:
+            if not summary.endswith((".", "!", "?")):
+                summary = summary.strip() + "."
+            return summary
+
+    else:
+        Console.warn("Unable to extract summary for: %s", text)
+
+    return None
+

eric ide

mercurial