Skip to content

Keep Markdown in cleaned comments; add protoc-utils-markdown for shared reference links - #14

Merged
delphyne merged 2 commits into
mainfrom
fix/comment-cleaning-and-markdown-links
Oct 8, 2026
Merged

delphyne merged 2 commits into
mainfrom
fix/comment-cleaning-and-markdown-links

Conversation

@delphyne

@delphyne delphyne commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Two changes that let protoc-gen-markdown and protoc-gen-openapi handle doc-comment Markdown the same way.

Comment cleaning keeps Markdown intact

CommentParser.ParseContext treated any leading non-alphanumeric run as frame chrome, so cleaning ordinary // comments:

  • dropped a leading code span's backtick or a reference link's [ (`entity_type` was… → entity_type` was…),
  • stripped list markers shared by every line (- a / - b → a / b),
  • blanked lines with no alphanumerics, losing code fences and table rules.

Comments with no border lines and no column-zero fence are now treated as plain: only their common leading whitespace is removed and every line in the content range is kept.
Framed, Holub, and JavaDoc comments go through the existing path unchanged.

New module: protoc-utils-markdown

A JVM library (depends on the core library, commonmark-java, slf4j-api) extracted from protoc-gen-markdown's private resolver:

  • ReferenceIndex<T> indexes every message, field, enum, enum value, service, and RPC under every name a comment can use, and resolves labels with protoc-gen-markdown's scope rules. A plugin-supplied function maps each element to its own target type.
  • ReferenceLinkProcessor<T> is a commonmark LinkProcessor with NONE / WARN / FAIL_ON_INVALID modes, referenceLink=<label>=<URL> overrides, and collected failures with a CodeGeneratorResponse-ready summary.
  • MarkdownText renders documents back to CommonMark and flattens them to plain text or a first sentence for fields that can't hold Markdown.

The license allowlist gains BSD-2-Clause (commonmark, as in the plugin repos) and slf4j-api, whose MIT license is declared only in its parent POM.

Release

Consumers pin 1.1.0, so this should be released as 1.1.0 (new module + behavior fix):

  • engine-public/protoc-gen-markdown — adopts the shared resolver
  • engine-public/protoc-gen-openapi — adopts the shared resolver and cleaned comments
  • engine-public/protoc-gen-mermaid — version bump only

Test plan

  • ./gradlew build — 7 new CommentTests cases (leading code span, leading reference, shared reference prefix, bullet list, indented list, fenced code, table) plus all existing comment fixtures unchanged; 18 new tests for the markdown module
  • Consumed via publishToMavenLocal by all three plugins and the Partner API docs build

🤖 Generated with Claude Code

delphyne and others added 2 commits October 8, 2026 11:49
Edge detection treated any leading non-alphanumeric run as frame chrome, so
ordinary // comments lost a leading code span backtick or reference-link
bracket, shared list markers were stripped from every line, and lines with no
alphanumerics (code fences, table rules) were blanked.

Comments with no border lines and no column-zero fence are now treated as
plain: only their common leading whitespace is removed and every line in the
content range is kept. Framed, Holub, and JavaDoc comments keep the existing
behavior.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reference-link resolution, failure reporting, and Markdown-to-plain-text
conversion were implemented separately in protoc-gen-markdown and
protoc-gen-openapi. This module extracts them so both plugins share one
implementation:

- ReferenceIndex indexes every proto element under every name a comment
  can use and resolves labels with protoc-gen-markdown's scope rules,
  mapping elements to a plugin-supplied target type.
- ReferenceLinkProcessor is a commonmark LinkProcessor with NONE / WARN /
  FAIL_ON_INVALID modes, referenceLink URL overrides, and collected
  failures with a CodeGeneratorResponse-ready summary.
- MarkdownText renders documents back to CommonMark and flattens them to
  plain text or a first sentence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@andrewtburns andrewtburns left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did read through each file, and have a good notion of what's going on here.. no obvious errors spotted but kt isn't my finest language

@delphyne
delphyne merged commit 3d392a7 into main Oct 8, 2026
4 checks passed
@delphyne
delphyne deleted the fix/comment-cleaning-and-markdown-links branch October 8, 2026 17:58
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.

2 participants