Skip to content

Render bare URLs verbatim when re-serializing Markdown - #15

Open
delphyne wants to merge 1 commit into
mainfrom
fix/markdown-bare-url-escaping
Open

delphyne wants to merge 1 commit into
mainfrom
fix/markdown-bare-url-escaping

Conversation

@delphyne

Copy link
Copy Markdown
Collaborator

Problem

MarkdownText.render() round-trips parsed doc comments through commonmark's MarkdownRenderer, which backslash-escapes _ in Text nodes. The parser doesn't autolink bare URLs, so https://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations was emitted as ISO\_8601#Combined\_date\_and\_time\_representations. This only happens when a comment also contains a [Reference] link (the only case where protoc-gen-openapi re-renders), so the same URL showed up in two shapes in the generated OpenAPI and displayed backslashes in Redoc.

Fix

Register a Text node renderer that writes bare http(s):// URLs raw (trimming trailing sentence punctuation) and delegates everything else to CoreMarkdownNodeRenderer, so other text is still escaped.

Testing

  • New ReferenceLinkTests case: URL with underscores, URL followed by a period, and non-URL escaped underscores in the same paragraph.
  • Built protoc-gen-openapi against it and regenerated engine-partner-api: no ISO\_8601 remains in either generated spec; verified in served Redoc and Swagger UI.

🤖 Generated with Claude Code

MarkdownText.render() round-trips parsed doc comments through commonmark's
MarkdownRenderer, which backslash-escapes underscores in Text nodes. A bare
URL is not autolinked by the parser, so https://en.wikipedia.org/wiki/ISO_8601
came out as ISO\_8601 and leaked into generated OpenAPI descriptions whenever
the comment also contained a reference link (the only case that re-renders).

Add a Text node renderer that writes bare http(s) URLs raw and delegates all
other text to the core renderer's escaping.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant