Documentation ¶
Index ¶
- Variables
- func GetAvailableLanguages(aliases bool) []string
- func GetAvailableStyles() []string
- func GetLanguageByAlias(alias string) string
- func GetLanguageInfo() map[string][]string
- func LoadCustomThemes() error
- func PrintTokens(code string) error
- func ShouldRedact(pos int, ranges []RedactionRange) bool
- type CodeRenderer
- func (r *CodeRenderer) Render() (image.Image, error)
- func (r *CodeRenderer) WithFont(font *fonts.Font) *CodeRenderer
- func (r *CodeRenderer) WithFontName(name string, style *fonts.FontStyle) *CodeRenderer
- func (r *CodeRenderer) WithFontSize(size float64) *CodeRenderer
- func (r *CodeRenderer) WithLanguage(language string) *CodeRenderer
- func (r *CodeRenderer) WithLineHeight(height float64) *CodeRenderer
- func (r *CodeRenderer) WithLineHighlightRange(start, end int) *CodeRenderer
- func (r *CodeRenderer) WithLineNumberPadding(padding int) *CodeRenderer
- func (r *CodeRenderer) WithLineNumbers(show bool) *CodeRenderer
- func (r *CodeRenderer) WithLineRange(start, end int) *CodeRenderer
- func (r *CodeRenderer) WithManualRedaction(x, y, width, height int) *CodeRenderer
- func (r *CodeRenderer) WithMaxWidth(width int) *CodeRenderer
- func (r *CodeRenderer) WithMinWidth(width int) *CodeRenderer
- func (r *CodeRenderer) WithPadding(left, right, top, bottom int) *CodeRenderer
- func (r *CodeRenderer) WithRedactionBlurRadius(radius float64) *CodeRenderer
- func (r *CodeRenderer) WithRedactionEnabled(enabled bool) *CodeRenderer
- func (r *CodeRenderer) WithRedactionPattern(pattern string, name string) *CodeRenderer
- func (r *CodeRenderer) WithRedactionStyle(style RedactionStyle) *CodeRenderer
- func (r *CodeRenderer) WithStyle(style *CodeStyle) *CodeRenderer
- func (r *CodeRenderer) WithTabWidth(width int) *CodeRenderer
- func (r *CodeRenderer) WithTheme(theme string) *CodeRenderer
- type CodeStyle
- type HighlightedCode
- type Line
- type RedactionArea
- type RedactionConfig
- type RedactionPattern
- type RedactionRange
- type RedactionStyle
- type Token
Constants ¶
This section is empty.
Variables ¶
var DefaultRedactionPatterns = []RedactionPattern{ {regexp.MustCompile(`` + `(?i)` + `"` + `(?P<value>` + `(?:` + `sk_(?:live|test)_[\w]{24,}|` + `sk-[\w]{32,}|` + `gh[porsu]_[\w]{36,}|` + `AKIA[\w]{16}|` + `eyJ[\w-_=]+\.eyJ[\w-_=]+\.[\w-_.+/=]+` + `)` + `)` + `"`), "Known Secret Format"}, {regexp.MustCompile(`` + `(?i)` + `(?:\w+)?://` + `[^:]+:` + `(?P<value>[^@\s]+)` + `@`), "URL Password"}, {regexp.MustCompile(`` + `(?im)` + `(?:^|\s|"|,)` + `\s*` + `(?:")?` + `[\w]*` + `(?:` + `key|token|secret|pass(?:word)?|pwd|auth|cred` + `)` + `[\w]*` + `(?:")?\s*` + `(?:[:=]|:=)\s*` + `(?:"|\x60)` + `(?P<value>` + `(?:[^"\x60]|(?:\n|\\n)[^"\x60]*)*?` + `)` + `(?:"|\x60)`, ), "Sensitive Variable"}, }
DefaultRedactionPatterns contains common patterns for sensitive information
Functions ¶
func GetAvailableLanguages ¶
GetAvailableLanguages returns a list of all supported languages
func GetAvailableStyles ¶
func GetAvailableStyles() []string
GetAvailableStyles returns a list of all available syntax highlighting styles
func GetLanguageByAlias ¶
GetLanguageByAlias returns the canonical language name for a given alias
func GetLanguageInfo ¶
GetLanguageInfo returns a map of language names to their aliases
func LoadCustomThemes ¶
func LoadCustomThemes() error
LoadCustomThemes loads all custom themes from the embedded themes directory
func ShouldRedact ¶
func ShouldRedact(pos int, ranges []RedactionRange) bool
ShouldRedact returns true if the given position in the text should be redacted
Types ¶
type CodeRenderer ¶
func DefaultRenderer ¶
func DefaultRenderer(input string) *CodeRenderer
func NewRenderer ¶
func NewRenderer(input string, style *CodeStyle) *CodeRenderer
func (*CodeRenderer) WithFont ¶
func (r *CodeRenderer) WithFont(font *fonts.Font) *CodeRenderer
func (*CodeRenderer) WithFontName ¶
func (r *CodeRenderer) WithFontName(name string, style *fonts.FontStyle) *CodeRenderer
func (*CodeRenderer) WithFontSize ¶
func (r *CodeRenderer) WithFontSize(size float64) *CodeRenderer
func (*CodeRenderer) WithLanguage ¶
func (r *CodeRenderer) WithLanguage(language string) *CodeRenderer
func (*CodeRenderer) WithLineHeight ¶
func (r *CodeRenderer) WithLineHeight(height float64) *CodeRenderer
func (*CodeRenderer) WithLineHighlightRange ¶
func (r *CodeRenderer) WithLineHighlightRange(start, end int) *CodeRenderer
func (*CodeRenderer) WithLineNumberPadding ¶
func (r *CodeRenderer) WithLineNumberPadding(padding int) *CodeRenderer
func (*CodeRenderer) WithLineNumbers ¶
func (r *CodeRenderer) WithLineNumbers(show bool) *CodeRenderer
func (*CodeRenderer) WithLineRange ¶
func (r *CodeRenderer) WithLineRange(start, end int) *CodeRenderer
func (*CodeRenderer) WithManualRedaction ¶
func (r *CodeRenderer) WithManualRedaction(x, y, width, height int) *CodeRenderer
func (*CodeRenderer) WithMaxWidth ¶
func (r *CodeRenderer) WithMaxWidth(width int) *CodeRenderer
func (*CodeRenderer) WithMinWidth ¶
func (r *CodeRenderer) WithMinWidth(width int) *CodeRenderer
func (*CodeRenderer) WithPadding ¶
func (r *CodeRenderer) WithPadding(left, right, top, bottom int) *CodeRenderer
func (*CodeRenderer) WithRedactionBlurRadius ¶
func (r *CodeRenderer) WithRedactionBlurRadius(radius float64) *CodeRenderer
func (*CodeRenderer) WithRedactionEnabled ¶
func (r *CodeRenderer) WithRedactionEnabled(enabled bool) *CodeRenderer
func (*CodeRenderer) WithRedactionPattern ¶
func (r *CodeRenderer) WithRedactionPattern(pattern string, name string) *CodeRenderer
func (*CodeRenderer) WithRedactionStyle ¶
func (r *CodeRenderer) WithRedactionStyle(style RedactionStyle) *CodeRenderer
func (*CodeRenderer) WithStyle ¶
func (r *CodeRenderer) WithStyle(style *CodeStyle) *CodeRenderer
func (*CodeRenderer) WithTabWidth ¶
func (r *CodeRenderer) WithTabWidth(width int) *CodeRenderer
func (*CodeRenderer) WithTheme ¶
func (r *CodeRenderer) WithTheme(theme string) *CodeRenderer
type CodeStyle ¶
type CodeStyle struct { Theme string // The chroma syntax theme to use Language string // The language to highlight Font *fonts.Font // The font to use FontSize float64 // The font size in points LineHeight float64 // The line height multiplier PaddingLeft int // Padding between the code and the left edge PaddingRight int // Padding between the code and the right edge PaddingTop int // Padding between the code and the top edge PaddingBottom int // Padding between the code and the bottom edge LineNumberPadding int // Padding between line numbers and code TabWidth int // Width of tab characters in spaces MinWidth int // Minimum width in pixels (0 means no minimum) MaxWidth int // Maximum width in pixels (0 means no limit) ShowLineNumbers bool // Whether to show line numbers LineRanges []content.LineRange // Ranges of lines to render LineHighlightRanges []content.LineRange // Ranges of lines to highlight RedactionConfig *RedactionConfig // Redaction configuration }
type HighlightedCode ¶
type HighlightedCode struct { Lines []Line // The lines of code with their tokens BackgroundColor color.Color // Background color for the code block GutterColor color.Color // Color for the gutter (line numbers background) LineNumberColor color.Color // Color for line numbers HighlightColor color.Color // Color for highlighted lines CommentColor color.Color // Color for comments HighlightedLines []int // Lines that should be highlighted }
HighlightedCode represents syntax highlighted code ready for rendering
type Line ¶
type Line struct { Tokens []Token // The tokens in this line Highlight bool // Whether this line should be highlighted }
Line represents a single line of highlighted code
type RedactionArea ¶
RedactionArea represents an area to be redacted in the image
type RedactionConfig ¶
type RedactionConfig struct { Enabled bool Style RedactionStyle Patterns []RedactionPattern BlurRadius float64 ManualRedactions []RedactionArea }
RedactionConfig holds configuration for the redaction feature
func NewRedactionConfig ¶
func NewRedactionConfig() *RedactionConfig
NewRedactionConfig creates a new redaction configuration with default settings
func (*RedactionConfig) AddManualRedaction ¶
func (rc *RedactionConfig) AddManualRedaction(x, y, width, height int)
AddManualRedaction adds a manual redaction area
type RedactionPattern ¶
RedactionPattern represents a pattern to match for redaction
type RedactionRange ¶
type RedactionRange struct { StartIndex int EndIndex int Pattern string // Name of the pattern that matched }
RedactionRange represents a range of text that should be redacted
func FindRedactionRanges ¶
func FindRedactionRanges(config *RedactionConfig, text string) []RedactionRange
FindRedactionRanges analyzes the text and returns ranges that should be redacted
type RedactionStyle ¶
type RedactionStyle string
RedactionStyle represents the style of redaction to apply
const ( // RedactionStyleBlock replaces text with block characters RedactionStyleBlock RedactionStyle = "block" // RedactionStyleBlur applies a blur effect to the text RedactionStyleBlur RedactionStyle = "blur" )