Some checks failed
Test Suite / code-quality (push) Has been cancelled
Test Suite / unit-tests (3.11) (push) Has been cancelled
Test Suite / unit-tests (3.12) (push) Has been cancelled
Test Suite / integration-tests (push) Has been cancelled
Test Suite / e2e-tests (push) Has been cancelled
Test Suite / performance-tests (push) Has been cancelled
Test Suite / security-scan (push) Has been cancelled
Test Suite / test-summary (push) Has been cancelled
- Fixed critical CLI function redefinition (E0102): renamed duplicate list() to list_paradigms() - Fixed CLI parameter passing errors (E1120): updated main() calls with standalone_mode=False - Removed 20+ unused imports across 6 files (W0611 optimization) - Added missing final newlines to 10 files (C0304 compliance) - Optimized control flow patterns: removed unnecessary else-after-return - Enhanced string comparisons using 'in' operator for better readability - Maintained pylint score at 8.34/10 while eliminating critical runtime risks Created follow-up Issue #131 for remaining optimizations: - 200 broad exception handling instances - 106 variable shadowing cases - 278 import organization improvements - 391 line length standardizations 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
61 lines
1.8 KiB
Python
61 lines
1.8 KiB
Python
"""
|
|
Front matter parsing functionality for MarkiTect.
|
|
|
|
This module provides YAML front matter parsing for markdown files,
|
|
separating metadata from content.
|
|
"""
|
|
|
|
import re
|
|
import yaml
|
|
from typing import Dict, Tuple, Any
|
|
|
|
|
|
class FrontMatterParser:
|
|
"""Parser for YAML front matter in markdown files."""
|
|
|
|
def __init__(self):
|
|
"""Initialize the front matter parser."""
|
|
pass
|
|
|
|
def parse(self, content: str) -> Tuple[Dict[str, Any], str]:
|
|
"""
|
|
Parse front matter from markdown content.
|
|
|
|
Args:
|
|
content: Raw markdown content that may include YAML front matter
|
|
|
|
Returns:
|
|
Tuple of (front_matter_dict, markdown_content)
|
|
- front_matter_dict: Parsed YAML as dictionary, empty dict if none
|
|
- markdown_content: Markdown content with front matter removed
|
|
"""
|
|
if not content.strip():
|
|
return {}, content
|
|
|
|
# Check if content starts with front matter delimiter
|
|
if not content.strip().startswith('---'):
|
|
return {}, content
|
|
|
|
# Pattern to match YAML front matter
|
|
# Must start with --- at beginning of string, end with --- on its own line
|
|
pattern = r'^---\s*\n(.*?)\n---\s*\n(.*)$'
|
|
match = re.match(pattern, content, re.DOTALL)
|
|
|
|
if not match:
|
|
# No valid front matter found
|
|
return {}, content
|
|
|
|
yaml_content = match.group(1)
|
|
markdown_content = match.group(2)
|
|
|
|
# Parse YAML content
|
|
try:
|
|
front_matter = yaml.safe_load(yaml_content)
|
|
if front_matter is None:
|
|
front_matter = {}
|
|
except yaml.YAMLError:
|
|
# Invalid YAML - return empty dict and preserve content
|
|
front_matter = {}
|
|
|
|
return front_matter, markdown_content
|