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

Sun, 21 Apr 2019 10:44:57 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 21 Apr 2019 10:44:57 +0200
branch
setup.py
changeset 6963
1d763fbff600
parent 6942
2602857055c5
permissions
-rw-r--r--

setup.py: development finished and moved to default branch.

#
# 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