Пример #1
0
def parse_headers(source_lines, props, toplevel=False):
    """Parse the metadata stored in the content headers."""

    new_data = []; out = new_data.append
    iterative_source = IteratorParser(source_lines)

    for line in iterative_source:

        if line.startswith(':') and line.find(':', 2) != -1:

            marker = line.find(':', 2)
            prop, value = line[1:marker], line[marker+1:].strip()

            if prop.lower().startswith('x-'):
                _strip_prop = True
            else:
                _strip_prop = False

            if not _strip_prop:
                out(line)

            while True:
                try:
                    line = iterative_source.next()
                    if not _strip_prop:
                        out(line)
                except:
                    break
                sline = line.strip()
                if sline and not (sline.startswith(':') and \
                                  sline.find(':', 2) != -1):
                    value += ' ' + sline
                else:
                    iterative_source.push(line)
                    if not _strip_prop:
                        del new_data[-1]
                    break

            prop = prop.lower()

            if prop in props:
                oldvalue = props[prop]
                if isinstance(oldvalue, list):
                    oldvalue.append(value)
                else:
                    props[prop] = [oldvalue, value]
            else:
                props[prop] = value

        else:
            out(line)

    # re.sub('(?sm)\[\[# (.*?)\]\]', render_includes, content)

    return new_data, props
Пример #2
0
def parse_headers(source_lines, props, toplevel=False):
    """Parse the metadata stored in the content headers."""

    new_data = []
    out = new_data.append
    iterative_source = IteratorParser(source_lines)

    for line in iterative_source:

        if line.startswith(':') and line.find(':', 2) != -1:

            marker = line.find(':', 2)
            prop, value = line[1:marker], line[marker + 1:].strip()

            if prop.lower().startswith('x-'):
                _strip_prop = True
            else:
                _strip_prop = False

            if not _strip_prop:
                out(line)

            while True:
                try:
                    line = iterative_source.next()
                    if not _strip_prop:
                        out(line)
                except:
                    break
                sline = line.strip()
                if sline and not (sline.startswith(':') and \
                                  sline.find(':', 2) != -1):
                    value += ' ' + sline
                else:
                    iterative_source.push(line)
                    if not _strip_prop:
                        del new_data[-1]
                    break

            prop = prop.lower()

            if prop in props:
                oldvalue = props[prop]
                if isinstance(oldvalue, list):
                    oldvalue.append(value)
                else:
                    props[prop] = [oldvalue, value]
            else:
                props[prop] = value

        else:
            out(line)

    # re.sub('(?sm)\[\[# (.*?)\]\]', render_includes, content)
    return new_data, props
Пример #3
0
def convert(content):
    """Convert certain characters to prettier typographical syntax."""

    # Remember: the order of the replacements matter...
    content = content.replace(
        '"', '"').replace(
        ' -->', 'HTML-COMMENT-ELEMENT-CLOSE').replace(
        '->', '→').replace(
        '<-', '&larr;').replace(
        '---', '&ndash;').replace(
        '--', '&mdash;').replace(
        '<<', '&laquo;').replace(
        '>>', '&raquo;').replace(
        '(C)','&copy;').replace(    # hmz, why am i promoting ipr? ;p
        '(c)','&copy;').replace(
        '(tm)','&trade;').replace(
        '(TM)','&trade;').replace(
        '(r)','&reg;').replace(
        '(R)','&reg;').replace(
        '...', '&#8230;').replace(
        'HTML-COMMENT-ELEMENT-CLOSE', ' -->')

    icontent = IteratorParser(content)
    content = []

    _scurly = _dcurly = False
    _space = True
    _apply = False

    index = 0
    prev = ''

    while True:

        try:
            char = icontent.next()
        except StopIteration:
            break

        if not (_scurly or _dcurly) and _space:
            if char == "'":
                _scurly = index + 1
            elif char == '"':
                _dcurly = index + 1

        if _scurly and (_scurly != index + 1) and char == "'" and prev != '\\':
            try:
                n = icontent.next()
                if n in PUNCTUATION or n.isspace():
                    _apply = True
                icontent.push(n)
            except:
                _apply = True
            if _apply:
                content[_scurly - 1] = '&lsquo;'
                char = '&rsquo;'
                _scurly = False
            _apply = False
        
        if _dcurly and (_dcurly != index + 1) and char == '"' and prev != '\\':
            try:
                n = icontent.next()
                if n in PUNCTUATION or n.isspace():
                    _apply = True
                icontent.push(n)
            except:
                _apply = True
            if _apply:
                content[_dcurly - 1] = '&ldquo;'
                char = '&rdquo;'
                _dcurly = False
            _apply = False

        content.append(char)
        prev = char
        index += 1
        
        if char.isspace():
            _space = True
        else:
            _space = False

    content = ''.join(content).replace('"', '&quot;')
    content = replace_plexlinks(render_plexlink, content)

    # perhaps === heading === stylee ?

    return content
