app/core/parser.py aktualisiert
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s
All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s
This commit is contained in:
parent
b4b7ea76ab
commit
28d173b8fd
|
|
@ -2,7 +2,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""
|
"""
|
||||||
Modul: app/core/parser.py
|
Modul: app/core/parser.py
|
||||||
Version: 1.7.0 (fault-tolerant)
|
Version: 1.7.1 (fault-tolerant, API-kompatibel)
|
||||||
Datum: 2025-10-01
|
Datum: 2025-10-01
|
||||||
|
|
||||||
Zweck
|
Zweck
|
||||||
|
|
@ -10,7 +10,7 @@ Zweck
|
||||||
Fehlertolerantes Einlesen von Markdown-Dateien mit YAML-Frontmatter.
|
Fehlertolerantes Einlesen von Markdown-Dateien mit YAML-Frontmatter.
|
||||||
Kompatibel zur bisherigen Parser-API, aber robust gegenüber Nicht-UTF-8-Dateien:
|
Kompatibel zur bisherigen Parser-API, aber robust gegenüber Nicht-UTF-8-Dateien:
|
||||||
- Versucht nacheinander: utf-8 → utf-8-sig → cp1252 → latin-1.
|
- Versucht nacheinander: utf-8 → utf-8-sig → cp1252 → latin-1.
|
||||||
- Bei Fallback wird ein JSON-Warnhinweis auf stdout ausgegeben, Import bricht NICHT ab.
|
- Bei Fallback wird ein JSON-Warnhinweis auf stdout ausgegeben; der Import bricht NICHT ab.
|
||||||
- YAML-Frontmatter wird mit '---' am Anfang und '---' als Abschluss erkannt.
|
- YAML-Frontmatter wird mit '---' am Anfang und '---' als Abschluss erkannt.
|
||||||
- extract_wikilinks() normalisiert [[id#anchor|label]] → 'id'.
|
- extract_wikilinks() normalisiert [[id#anchor|label]] → 'id'.
|
||||||
|
|
||||||
|
|
@ -20,17 +20,16 @@ Kompatibel zur bisherigen Parser-API, aber robust gegenüber Nicht-UTF-8-Dateien
|
||||||
- normalize_frontmatter(fm) -> dict
|
- normalize_frontmatter(fm) -> dict
|
||||||
- validate_required_frontmatter(fm, required: tuple[str,...]=("id","title")) -> None
|
- validate_required_frontmatter(fm, required: tuple[str,...]=("id","title")) -> None
|
||||||
- extract_wikilinks(text) -> list[str]
|
- extract_wikilinks(text) -> list[str]
|
||||||
|
- FRONTMATTER_RE (Kompatibilitäts-Konstante; Regex für '---'-Zeilen)
|
||||||
|
|
||||||
Beispiele
|
Beispiele
|
||||||
---------
|
---------
|
||||||
# Einzelnes Markdown lesen
|
|
||||||
from app.core.parser import read_markdown, normalize_frontmatter, validate_required_frontmatter
|
from app.core.parser import read_markdown, normalize_frontmatter, validate_required_frontmatter
|
||||||
parsed = read_markdown("./vault/30_projects/project-demo.md")
|
parsed = read_markdown("./vault/30_projects/project-demo.md")
|
||||||
fm = normalize_frontmatter(parsed.frontmatter)
|
fm = normalize_frontmatter(parsed.frontmatter)
|
||||||
validate_required_frontmatter(fm)
|
validate_required_frontmatter(fm)
|
||||||
body = parsed.body
|
body = parsed.body
|
||||||
|
|
||||||
# Wikilinks extrahieren
|
|
||||||
from app.core.parser import extract_wikilinks
|
from app.core.parser import extract_wikilinks
|
||||||
links = extract_wikilinks(body)
|
links = extract_wikilinks(body)
|
||||||
|
|
||||||
|
|
@ -70,12 +69,14 @@ class ParsedNote:
|
||||||
# Frontmatter-Erkennung
|
# Frontmatter-Erkennung
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
|
|
||||||
# YAML-Frontmatter am Anfang der Datei:
|
# Öffentliche Kompatibilitäts-Konstante: frühere Skripte importieren FRONTMATTER_RE
|
||||||
# ---\n
|
FRONTMATTER_RE = re.compile(r"^\s*---\s*$") # <— public
|
||||||
# <yaml>
|
# Zusätzlich interner Alias (falls jemand ihn referenziert)
|
||||||
# ---\n
|
FRONTMATTER_END = FRONTMATTER_RE # <— public alias
|
||||||
_FRONTMATTER_HEAD = re.compile(r"^\s*---\s*$")
|
|
||||||
_FRONTMATTER_END = re.compile(r"^\s*---\s*$")
|
# interne Namen bleiben bestehen
|
||||||
|
_FRONTMATTER_HEAD = FRONTMATTER_RE
|
||||||
|
_FRONTMATTER_END = FRONTMATTER_RE
|
||||||
|
|
||||||
|
|
||||||
def _split_frontmatter(text: str) -> Tuple[Dict[str, Any], str]:
|
def _split_frontmatter(text: str) -> Tuple[Dict[str, Any], str]:
|
||||||
|
|
@ -229,7 +230,6 @@ def normalize_frontmatter(fm: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
elif isinstance(out["tags"], list):
|
elif isinstance(out["tags"], list):
|
||||||
out["tags"] = [str(t).strip() for t in out["tags"] if t is not None]
|
out["tags"] = [str(t).strip() for t in out["tags"] if t is not None]
|
||||||
else:
|
else:
|
||||||
# Unbekannter Typ → in Liste mit String umwandeln
|
|
||||||
out["tags"] = [str(out["tags"]).strip()] if out["tags"] not in (None, "") else []
|
out["tags"] = [str(out["tags"]).strip()] if out["tags"] not in (None, "") else []
|
||||||
if "embedding_exclude" in out:
|
if "embedding_exclude" in out:
|
||||||
out["embedding_exclude"] = bool(out["embedding_exclude"])
|
out["embedding_exclude"] = bool(out["embedding_exclude"])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user