Skip to content

Commit 83fc655

Browse files
committed
fix(submit): handle hyphenated HTML tags, fix doc comment placement
- Expand `htmlTagRe` to match custom elements with hyphens (e.g. `<my-component>`) and namespaced tags (e.g. `<xml:tag>`) - Move orphaned doc comment block to directly precede `unwrapParagraphs` so it attaches to the function in godoc
1 parent 210204c commit 83fc655

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

cmd/submit.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -553,18 +553,9 @@ func generatePRBody(g *git.Git, base, head string) (string, error) {
553553
return sb.String(), nil
554554
}
555555

556-
// unwrapParagraphs removes hard line breaks within plain-text paragraphs while
557-
// preserving intentional structure: blank lines, markdown block-level syntax
558-
// (headers, lists, blockquotes, horizontal rules), and code blocks (both fenced
559-
// and indented). This converts the ~72-column convention used in commit messages
560-
// into flowing text suitable for GitHub's markdown renderer.
561-
//
562-
// If HTML tags are found in prose (outside code blocks and inline code spans),
563-
// the entire text is returned as-is — anyone writing raw HTML in a commit message
564-
// is doing something intentional with formatting.
565-
566-
// htmlTagRe matches anything that looks like an HTML tag (e.g. <div>, </span>, <br/>).
567-
var htmlTagRe = regexp.MustCompile(`</?[a-zA-Z][a-zA-Z0-9]*[\s/>]`)
556+
// htmlTagRe matches anything that looks like an HTML tag, including custom
557+
// elements with hyphens (e.g. <my-component>) and namespaced tags (e.g. <xml:tag>).
558+
var htmlTagRe = regexp.MustCompile(`</?[a-zA-Z][-:a-zA-Z0-9]*[\s/>]`)
568559

569560
// inlineCodeRe matches backtick-enclosed inline code spans so we can strip them
570561
// before checking for HTML. Otherwise `<token>` in code would trigger a false positive.
@@ -620,6 +611,15 @@ func containsHTMLOutsideCode(text string) bool {
620611
return false
621612
}
622613

614+
// unwrapParagraphs removes hard line breaks within plain-text paragraphs while
615+
// preserving intentional structure: blank lines, markdown block-level syntax
616+
// (headers, lists, blockquotes, horizontal rules), and code blocks (both fenced
617+
// and indented). This converts the ~72-column convention used in commit messages
618+
// into flowing text suitable for GitHub's markdown renderer.
619+
//
620+
// If HTML tags are found in prose (outside code blocks and inline code spans),
621+
// the entire text is returned as-is — anyone writing raw HTML in a commit message
622+
// is doing something intentional with formatting.
623623
func unwrapParagraphs(text string) string {
624624
if text == "" {
625625
return ""

cmd/submit_internal_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ func TestContainsHTMLOutsideCode(t *testing.T) {
158158
{"HTML in inline code", "Use `<div>` for this", false},
159159
{"HTML in prose AND code block", "<br/>\n\n```\n<div>x</div>\n```", true},
160160
{"angle bracket not HTML", "x < y", false},
161+
{"hyphenated custom element", "Use <my-component> here", true},
162+
{"namespaced XML tag", "The <xml:tag> element", true},
161163
}
162164
for _, tt := range tests {
163165
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)