" % configuration['table_alignment']
tbl += "
\n" % configuration['border_width']
for row_idx in range(len(rows)):
columns = rows[row_idx]
tbl += ""
for col_idx in range(len(columns)):
col = columns[col_idx]
tbl += "| "
tbl += col
if row_idx < len(rows) and col_idx < len(columns) - 1:
tbl += " | "
if row_idx < len(rows) - 1:
tbl += "
\n"
tbl += "\n"
tbl += ""
tbl += "
\n"
return tbl
def create_table_with_columns_based_on_newlines(self, paragraph, separator):
rows = []
lines = paragraph.splitlines()
for line in lines:
rows.append(line.split(separator))
return rows
def create_table_with_fixed_number_of_columns(self, paragraph, separator, num_columns):
cells = paragraph.split(separator)
current_row = []
rows = []
for cell in cells:
current_row.append(cell.strip('\n'))
if len(current_row) == num_columns:
rows.append(current_row)
current_row = []
if len(current_row) > 0:
rows.append(current_row)
return rows
class HTMLFormatting(Formatting):
def __init__(self, markup):
super().__init__(markup)
def begin_document(self):
return "\n"
def end_document(self):
return "\n"
def raw_html(self, content):
return content
class TxtParser(object):
def __init__(self):
self.markup = HTMLMarkup()
self.format = HTMLFormatting(self.markup)
self.append_page_break = False
self.create_title = False
self.page_title = ""
self.paragraph_filters = []
self.document_filters = []
def convert(self, content):
converted = self.format.begin_document()
if len(content) > 0:
self.parse_link_aliases_and_find_title(content)
if self.create_title and self.page_title != "":
converted += "\n"
converted += "