Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions extension/typographer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ func newDefaultSubstitutions() [][]byte {
return replacements
}

func newUnicodeSubstitutions() [][]byte {
replacements := make([][]byte, typographicPunctuationMax)
replacements[LeftSingleQuote] = []byte("‘")
replacements[RightSingleQuote] = []byte("’")
replacements[LeftDoubleQuote] = []byte("“")
replacements[RightDoubleQuote] = []byte("”")
replacements[EnDash] = []byte("–")
replacements[EmDash] = []byte("—")
replacements[Ellipsis] = []byte("…")
replacements[LeftAngleQuote] = []byte("«")
replacements[RightAngleQuote] = []byte("»")
replacements[Apostrophe] = []byte("’")

return replacements
}

// SetOption implements SetOptioner.
func (b *TypographerConfig) SetOption(name parser.OptionName, value interface{}) {
switch name {
Expand Down Expand Up @@ -113,8 +129,8 @@ func (o *withTypographicSubstitutions) SetTypographerOption(p *TypographerConfig
p.Substitutions = o.value
}

// WithTypographicSubstitutions is a functional otpion that specify replacement text
// for punctuations.
// WithTypographicSubstitutions is a functional option that specifies replacement text
// for punctuations using SGML text entities.
func WithTypographicSubstitutions[T []byte | string](values map[TypographicPunctuation]T) TypographerOption {
replacements := newDefaultSubstitutions()
for k, v := range values {
Expand All @@ -124,6 +140,17 @@ func WithTypographicSubstitutions[T []byte | string](values map[TypographicPunct
return &withTypographicSubstitutions{replacements}
}

// WithTypographicSubstitutions is a functional option that specify replacement text
// for punctuations with Unicode.
func WithTypographicSubstitutionsUnicode[T []byte | string](values map[TypographicPunctuation]T) TypographerOption {
replacements := newUnicodeSubstitutions()
for k, v := range values {
replacements[k] = []byte(v)
}

return &withTypographicSubstitutions{replacements}
}

type typographerDelimiterProcessor struct {
}

Expand Down