Setting ids declared in the ``{% schema %}`` of a Liquid file (own and block settings).
(text: str)
| 375 | # --------------------------------------------------------------- definitions |
| 376 | |
| 377 | def _schema_ids(text: str) -> set[str]: |
| 378 | """Setting ids declared in the ``{% schema %}`` of a Liquid file (own and block settings).""" |
| 379 | ids: set[str] = set() |
| 380 | m = re.search(r"\{%-?\s*schema\s*-?%\}(.*?)\{%-?\s*endschema\s*-?%\}", text, re.S) |
| 381 | if not m: |
| 382 | return ids |
| 383 | try: |
| 384 | data = json.loads(m.group(1)) |
| 385 | except ValueError: |
| 386 | return ids |
| 387 | |
| 388 | def walk(o: object) -> None: |
| 389 | if isinstance(o, dict): |
| 390 | sid = o.get("id") |
| 391 | if isinstance(sid, str) and ("type" in o): |
| 392 | ids.add(sid) |
| 393 | for v in o.values(): |
| 394 | walk(v) |
| 395 | elif isinstance(o, list): |
| 396 | for v in o: |
| 397 | walk(v) |
| 398 | |
| 399 | walk(data) |
| 400 | return ids |
| 401 | |
| 402 | |
| 403 | def _schema_scoped(text: str) -> tuple[set[str], set[str]]: |