"""Wrap every image in an article body so it can carry a CRT overlay. The scanlines belong on the pictures, not on the whole screen. A board showing a photograph was a monitor displaying it; the text around it is just text, and a gradient over the entire page shimmers at non-integer zoom. An cannot host a ::after of its own, so each one gets a wrapper. Done here rather than with CSS :has() because images are not reliably alone in their paragraph, and :has() would miss the ones that are not. """ import re from pelican import signals IMG = re.compile(r']*>') IFRAME = re.compile(r']*>') DIM = re.compile(r'\b(width|height)="(\d+)"') def _wrap(content): body = getattr(content, "_content", None) if not body or "{m.group(0)}', body) def _ratio(content): """Give every embed its own aspect ratio so it can fill the column. The embeds carry fixed pixel sizes from whenever they were pasted in, and they are not all the same shape: four are 16:9 but one is 500x402. Forcing a single ratio would letterbox or crop that one, so each gets the ratio its own attributes describe, and anything without attributes falls back to 16:9. """ body = getattr(content, "_content", None) if not body or "' content._content = IFRAME.sub(sub, body) def register(): signals.content_object_init.connect(_wrap) signals.content_object_init.connect(_ratio)