Skip to content

Commit 5e5cc1c

Browse files
committed
refactor: express flag-boundary check as a single regex
1 parent b50de5f commit 5e5cc1c

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

internal/docgen/mintlify.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,13 @@ func backtickFlags(s string) string {
189189
return strings.Join(parts, "```")
190190
}
191191

192-
// isFlagBoundaryChar reports whether c is a valid character before a flag —
193-
// anything that is not a word char (\w), backtick, slash, or dash.
192+
// nonBoundaryByte matches a single byte that cannot precede a CLI flag:
193+
// a word char (\w), backtick, slash, or dash.
194+
var nonBoundaryByte = regexp.MustCompile("[`/\\w-]")
195+
196+
// isFlagBoundaryChar reports whether c is a valid character before a flag.
194197
func isFlagBoundaryChar(c byte) bool {
195-
switch {
196-
case c == '/', c == '-', c == '`', c == '_':
197-
return false
198-
case c >= 'a' && c <= 'z', c >= 'A' && c <= 'Z', c >= '0' && c <= '9':
199-
return false
200-
}
201-
return true
198+
return !nonBoundaryByte.Match([]byte{c})
202199
}
203200

204201
func backtickFlagsFragment(s string) string {

0 commit comments

Comments
 (0)