Documentation
¶
Index ¶
- Variables
- func BuildGatedBody(content string, opts ...Option) string
- func BuildGatedBodyKey(key, content string, opts ...Option) string
- func EndMarker(section string, opts ...Option) string
- func RegisterCommentStyle(ext string, style CommentStyle)
- func RemoveSection(filePath, key string, opts ...Option) error
- func StartMarker(section string, opts ...Option) string
- func UpdateMultiple(filePath string, sections map[string]string, opts ...Option) error
- func UpdateSection(filePath, key, sectionContent string, opts ...Option) error
- type CommentStyle
- type Option
- type Options
Constants ¶
This section is empty.
Variables ¶
var DefaultCommentStyles = map[string]CommentStyle{ ".go": {LinePrefix: "//"}, ".js": {LinePrefix: "//"}, ".ts": {LinePrefix: "//"}, ".tsx": {LinePrefix: "//"}, ".jsx": {LinePrefix: "//"}, ".java": {LinePrefix: "//"}, ".c": {LinePrefix: "//"}, ".h": {LinePrefix: "//"}, ".cpp": {LinePrefix: "//"}, ".rs": {LinePrefix: "//"}, ".swift": {LinePrefix: "//"}, ".cs": {LinePrefix: "//"}, ".zig": {LinePrefix: "//"}, ".py": {LinePrefix: "#"}, ".sh": {LinePrefix: "#"}, ".rb": {LinePrefix: "#"}, ".yml": {LinePrefix: "#"}, ".yaml": {LinePrefix: "#"}, ".toml": {LinePrefix: "#"}, ".env": {LinePrefix: "#"}, ".sql": {LinePrefix: "--"}, ".html": {LinePrefix: "<!--", BlockEnd: "-->", Space: true}, ".md": {LinePrefix: "<!--", BlockEnd: "-->", Space: true}, ".xml": {LinePrefix: "<!--", BlockEnd: "-->", Space: true}, }
Global registry for comment styles overrideable at runtime.
Functions ¶
func BuildGatedBody ¶
BuildGatedBody returns a gated body snippet (unnamed section) with start/end markers surrounding the provided content. Newlines are normalized so the snippet always ends with a trailing newline. The content is placed exactly between markers. Example (markdown): <!-- CANARY:START -->\n<content>\n<!-- CANARY:END -->\n
func BuildGatedBodyKey ¶
BuildGatedBodyKey returns a gated body snippet for a keyed section. Example (markdown): <!-- CANARY:mykey:START -->\n<content>\n<!-- CANARY:mykey:END -->\n
func EndMarker ¶
EndMarker returns the end marker string for a keyed or unnamed section given options.
func RegisterCommentStyle ¶
func RegisterCommentStyle(ext string, style CommentStyle)
RegisterCommentStyle allows external code to override or add a comment style for extension.
func RemoveSection ¶
RemoveSection removes a keyed section.
func StartMarker ¶
StartMarker returns the start marker string for a keyed or unnamed section given options.
func UpdateMultiple ¶
UpdateMultiple updates or inserts multiple keyed sections.
func UpdateSection ¶ added in v0.3.3
UpdateSection updates or inserts the gated section named key in filePath.
key must be non-empty. An unkeyed section cannot be created any more: two tools writing unkeyed sections into the same file have no way to tell their sections apart, which is how a file ends up with duplicates. An unkeyed section that already exists is still adopted -- its body is replaced in place and its markers left as they are -- so files written by older versions keep updating rather than growing a second section beside them.
Types ¶
type CommentStyle ¶
type CommentStyle struct {
// LinePrefix denotes a single-line comment marker (e.g. "//", "#", "--").
LinePrefix string
// BlockStart and BlockEnd denote multi-line comment delimiters (e.g. "/*" and "*/").
BlockStart string
BlockEnd string
// Optional space insertion between delimiters and content for readability.
Space bool
}
CommentStyle describes how comments are represented for a language/file type. Either single-line (LinePrefix) or multi-line (BlockStart/BlockEnd) or both may be set.
func DetectStyleFromExtension ¶
func DetectStyleFromExtension(path string) CommentStyle
DetectStyleFromExtension returns a reasonable default style based on file extension.
type Option ¶
type Option func(*Options)
Option functional option.
func WithBlankLineBefore ¶
func WithBlankLineBefore() Option
WithBlankLineBefore enables blank line insertion.
type Options ¶
type Options struct {
Key string // The logical gating namespace, e.g. "CANARY"
Style CommentStyle
StartToken string // e.g. "START"
EndToken string // e.g. "END"
// If true, enforce blank line preceding an appended section.
EnsureBlankBefore bool
}
Options configures gating behavior.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns a baseline configuration targeting HTML-style comments used in markdown.