Answer the fourth round: citation check on its own, fences close on their own marker, atomic write, prose
This commit is contained in:
@@ -3,7 +3,7 @@ import re
|
||||
|
||||
from loop_claude.stop import Stop
|
||||
|
||||
FENCE = re.compile(r"^ {0,3}(```|~~~)", re.M)
|
||||
FENCE = re.compile(r"^ {0,3}(`{3,}|~{3,})", re.M)
|
||||
|
||||
|
||||
def read_premises(root: str) -> str | Stop:
|
||||
@@ -27,9 +27,16 @@ def read_premises(root: str) -> str | Stop:
|
||||
|
||||
def sections(text: str) -> dict[str, list[str]]:
|
||||
blocks: list[tuple[str | None, list[str]]] = []
|
||||
fenced = False
|
||||
opener = ""
|
||||
for line in text.splitlines():
|
||||
fenced ^= bool(FENCE.match(line))
|
||||
# A fence closes only on the opener's character, at least as long.
|
||||
if fence := FENCE.match(line):
|
||||
marker = fence.group(1)
|
||||
if not opener:
|
||||
opener = marker
|
||||
elif marker[0] == opener[0] and len(marker) >= len(opener):
|
||||
opener = ""
|
||||
fenced = bool(opener or fence)
|
||||
if not fenced and line.startswith("## "):
|
||||
blocks.append((line.strip()[3:], []))
|
||||
elif not fenced and line.startswith("# "):
|
||||
|
||||
Reference in New Issue
Block a user