Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make docs preprocessor more generic and update docs #58

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ The server has only been tested with Neovim. Documentation for setting up the la
If you run into issues setting up the language server:

1. Check the existing documentation in `docs/editors/`
2. [Open an issue](https://github.com/joshuadavidthomas/django-language-server/blob/main/../../issues/new) describing your setup and the problems you're encountering
2. [Open an issue](https://github.com/joshuadavidthomas/django-language-server/issues/new) describing your setup and the problems you're encountering
- Include your editor and any relevant configuration
- Share any error messages or unexpected behavior
- The more details, the better!
Expand Down
28 changes: 20 additions & 8 deletions docs/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,25 +270,28 @@ def preview_changes(original: str, processed: str) -> None:
print_change_group(group)


def process_readme(
def process_file(
input: str = "README.md",
output: str = "docs/index.md",
processors: list[ProcessingFunc] | None = None,
preview: bool = True,
description: str | None = None,
) -> bool:
"""
Process README.md with given processing functions.
Process a file with given processing functions.

Args:
input_path: Path to the input README.md file
output_path: Path where the processed file will be saved
input: Path to the input file
output: Path where the processed file will be saved
processors: List of processing functions to apply
preview: Whether to show a preview of changes
description: Optional description for status message

Returns:
bool: True if processing was successful, False otherwise
"""
with console.status("[bold green]Processing README...") as status:
status_msg = f"[bold green]Processing {description or input}..."
with console.status(status_msg) as status:
input_path = Path(input)
output_path = Path(output)

Expand Down Expand Up @@ -442,10 +445,12 @@ def convert_repo_links(repo_url: str) -> ProcessingFunc:
Input:
See the [`LICENSE`](LICENSE) file for more information.
Check the [Neovim](/docs/editors/neovim.md) guide.
Open an [issue](../../issues/new) to report bugs.

Output:
See the [`LICENSE`](https://github.com/username/repo/blob/main/LICENSE) file for more information.
Check the [Neovim](editors/neovim.md) guide.
Open an [issue](https://github.com/username/repo/issues/new) to report bugs.
"""

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

# Handle relative paths with ../ or ./
if "../" in path or "./" in path:
# Special handling for GitHub-specific paths
if "issues/" in path or "pulls/" in path:
clean_path = path.replace("../", "").replace("./", "")
return f"[{text}]({repo_url}/{clean_path})"

# Handle root-relative paths
if path.startswith("/"):
path = path.removeprefix("/")
Expand All @@ -487,8 +499,7 @@ def replace_link(match: re.Match[str]) -> str:


def main():
"""Example usage of the readme processor."""
console.print("[bold blue]README Processor[/bold blue]")
console.print("[bold blue]File Processor[/bold blue]")

processors = [
add_frontmatter({"title": "Home"}),
Expand All @@ -498,11 +509,12 @@ def main():
),
]

success = process_readme(
success = process_file(
input="README.md",
output="docs/index.md",
processors=processors,
preview=True,
description="README.md → docs/index.md",
)

if success:
Expand Down
Loading