Enhance editor and theming
This commit is contained in:
@@ -3,8 +3,26 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from .media import MARKDOWN_EXTENSIONS, WEBPAGE_EXTENSIONS
|
||||
from .markdown_utils import extract_headings
|
||||
|
||||
SUPPORTED_DOCUMENT_EXTENSIONS = MARKDOWN_EXTENSIONS | WEBPAGE_EXTENSIONS
|
||||
|
||||
EXCLUDED_DIR_NAMES = {
|
||||
".git",
|
||||
"__pycache__",
|
||||
".pytest_cache",
|
||||
".mypy_cache",
|
||||
"build",
|
||||
"dist",
|
||||
"logs",
|
||||
"html",
|
||||
"mdhelper_env",
|
||||
"vendor",
|
||||
"venv",
|
||||
".venv",
|
||||
}
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class DocumentEntry:
|
||||
@@ -14,20 +32,20 @@ class DocumentEntry:
|
||||
|
||||
|
||||
def first_heading(path: Path) -> str | None:
|
||||
if path.suffix.lower() not in {".md", ".markdown"}:
|
||||
return None
|
||||
headings = extract_headings(path)
|
||||
return headings[0].title if headings else None
|
||||
|
||||
|
||||
def discover_documents(project_root: Path) -> list[DocumentEntry]:
|
||||
candidates: list[Path] = []
|
||||
|
||||
sample = project_root / "sample.md"
|
||||
if sample.exists():
|
||||
candidates.append(sample)
|
||||
|
||||
docs_dir = project_root / "docs"
|
||||
if docs_dir.exists():
|
||||
candidates.extend(sorted(docs_dir.rglob("*.md")))
|
||||
candidates = [
|
||||
path
|
||||
for path in sorted(project_root.rglob("*"))
|
||||
if path.is_file()
|
||||
and path.suffix.lower() in SUPPORTED_DOCUMENT_EXTENSIONS
|
||||
and not any(part.startswith(".") or part in EXCLUDED_DIR_NAMES for part in path.relative_to(project_root).parts)
|
||||
]
|
||||
|
||||
entries: list[DocumentEntry] = []
|
||||
for path in candidates:
|
||||
|
||||
Reference in New Issue
Block a user