AArevia
Product

Product features · Rectangular CSS grid areas

01

Inspect grid_areas.py for named cells that leave holes inside an area's bounding rectangle.

01

Connection

Base URL, credentials and a reachable server.

02

Selection

A model available through the configured endpoint.

03

Capabilities

Context limits and tool support are determined by the model and server.

Rectangular CSS grid areas

● ● ●Arevia●
A concrete starting point · Rectangular CSS grid areas ×
import re

def grid_areas(rows):
    if type(rows) is not list or any(type(r) is not str for r in rows):
        raise ValueError("grid.rows")
    if not rows:
        return {}
    cells = [r.split() for r in rows]
    width = len(cells[0])
    if not width or any(len(r) != width for r in cells):
        raise ValueError("grid.width")
    groups = {}
    for y, row in enumerate(cells):
        for x, name in enumerate(row):
            if name == ".":
                continue
            if not re.fullmatch(r"[A-Za-z_][A-Za-z0-9_-]*", name):
                raise ValueError("grid.name")
            groups.setdefault(name, []).append((y, x))
    result = {}
    for name, points in groups.items():
        top, bottom = min(y for y,x in points), max(y for y,x in points)+1
        left, right = min(x for y,x in points), max(x for y,x in points)+1
        if len(points) != (bottom-top)*(right-left):
            raise ValueError("grid.rectangle")
        result[name] = (top, bottom, left, right)
    return result
✳Rectangular CSS grid areas
✓ ChangesReview before applying ↗
Illustrative workspace
AI coding workspace

Your next change starts here.

Get the Windows app ↗