How to use the html.entities.entitydefs function in html

To help you get started, we’ve selected a few html examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IfcOpenShell / IfcOpenShell / src / ifcexpressparser / documentation.py View on Github external
def description(item):
    global name_to_oid, oid_to_desc, oid_to_name, oid_to_pid
    oid = name_to_oid.get(item,0)
    desc = oid_to_desc.get(oid, None)
    if desc:
        for a,b in entitydefs.items(): desc = desc.replace("&%s;"%a,b)
        desc = desc.replace("\r","")
        for r,s in regices: desc = r.sub(s,desc)
        desc = desc.strip()
        return desc.split("\n")
    else: return []
github lino-framework / lino / lino / utils / html2text.py View on Github external
def name2cp(k):
    if k == 'apos':
        return ord("'")
    if hasattr(htmlentitydefs, "name2codepoint"):  # requires Python 2.3
        return htmlentitydefs.name2codepoint[k]
    else:
        k = htmlentitydefs.entitydefs[k]
        if k.startswith("&#") and k.endswith(";"):
            return int(k[2:-1])  # not in latin-1
        return ord(codecs.latin_1_decode(k)[0])
github andriyko / sublime-robot-framework-assistant / rfassistant / external / html2text.py View on Github external
def name2cp(k):
    if k == 'apos': return ord("'")
    if hasattr(htmlentitydefs, "name2codepoint"): # requires Python 2.3
        return htmlentitydefs.name2codepoint[k]
    else:
        k = htmlentitydefs.entitydefs[k]
        if k.startswith("&#") and k.endswith(";"): return int(k[2:-1]) # not in latin-1
        return ord(codecs.latin_1_decode(k)[0])
github soimort / you-get / src / you_get / util / strings.py View on Github external
        string = re.sub(r'&[^;]+;', lambda m: entitydefs[m.group(0)[1:-1]], string)
        return string
github louipc / turses / turses / ui.py View on Github external
def entity_replacer(m):
        entity = m.group(1)
        if entity in entitydefs:
            return entitydefs[entity]
        else:
            return m.group(0)
github push-things / django-th / django_th / html_entities.py View on Github external
    def html_entity_decode_char(self, m, defs=htmlentities.entitydefs):
        """
            decode html entity into one of the html char
        """
        try:
            char = defs[m.group(1)]
            return "&{char};".format(char=char)
        except ValueError:
            return m.group(0)
        except KeyError:
            return m.group(0)
github SergeySatskiy / codimension / thirdparty / diff2html / diff2html.py View on Github external
def __init__(self, filename, encoding):
        if isinstance( filename, StringIO.StringIO ):
            self._file = filename
        else:
            self._file = open(filename, "wb") if filename else sys.stdout
        self._encoding = encoding

        # See which of the HTML entities of interest are supported by this encoding.
        self._char_replacements = {}
        for code_point,html_enity_name in entitydefs.codepoint2name.iteritems():
            char = unichr(code_point)
            try:
                char.encode(encoding)
            except UnicodeEncodeError:
                self._char_replacements[char] = "&" + html_enity_name + ";"
        self._char_replacements.update((unichr(i),".") for i in xrange(32) if unichr(i) not in u"\t\n\r")
        self._dbg_saw_html = False
github PyAr / OpenLex / modules / html2text.py View on Github external
def name2cp(k):
    if k == 'apos':
        return ord("'")
    if hasattr(htmlentitydefs, "name2codepoint"):  # requires Python 2.3
        return htmlentitydefs.name2codepoint[k]
    else:
        k = htmlentitydefs.entitydefs[k]
        if k.startswith("&#") and k.endswith(";"):
            return int(k[2:-1])  # not in latin-1
        return ord(codecs.latin_1_decode(k)[0])
github louipc / turses / turses / ui.py View on Github external
def entity_replacer(m):
        entity = m.group(1)
        if entity in entitydefs:
            return entitydefs[entity]
        else:
            return m.group(0)
github nate-parrott / astro-bot / html2text.py View on Github external
def name2cp(k):
    if k == 'apos': return ord("'")
    if hasattr(htmlentitydefs, "name2codepoint"): # requires Python 2.3
        return htmlentitydefs.name2codepoint[k]
    else:
        k = htmlentitydefs.entitydefs[k]
        if k.startswith("&#") and k.endswith(";"): return int(k[2:-1]) # not in latin-1
        return ord(codecs.latin_1_decode(k)[0])