Support relative markdown link navigation #3

Closed
opened 2026-05-19 02:29:21 +00:00 by ldraney · 0 comments
Owner

Type

Feature

Lineage

  • Project: mdview
  • Plan: n/a
  • Phase: n/a

Repo

ldraney/mdview

User Story

As a user, I want to click relative links to other .md files (e.g. docs/user-stories.md) in the rendered view and have them render through mdview, so I can navigate a doc tree in the browser.

Context

Currently mdview only renders the single file passed via CLI. Markdown docs commonly link to each other with relative paths. These links should resolve to the mdview renderer, not 404.

Description

  • Derive a base directory from MDVIEW_FILE
  • Add a catch-all route that serves any .md file relative to that base dir
  • Post-process rendered HTML to rewrite .md hrefs to mdview routes
  • Keep root / rendering the original entry file

File Targets

  • config/routes.rb -- add catch-all route
  • app/controllers/markdown_controller.rb -- path resolution, link rewriting

Acceptance Criteria

  • Clicking a relative .md link navigates to the rendered file
  • Links to non-.md files are left untouched
  • Path traversal (../../../etc/passwd) is blocked
  • Root / still renders the entry file

Test Expectations

  • README with [link](docs/foo.md) renders, click navigates to foo.md
  • Mermaid diagrams work on sub-pages too

Constraints

  • Files must be within the base directory (no escaping)
  • Non-existent files show a clear 404

Checklist

  • Catch-all route
  • Path resolution in controller
  • Link rewriting in rendered HTML
  • Path traversal guard
  • Visual test

Follows from initial scaffold and #1.

### Type Feature ### Lineage - Project: mdview - Plan: n/a - Phase: n/a ### Repo ldraney/mdview ### User Story As a user, I want to click relative links to other `.md` files (e.g. `docs/user-stories.md`) in the rendered view and have them render through mdview, so I can navigate a doc tree in the browser. ### Context Currently mdview only renders the single file passed via CLI. Markdown docs commonly link to each other with relative paths. These links should resolve to the mdview renderer, not 404. ### Description - Derive a base directory from `MDVIEW_FILE` - Add a catch-all route that serves any `.md` file relative to that base dir - Post-process rendered HTML to rewrite `.md` hrefs to mdview routes - Keep root `/` rendering the original entry file ### File Targets - `config/routes.rb` -- add catch-all route - `app/controllers/markdown_controller.rb` -- path resolution, link rewriting ### Acceptance Criteria - Clicking a relative `.md` link navigates to the rendered file - Links to non-`.md` files are left untouched - Path traversal (`../../../etc/passwd`) is blocked - Root `/` still renders the entry file ### Test Expectations - README with `[link](docs/foo.md)` renders, click navigates to foo.md - Mermaid diagrams work on sub-pages too ### Constraints - Files must be within the base directory (no escaping) - Non-existent files show a clear 404 ### Checklist - [ ] Catch-all route - [ ] Path resolution in controller - [ ] Link rewriting in rendered HTML - [ ] Path traversal guard - [ ] Visual test ### Related Follows from initial scaffold and #1.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ldraney/mdview#3
No description provided.