Files
SuperminarenandClaude Sonnet 5.5 874838f525 Swedish adaptation: Instegscertifikat and HAREC
- Editions replaced by INSTEG, HAREC and UPPGRADERING (Instegscertifikat -> HAREC)
- Question pool optional; simulator, homework tool and solutions switch off without one
- All UI strings, templates, renderers and project JS localised to sv-SE
  (decimal comma, Swedish non-breaking-space rules, Å/Ä/Ö in Morse table)
- DARC branding, membership CTA and German links removed; attribution footer added
- Page names centralised in src/pages.py
- README and docs rewritten in Swedish

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-10-10 15:03:02 +02:00

59 lines
1.3 KiB
Python

import re
from mistletoe.span_token import SpanToken
class Unit(SpanToken):
units = [
"A",
"Ah",
"A/mm²",
"baud",
"bit",
"bit/s",
"dB",
"dBi",
"dBm",
"dBW",
"F",
"J",
"Hz",
"H",
"cm",
"m",
"m²",
"Ohm",
"ohm",
"ppm",
"pps",
"s",
"V",
"W",
"Wh",
"°",
"%",
]
prefixes = ["p", "n", "μ", "m", "k", "M", "G"]
pattern = re.compile(
# Check for word boundary at start of value ensures only numeric values are caught.
r"\b(?P<value>[0-9,]+) ?(?P<prefix>"
# Group all prefixes together in a capture group
# Empty string at end of list is required so the group always exists in the resulting match
+ "|".join(prefixes + [""])
+ ")(?P<unit>"
# Group all units together in a capture group.
+ "|".join(units)
# Word boundary check at end of unit to ensure proper handling of units like A, Ah etc.
+ r")(?!\w)"
)
value: str
prefix: str
unit: str
def __init__(self, match: re.Match):
self.value = match.group("value")
self.prefix = match.group("prefix") or ""
self.unit = match.group("unit")