- 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]>
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import re
|
|
|
|
from mistletoe.block_tokenizer import FileWrapper
|
|
|
|
from renderer.referenced_token import ReferencedToken
|
|
|
|
|
|
class Image(ReferencedToken):
|
|
"""
|
|
Block token for pictures and photos.
|
|
Examples:
|
|
[picture:727:amplitude_period_halvvagor:Positiva och negativa halvvågor hos en sinusvåg]
|
|
[photo:123:n_vattenfall_trx_collage:Vyer av olika transceivrar]
|
|
"""
|
|
|
|
pattern = re.compile(r"^\[(?P<kind>picture|photo):(?P<id>\d+):(?P<marker>[^:\]]+):(?P<text>[^:\]]+)\]$")
|
|
|
|
@classmethod
|
|
def start(cls, line: str):
|
|
return cls.pattern.match(line.strip()) is not None
|
|
|
|
@classmethod
|
|
def check_interrupts_paragraph(cls, lines: FileWrapper):
|
|
line = lines.peek()
|
|
if line is not None:
|
|
return cls.start(line)
|
|
else:
|
|
return False
|
|
|
|
@classmethod
|
|
def read(cls, lines: FileWrapper):
|
|
match = cls.pattern.match(next(lines).strip())
|
|
return match.group("kind"), match.group("id"), match.group("marker"), match.group("text")
|
|
|
|
def __init__(self, match):
|
|
kind, id, marker, text = match
|
|
super().__init__(marker)
|
|
self.kind = kind
|
|
self.id = id
|
|
self.text = text
|