[Bug]: CRLF Markdown frontmatter is not recognized
Issue Origin
Observed or reproduced in a real environment: offline on Windows with Python 3.14.3 and existing PyYAML 6.0.3, using the exact complete MarkdownParser._extract_frontmatter method and its exact initializer regex assignment extracted from current owning source. This was not a full OpenViking package or service run.
Bug Description
The frontmatter pattern in openviking/parse/parsers/markdown.py only accepts LF at its delimiter boundaries:
r"^---\n(.*?)\n---\n"
A valid Windows-authored document with CRLF line endings therefore returns no frontmatter metadata. The equivalent LF document returns the expected title/fields and stripped body.
The current production call path is parse_content -> _compute_layout -> _extract_frontmatter. The layout planner uses the extracted metadata for the title and only removes the block when extract_frontmatter is enabled. The current file reader reads bytes and decodes them without newline translation, so the content path can retain CRLF.
Steps to Reproduce
- Use main
7192600efab4931a78dff83d0ffef9c0e04b45bb(owning file blob4f5ea173616ec32a9cb6a33977748eaed014c41b). - Compare these two ordinary documents with the owning helper:
lf = "---\ntitle: Release Notes\nowner: team\n---\n# Guide\n\nbody text\n"
crlf = lf.replace("\n", "\r\n")
- Execute the complete unmodified helper using its complete actual regex assignment and real PyYAML BaseLoader. A plain state holder supplies that actual regex; no application import or substitute YAML implementation is needed.
- The LF control succeeds; the CRLF case returns the entire input and
None.
Expected Behavior
Both documents yield {"title": "Release Notes", "owner": "team"} and the body after the closing delimiter. Body line endings remain unchanged.
Actual Behavior
LF: expected metadata and body. CRLF: metadata is None, and the frontmatter block is not recognized or stripped.
Minimal Reproducible Example
This is the isolated production-method probe used locally, run from a checkout with PyYAML available:
import __future__, ast, logging, re
from pathlib import Path
from types import SimpleNamespace
import yaml
tree = ast.parse(Path("openviking/parse/parsers/markdown.py").read_text(encoding="utf-8"))
owner = next(n for n in tree.body if isinstance(n, ast.ClassDef) and n.name == "MarkdownParser")
method = next(n for n in owner.body if isinstance(n, ast.FunctionDef) and n.name == "_extract_frontmatter")
init = next(n for n in owner.body if isinstance(n, ast.FunctionDef) and n.name == "__init__")
pattern = next(n for n in init.body if isinstance(n, ast.Assign)
and any(isinstance(t, ast.Attribute) and t.attr == "_frontmatter_pattern" for t in n.targets))
scope = {"yaml": yaml, "logger": logging.getLogger("repro"), "re": re,
"self": SimpleNamespace()}
for nodes in ([method], [pattern]):
exec(compile(ast.Module(body=nodes, type_ignores=[]), "actual-source", "exec",
flags=__future__.annotations.compiler_flag), scope)
lf = "---\ntitle: Release Notes\nowner: team\n---\n# Guide\n\nbody text\n"
for text in (lf, lf.replace("\n", "\r\n")):
print(scope["_extract_frontmatter"](scope["self"], text))
OpenViking Version
main 7192600efab4931a78dff83d0ffef9c0e04b45bb
Python Version
3.14.3; PyYAML 6.0.3 (existing dependency, satisfies pyyaml>=6.0)
Operating System
Windows
Additional Context
I intend to implement and maintain the correction through my own upstream PR: admit an optional carriage return at the three frontmatter delimiter newlines and add LF/CRLF regression coverage in the existing frontmatter tests. The repair should preserve the default stored body and explicit removal behavior.
Related #6547 / #6543 covers paragraph splitting in _smart_split_content; the current scoped PR diff leaves the frontmatter regex unchanged.
AI assistance: source investigation, this exact-method reproduction and this report were prepared by an AI agent. No full parser constructor, package import, resource ingestion, VikingFS, model, service, full suite or CI was executed or claimed.
I'd like to work on this. Planning a small fix to make the frontmatter regex accept CRLF (\r?\n) and add a regression test. Will open a PR shortly.