mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DOCX Output: Handle nested display:table tags with no rows. Fixes #1619662 [Can't Convert Gutenberg AZW3 to DOCX](https://bugs.launchpad.net/calibre/+bug/1619662)
This commit is contained in:
parent
0e16172f28
commit
efcecb8e67
@ -73,7 +73,7 @@ class Cell(object):
|
|||||||
|
|
||||||
BLEVEL = 2
|
BLEVEL = 2
|
||||||
|
|
||||||
def __init__(self, row, html_tag, tag_style):
|
def __init__(self, row, html_tag, tag_style=None):
|
||||||
self.row = row
|
self.row = row
|
||||||
self.table = self.row.table
|
self.table = self.row.table
|
||||||
self.html_tag = html_tag
|
self.html_tag = html_tag
|
||||||
@ -85,6 +85,9 @@ class Cell(object):
|
|||||||
self.col_span = max(0, int(html_tag.get('colspan', 1)))
|
self.col_span = max(0, int(html_tag.get('colspan', 1)))
|
||||||
except Exception:
|
except Exception:
|
||||||
self.col_span = 1
|
self.col_span = 1
|
||||||
|
if tag_style is None:
|
||||||
|
self.valign = 'center'
|
||||||
|
else:
|
||||||
self.valign = {'top':'top', 'bottom':'bottom', 'middle':'center'}.get(tag_style._get('vertical-align'))
|
self.valign = {'top':'top', 'bottom':'bottom', 'middle':'center'}.get(tag_style._get('vertical-align'))
|
||||||
self.items = []
|
self.items = []
|
||||||
self.width = convert_width(tag_style)
|
self.width = convert_width(tag_style)
|
||||||
@ -204,6 +207,7 @@ class Row(object):
|
|||||||
def __init__(self, table, html_tag, tag_style=None):
|
def __init__(self, table, html_tag, tag_style=None):
|
||||||
self.table = table
|
self.table = table
|
||||||
self.html_tag = html_tag
|
self.html_tag = html_tag
|
||||||
|
self.orig_tag_style = tag_style
|
||||||
self.cells = []
|
self.cells = []
|
||||||
self.current_cell = None
|
self.current_cell = None
|
||||||
self.background_color = None if tag_style is None else convert_color(tag_style.backgroundColor)
|
self.background_color = None if tag_style is None else convert_color(tag_style.backgroundColor)
|
||||||
@ -230,6 +234,8 @@ class Row(object):
|
|||||||
self.current_cell.add_block(block)
|
self.current_cell.add_block(block)
|
||||||
|
|
||||||
def add_table(self, table):
|
def add_table(self, table):
|
||||||
|
if self.current_cell is None:
|
||||||
|
self.current_cell = Cell(self, self.html_tag, self.orig_tag_style)
|
||||||
return self.current_cell.add_table(table)
|
return self.current_cell.add_table(table)
|
||||||
|
|
||||||
def serialize(self, parent, makeelement):
|
def serialize(self, parent, makeelement):
|
||||||
@ -244,6 +250,7 @@ class Table(object):
|
|||||||
def __init__(self, namespace, html_tag, tag_style=None):
|
def __init__(self, namespace, html_tag, tag_style=None):
|
||||||
self.namespace = namespace
|
self.namespace = namespace
|
||||||
self.html_tag = html_tag
|
self.html_tag = html_tag
|
||||||
|
self.orig_tag_style = tag_style
|
||||||
self.rows = []
|
self.rows = []
|
||||||
self.current_row = None
|
self.current_row = None
|
||||||
self.width = convert_width(tag_style)
|
self.width = convert_width(tag_style)
|
||||||
@ -324,6 +331,8 @@ class Table(object):
|
|||||||
self.current_row.add_block(block)
|
self.current_row.add_block(block)
|
||||||
|
|
||||||
def add_table(self, table):
|
def add_table(self, table):
|
||||||
|
if self.current_row is None:
|
||||||
|
self.current_row = Row(self, self.html_tag, self.orig_tag_style)
|
||||||
return self.current_row.add_table(table)
|
return self.current_row.add_table(table)
|
||||||
|
|
||||||
def serialize(self, parent):
|
def serialize(self, parent):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user