refactor: simplify rendering of table cells
This commit is contained in:
@@ -17,6 +17,8 @@ from .tag import Tag
|
|||||||
from .underline import Underline
|
from .underline import Underline
|
||||||
from .unit import Unit
|
from .unit import Unit
|
||||||
|
|
||||||
|
table_alignment = {"l": "left", "c": "center", "r": "right"}
|
||||||
|
|
||||||
|
|
||||||
class FiftyOhmHtmlRenderer(HtmlRenderer):
|
class FiftyOhmHtmlRenderer(HtmlRenderer):
|
||||||
margin_anchor_id = 0
|
margin_anchor_id = 0
|
||||||
@@ -201,14 +203,10 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def render_cell_helper(cell, alignment, type):
|
def render_cell_helper(cell, alignment, type):
|
||||||
if alignment == "l":
|
style = ""
|
||||||
return f"<{type} style='text-align: left;'>{cell}</{type}>"
|
if alignment in table_alignment:
|
||||||
elif alignment == "r":
|
style = f' style="text-align: {table_alignment[alignment]};"'
|
||||||
return f"<{type} style='text-align: right;'>{cell}</{type}>"
|
return f"<{type}{style}>{cell}</{type}>\n"
|
||||||
elif alignment == "c":
|
|
||||||
return f"<{type} style='text-align: center;'>{cell}</{type}>"
|
|
||||||
else:
|
|
||||||
return f"<{type}>{cell}</{type}>"
|
|
||||||
|
|
||||||
def render_table(self, token):
|
def render_table(self, token):
|
||||||
alignment = token.alignment
|
alignment = token.alignment
|
||||||
|
|||||||
Reference in New Issue
Block a user