示例#1
0
def render_cp(char):
    """
    Render the code point(s) of a character.

    :param char: The char object to render.
    :returns: HTML string of the code points.
    """
    if isinstance(char, RangeChar):
        return mark_safe('U+{first_c} … U+{last_c}'.format(
            first_c=cp_to_str(char.first_cp),
            last_c=cp_to_str(char.last_cp),
        ))
    else:
        return format_html_join(" ", "U+{}",
                                ((cp_to_str(c), )
                                 for c in char.cp))
示例#2
0
def _serialize_data(lgr, data):
    """
    Serialize data to XML.

    :param lgr: The LGR structure to serialize.
    :param data: Data root node.
    """
    for char in lgr.repertoire:
        attributes = {}
        if char.comment is not None:
            attributes['comment'] = char.comment
        if char.when is not None:
            attributes['when'] = char.when
        if char.not_when is not None:
            attributes['not-when'] = char.not_when
        if len(char.references) > 0:
            attributes['ref'] = ' '.join(str(r) for r in char.references)
        if len(char.tags) > 0:
            attributes['tag'] = ' '.join(char.tags)
        if isinstance(char, RangeChar):
            tag = 'range'
            attributes['first-cp'] = cp_to_str(char.first_cp)
            attributes['last-cp'] = cp_to_str(char.last_cp)
        elif isinstance(char, Char) or isinstance(char, CharSequence):
            tag = 'char'
            attributes['cp'] = ' '.join('%04X' % c for c in char.cp)

        char_node = etree.SubElement(data, tag, **attributes)

        for variant in char.get_variants():
            variant_attributes = {}
            if variant.type is not None:
                variant_attributes['type'] = variant.type
            if variant.when is not None:
                variant_attributes['when'] = variant.when
            if variant.not_when is not None:
                variant_attributes['not-when'] = variant.not_when
            if variant.comment is not None:
                variant_attributes['comment'] = variant.comment
            if len(variant.references) > 0:
                variant_attributes['ref'] = ' '.join(
                    str(r) for r in variant.references)

            variant_attributes['cp'] = ' '.join(
                cp_to_str(c) for c in variant.cp)
            etree.SubElement(char_node, 'var', **variant_attributes)
示例#3
0
def render_char(char):
    """
    Render a char in HTML.

    Input:
        * char: The char object to render.
    Output:
        * HTML string to display
    """
    if isinstance(char, RangeChar):
        return mark_safe('U+{first_c} ({first_u}) … '
                         'U+{last_c} ({last_u})'.format(
            first_c=cp_to_str(char.first_cp),
            first_u=HTML_UNICODE_FORMAT % char.first_cp,
            last_c=cp_to_str(char.last_cp),
            last_u=HTML_UNICODE_FORMAT % char.last_cp,
        ))
    else:
        out = format_html_join(" ", "U+{} ({})", ((cp_to_str(c), mark_safe(HTML_UNICODE_FORMAT % c)) for c in char.cp))
        if len(char.cp) > 1:
            out += mark_safe(" [<bdi>{}</bdi>]".format("".join("&#x{:06X};".format(c) for c in char.cp)))
        return out
示例#4
0
def render_cp_or_sequence(cp_or_sequence):
    """
    Render the code point(s) of a list unique or list of code points..

    :param cp_or_sequence: Sequence of code point to add to the class.
    :returns: HTML string of the code point sequence
    """
    if isinstance(cp_or_sequence, int):
        cp_or_sequence = [cp_or_sequence]

    out = format_html_join(" ", "U+{} ({})", ((cp_to_str(c), mark_safe(HTML_UNICODE_FORMAT % c)) for c in cp_or_sequence))
    if len(cp_or_sequence) > 1:
        out += mark_safe(" [<bdi>{}</bdi>]".format("".join("&#x{:06X};".format(c) for c in cp_or_sequence)))
    return out
示例#5
0
文件: char.py 项目: cnxtech/lgr-core
 def __repr__(self):
     return "<Variant: %s>" % ' '.join(cp_to_str(c) for c in self.cp)
示例#6
0
文件: char.py 项目: cnxtech/lgr-core
 def __repr__(self):
     return '<RangeChar: %s (%s - %s)>' % (' '.join(
         cp_to_str(c) for c in self.cp), cp_to_str(
             self.first_cp), cp_to_str(self.last_cp))
示例#7
0
文件: char.py 项目: cnxtech/lgr-core
 def __repr__(self):
     return '<%s: %s>' % (self.__class__.__name__, ' '.join(
         cp_to_str(c) for c in self.cp))