Ejemplo n.º 1
0
def convert_row(row, row_i, columns_width, row_str, border):
    """Convert row of table.

    Argument:

        row:           taple of row string of hatena syntax and columns values
        row_i:         row index
        columns_width: list of maximum width of each columns
        row_str:       converted row string
        border:        reST table border line string

    """

    for i in range(len(row[1])):
        # numbers of values
        if i < len(row[1]) - 1:
            row_str += ("  " + row[1][i] +
                        " " * (columns_width[i] -
                               utils.length_str(row[1][i])) + ' ')
            if row_i == 0:
                border += (" " + "=" * (columns_width[i] + 2))
        else:
            row_str += ("  " + row[1][i] +
                        " " * (columns_width[i]
                               - utils.length_str(row[1][i]))
                        + '  ')
            if row_i == 0:
                border += (" " + "=" * (columns_width[i] + 2) + ' ')
    return (row_str, border)
Ejemplo n.º 2
0
def get_columns_width_list(table, columns_width):
    """Retrieve list of maximum width of each columns.

    Argument:

        table:         list of rows
        columns_width: list of maximum width of each columns

    """

    for row in table:
        '''
        row is tuple; (pattern, values)
        row[0] is pattern
        row[1] is values list
        '''
        for i in range(len(row[1])):
            if columns_width[i] <= utils.length_str(row[1][i]):
                columns_width[i] = utils.length_str(row[1][i])
            else:
                columns_width[i] = columns_width[i]
    return columns_width
Ejemplo n.º 3
0
def section2rest(string):
    """Convert hatena syntax to reST of section.

    Argument:

        string: text string of blog entry.
    """

    for i in range(2, 4)[::-1]:
        """2:section, 3:subsection"""
        sep = '-' if i == 2 else '^'
        r, m = utils.regex_search('^(\*){%d}(.*)' % i, string)
        if m:
            pat_space = re.compile('^\s+')
            section_str = pat_space.sub('', m.group(2))
            string = r.sub(
                '\n' + section_str + '\n'
                + sep * utils.length_str(section_str) + '\n', string)
    return string
Ejemplo n.º 4
0
def output(title, categories, body):
    body_str = (title + '\n' +
                '=' * utils.length_str(title) + '\n\n' +
                body + '\n\n' + footer(categories))
    return body_str