Skip to content

Commit d9d0f4e

Browse files
make docs preprocessor more generic and update docs (#58)
1 parent 6924fe7 commit d9d0f4e

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ The server has only been tested with Neovim. Documentation for setting up the la
113113
If you run into issues setting up the language server:
114114

115115
1. Check the existing documentation in `docs/editors/`
116-
2. [Open an issue](https://github.com/joshuadavidthomas/django-language-server/blob/main/../../issues/new) describing your setup and the problems you're encountering
116+
2. [Open an issue](https://github.com/joshuadavidthomas/django-language-server/issues/new) describing your setup and the problems you're encountering
117117
- Include your editor and any relevant configuration
118118
- Share any error messages or unexpected behavior
119119
- The more details, the better!

docs/processor.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,25 +270,28 @@ def preview_changes(original: str, processed: str) -> None:
270270
print_change_group(group)
271271

272272

273-
def process_readme(
273+
def process_file(
274274
input: str = "README.md",
275275
output: str = "docs/index.md",
276276
processors: list[ProcessingFunc] | None = None,
277277
preview: bool = True,
278+
description: str | None = None,
278279
) -> bool:
279280
"""
280-
Process README.md with given processing functions.
281+
Process a file with given processing functions.
281282
282283
Args:
283-
input_path: Path to the input README.md file
284-
output_path: Path where the processed file will be saved
284+
input: Path to the input file
285+
output: Path where the processed file will be saved
285286
processors: List of processing functions to apply
286287
preview: Whether to show a preview of changes
288+
description: Optional description for status message
287289
288290
Returns:
289291
bool: True if processing was successful, False otherwise
290292
"""
291-
with console.status("[bold green]Processing README...") as status:
293+
status_msg = f"[bold green]Processing {description or input}..."
294+
with console.status(status_msg) as status:
292295
input_path = Path(input)
293296
output_path = Path(output)
294297

@@ -442,10 +445,12 @@ def convert_repo_links(repo_url: str) -> ProcessingFunc:
442445
Input:
443446
See the [`LICENSE`](LICENSE) file for more information.
444447
Check the [Neovim](/docs/editors/neovim.md) guide.
448+
Open an [issue](../../issues/new) to report bugs.
445449
446450
Output:
447451
See the [`LICENSE`](https://github.com/username/repo/blob/main/LICENSE) file for more information.
448452
Check the [Neovim](editors/neovim.md) guide.
453+
Open an [issue](https://github.com/username/repo/issues/new) to report bugs.
449454
"""
450455

451456
def processor(content: str) -> str:
@@ -467,6 +472,13 @@ def replace_link(match: re.Match[str]) -> str:
467472
clean_path = path.removeprefix("/docs/").removeprefix("docs/")
468473
return f"[{text}]({clean_path})"
469474

475+
# Handle relative paths with ../ or ./
476+
if "../" in path or "./" in path:
477+
# Special handling for GitHub-specific paths
478+
if "issues/" in path or "pulls/" in path:
479+
clean_path = path.replace("../", "").replace("./", "")
480+
return f"[{text}]({repo_url}/{clean_path})"
481+
470482
# Handle root-relative paths
471483
if path.startswith("/"):
472484
path = path.removeprefix("/")
@@ -487,8 +499,7 @@ def replace_link(match: re.Match[str]) -> str:
487499

488500

489501
def main():
490-
"""Example usage of the readme processor."""
491-
console.print("[bold blue]README Processor[/bold blue]")
502+
console.print("[bold blue]File Processor[/bold blue]")
492503

493504
processors = [
494505
add_frontmatter({"title": "Home"}),
@@ -498,11 +509,12 @@ def main():
498509
),
499510
]
500511

501-
success = process_readme(
512+
success = process_file(
502513
input="README.md",
503514
output="docs/index.md",
504515
processors=processors,
505516
preview=True,
517+
description="README.md → docs/index.md",
506518
)
507519

508520
if success:

0 commit comments

Comments
 (0)