Пример #4
0
def convert(content):
    """Convert certain characters to prettier typographical syntax."""

    # remember: the order of the replacements matter...

    content = content.replace(
        # '&lt;', '<').replace(
        # '&gt;', '>').replace(
        '&quot;',
        '"').replace(
            # '&amp;', '&').replace(
            ' -->',
            'HTML-COMMENT-ELEMENT-CLOSE'
        ).replace('-&gt;', '&rarr;').replace('<-', '&larr;').replace(
            '---', '&ndash;').replace('--', '&mdash;').replace(
                '<<', '&laquo;').replace('>>', '&raquo;').replace(
                    '(C)',
                    '&copy;').replace(  # hmz, why am i promoting ipr? ;p
                        '(c)', '&copy;').replace('(tm)', '&trade;').replace(
                            '(TM)', '&trade;').replace('(r)', '&reg;').replace(
                                '(R)',
                                '&reg;').replace('...', '&#8230;').replace(
                                    'HTML-COMMENT-ELEMENT-CLOSE', ' -->')

    icontent = IteratorParser(content)
    content = []

    _scurly = _dcurly = False
    _space = True
    _apply = False

    index = 0
    prev = ''

    while True:

        try:
            char = icontent.next()
        except StopIteration:
            break

        if not (_scurly or _dcurly) and _space:
            if char == "'":
                _scurly = index + 1
            elif char == '"':
                _dcurly = index + 1

        if _scurly and (_scurly != index + 1) and char == "'" and prev != '\\':
            try:
                n = icontent.next()
                if n in PUNCTUATION or n.isspace():
                    _apply = True
                icontent.push(n)
            except:
                _apply = True
            if _apply:
                content[_scurly - 1] = '&lsquo;'
                char = '&rsquo;'
                _scurly = False
            _apply = False

        if _dcurly and (_dcurly != index + 1) and char == '"' and prev != '\\':
            try:
                n = icontent.next()
                if n in PUNCTUATION or n.isspace():
                    _apply = True
                icontent.push(n)
            except:
                _apply = True
            if _apply:
                content[_dcurly - 1] = '&ldquo;'
                char = '&rdquo;'
                _dcurly = False
            _apply = False

        content.append(char)
        prev = char
        index += 1

        if char.isspace():
            _space = True
        else:
            _space = False

    content = ''.join(content).replace('"', '&quot;')
    content = replace_plexlinks(render_plexlink, content)

    # perhaps === heading === stylee ?

    return content
Пример #5
0
def convert(content):
    """Convert certain characters to prettier typographical syntax."""

    # remember: the order of the replacements matter...

    content = (
        content.replace(
            # '&lt;', '<').replace(
            # '&gt;', '>').replace(
            "&quot;",
            '"',
        )
        .replace(
            # '&amp;', '&').replace(
            " -->",
            "HTML-COMMENT-ELEMENT-CLOSE",
        )
        .replace("-&gt;", "&rarr;")
        .replace("<-", "&larr;")
        .replace("---", "&ndash;")
        .replace("--", "&mdash;")
        .replace("<<", "&laquo;")
        .replace(">>", "&raquo;")
        .replace("(C)", "&copy;")
        .replace("(c)", "&copy;")  # hmz, why am i promoting ipr? ;p
        .replace("(tm)", "&trade;")
        .replace("(TM)", "&trade;")
        .replace("(r)", "&reg;")
        .replace("(R)", "&reg;")
        .replace("...", "&#8230;")
        .replace("HTML-COMMENT-ELEMENT-CLOSE", " -->")
    )

    icontent = IteratorParser(content)
    content = []

    _scurly = _dcurly = False
    _space = True
    _apply = False

    index = 0
    prev = ""

    while True:

        try:
            char = icontent.next()
        except StopIteration:
            break

        if not (_scurly or _dcurly) and _space:
            if char == "'":
                _scurly = index + 1
            elif char == '"':
                _dcurly = index + 1

        if _scurly and (_scurly != index + 1) and char == "'" and prev != "\\":
            try:
                n = icontent.next()
                if n in PUNCTUATION or n.isspace():
                    _apply = True
                icontent.push(n)
            except:
                _apply = True
            if _apply:
                content[_scurly - 1] = "&lsquo;"
                char = "&rsquo;"
                _scurly = False
            _apply = False

        if _dcurly and (_dcurly != index + 1) and char == '"' and prev != "\\":
            try:
                n = icontent.next()
                if n in PUNCTUATION or n.isspace():
                    _apply = True
                icontent.push(n)
            except:
                _apply = True
            if _apply:
                content[_dcurly - 1] = "&ldquo;"
                char = "&rdquo;"
                _dcurly = False
            _apply = False

        content.append(char)
        prev = char
        index += 1

        if char.isspace():
            _space = True
        else:
            _space = False

    content = "".join(content).replace('"', "&quot;")
    content = replace_plexlinks(render_plexlink, content)

    # perhaps === heading === stylee ?

    return content