refactor: use helper to format unit
This commit is contained in:
@@ -12,36 +12,6 @@ from renderer.tag import Tag
|
|||||||
from renderer.underline import Underline
|
from renderer.underline import Underline
|
||||||
from renderer.unit import Unit
|
from renderer.unit import Unit
|
||||||
|
|
||||||
units = {
|
|
||||||
"A": "A",
|
|
||||||
"Ah": "Ah",
|
|
||||||
"A/mm²": "A/mm²",
|
|
||||||
"baud": "baud",
|
|
||||||
"Bit": "Bit",
|
|
||||||
"Bit/s": "Bit/s",
|
|
||||||
"dB": "dB",
|
|
||||||
"dBi": "dBi",
|
|
||||||
"dBm": "dBm",
|
|
||||||
"dBW": "dBW",
|
|
||||||
"F": "F",
|
|
||||||
"J": "J",
|
|
||||||
"Hz": "Hz",
|
|
||||||
"H": "H",
|
|
||||||
"cm": "cm",
|
|
||||||
"m": "m",
|
|
||||||
"m²": "m²",
|
|
||||||
"ppm": "ppm",
|
|
||||||
"pps": "pps",
|
|
||||||
"s": "s",
|
|
||||||
"V": "V",
|
|
||||||
"W": "W",
|
|
||||||
"Wh": "Wh",
|
|
||||||
"°": "°",
|
|
||||||
"%": "%",
|
|
||||||
}
|
|
||||||
|
|
||||||
no_space_units = ["°", "%"]
|
|
||||||
|
|
||||||
|
|
||||||
class FiftyOhmHtmlRenderer(HtmlRenderer):
|
class FiftyOhmHtmlRenderer(HtmlRenderer):
|
||||||
margin_anchor_id = 0
|
margin_anchor_id = 0
|
||||||
@@ -82,14 +52,25 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
|
|||||||
def render_underline(self, token):
|
def render_underline(self, token):
|
||||||
return f"<u>{self.render_inner(token)}</u>"
|
return f"<u>{self.render_inner(token)}</u>"
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def render_unit(token):
|
def render_unit(cls, token):
|
||||||
unit = token.prefix + units[token.unit]
|
unit = token.prefix + cls.format_unit(token.unit)
|
||||||
if token.unit in no_space_units:
|
if token.unit in ["°", "%"]:
|
||||||
return f"{token.value}{unit}"
|
return f"{token.value}{unit}"
|
||||||
else:
|
else:
|
||||||
return f"{token.value} {unit}"
|
return f"{token.value} {unit}"
|
||||||
|
|
||||||
|
units = {
|
||||||
|
"Ohm": "Ω",
|
||||||
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def format_unit(cls, unit):
|
||||||
|
if unit in cls.units.keys():
|
||||||
|
return cls.units[unit]
|
||||||
|
else:
|
||||||
|
return unit
|
||||||
|
|
||||||
def render_thematic_break(self, token):
|
def render_thematic_break(self, token):
|
||||||
self.margin_anchor_id += 1
|
self.margin_anchor_id += 1
|
||||||
return f'<a id="margin_{self.margin_anchor_id}"></a>'
|
return f'<a id="margin_{self.margin_anchor_id}"></a>'
|
||||||
|
|||||||
Reference in New Issue
Block a user