mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-09-11 12:17:45 +02:00
19 lines
560 B
Python
19 lines
560 B
Python
from typeguard import typechecked
|
|
from typing import Tuple
|
|
import re
|
|
|
|
@typechecked
|
|
def parse_frontmatter(raw: str) -> Tuple[dict, str]:
|
|
if not raw.startswith("---"):
|
|
return {}, raw
|
|
end = raw.find("---", 3)
|
|
if end == -1:
|
|
return {}, raw
|
|
fm_block = raw[3:end].strip()
|
|
body = raw[end + 3:].strip()
|
|
meta: dict = {}
|
|
for line in fm_block.splitlines():
|
|
m = re.match(r"^(\w[\w_-]*)\s*:\s*(.+)$", line)
|
|
if m:
|
|
meta[m.group(1).strip()] = m.group(2).strip().strip('"').strip("'")
|
|
return meta, body |