diff --git a/README.md b/README.md index 032304d..35733d3 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ You can overwrite the substitutions by `extensions.WithTypographicSubstitutions` markdown := goldmark.New( goldmark.WithExtensions( extension.NewTypographer( - extension.WithTypographicSubstitutions(extension.TypographerSubstitutions{ + extension.WithTypographicSubstitutions(extension.TypographicSubstitutions{ extension.LeftSingleQuote: []byte("‚"), extension.RightSingleQuote: nil, // nil disables a substitution }), diff --git a/extension/typographer.go b/extension/typographer.go index 9978086..490fb5a 100644 --- a/extension/typographer.go +++ b/extension/typographer.go @@ -62,7 +62,7 @@ func newDefaultSubstitutions() [][]byte { // SetOption implements SetOptioner. func (b *TypographerConfig) SetOption(name parser.OptionName, value interface{}) { switch name { - case TypographicSubstitutions: + case optTypographicSubstitutions: b.Substitutions = value.([][]byte) } } @@ -73,19 +73,17 @@ type TypographerOption interface { SetTypographerOption(*TypographerConfig) } -// TypographicSubstitutions is an otpion name that specify replacement text for -// punctuations. -const TypographicSubstitutions parser.OptionName = "TypographicSubstitutions" +const optTypographicSubstitutions parser.OptionName = "TypographicSubstitutions" -// TypographerSubstitutions is a list of the substitutions for the Typographer extension. -type TypographerSubstitutions map[TypographicPunctuation][]byte +// TypographicSubstitutions is a list of the substitutions for the Typographer extension. +type TypographicSubstitutions map[TypographicPunctuation][]byte type withTypographicSubstitutions struct { value [][]byte } func (o *withTypographicSubstitutions) SetParserOption(c *parser.Config) { - c.Options[TypographicSubstitutions] = o.value + c.Options[optTypographicSubstitutions] = o.value } func (o *withTypographicSubstitutions) SetTypographerOption(p *TypographerConfig) { diff --git a/parser/atx_heading.go b/parser/atx_heading.go index abfa788..837a113 100644 --- a/parser/atx_heading.go +++ b/parser/atx_heading.go @@ -15,9 +15,9 @@ type HeadingConfig struct { // SetOption implements SetOptioner. func (b *HeadingConfig) SetOption(name OptionName, value interface{}) { switch name { - case AutoHeadingID: + case optAutoHeadingID: b.AutoHeadingID = true - case Attribute: + case optAttribute: b.Attribute = true } } @@ -29,13 +29,13 @@ type HeadingOption interface { } // AutoHeadingID is an option name that enables auto IDs for headings. -var AutoHeadingID OptionName = "AutoHeadingID" +const optAutoHeadingID OptionName = "AutoHeadingID" type withAutoHeadingID struct { } func (o *withAutoHeadingID) SetParserOption(c *Config) { - c.Options[AutoHeadingID] = true + c.Options[optAutoHeadingID] = true } func (o *withAutoHeadingID) SetHeadingOption(p *HeadingConfig) { diff --git a/parser/html_block.go b/parser/html_block.go index 00085d3..831ba7d 100644 --- a/parser/html_block.go +++ b/parser/html_block.go @@ -17,25 +17,25 @@ type HTMLConfig struct { // SetOption implements SetOptioner. func (b *HTMLConfig) SetOption(name OptionName, value interface{}) { switch name { - case FilterTags: + case optFilterTags: b.FilterTags = value.(map[string]bool) } } // A HTMLOption interface sets options for the raw HTML parsers. type HTMLOption interface { + Option SetHTMLOption(*HTMLConfig) } -// FilterTags is an otpion name that specify forbidden tag names. -const FilterTags OptionName = "FilterTags" +const optFilterTags OptionName = "FilterTags" type withFilterTags struct { value map[string]bool } func (o *withFilterTags) SetParserOption(c *Config) { - c.Options[FilterTags] = o.value + c.Options[optFilterTags] = o.value } func (o *withFilterTags) SetHTMLOption(p *HTMLConfig) { @@ -43,10 +43,7 @@ func (o *withFilterTags) SetHTMLOption(p *HTMLConfig) { } // WithFilterTags is a functional otpion that specify forbidden tag names. -func WithFilterTags(names ...string) interface { - Option - HTMLOption -} { +func WithFilterTags(names ...string) HTMLOption { m := map[string]bool{} for _, name := range names { m[name] = true diff --git a/parser/parser.go b/parser/parser.go index ad1b3c5..4a17413 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -382,13 +382,13 @@ type Option interface { type OptionName string // Attribute is an option name that spacify attributes of elements. -const Attribute OptionName = "Attribute" +const optAttribute OptionName = "Attribute" type withAttribute struct { } func (o *withAttribute) SetParserOption(c *Config) { - c.Options[Attribute] = true + c.Options[optAttribute] = true } // WithAttribute is a functional option that enables custom attributes. diff --git a/renderer/html/html.go b/renderer/html/html.go index 25284c0..182def9 100644 --- a/renderer/html/html.go +++ b/renderer/html/html.go @@ -31,13 +31,13 @@ func NewConfig() Config { // SetOption implements renderer.NodeRenderer.SetOption. func (c *Config) SetOption(name renderer.OptionName, value interface{}) { switch name { - case HardWraps: + case optHardWraps: c.HardWraps = value.(bool) - case XHTML: + case optXHTML: c.XHTML = value.(bool) - case Unsafe: + case optUnsafe: c.Unsafe = value.(bool) - case TextWriter: + case optTextWriter: c.Writer = value.(Writer) } } @@ -48,14 +48,14 @@ type Option interface { } // TextWriter is an option name used in WithWriter. -const TextWriter renderer.OptionName = "Writer" +const optTextWriter renderer.OptionName = "Writer" type withWriter struct { value Writer } func (o *withWriter) SetConfig(c *renderer.Config) { - c.Options[TextWriter] = o.value + c.Options[optTextWriter] = o.value } func (o *withWriter) SetHTMLOption(c *Config) { @@ -72,13 +72,13 @@ func WithWriter(writer Writer) interface { } // HardWraps is an option name used in WithHardWraps. -const HardWraps renderer.OptionName = "HardWraps" +const optHardWraps renderer.OptionName = "HardWraps" type withHardWraps struct { } func (o *withHardWraps) SetConfig(c *renderer.Config) { - c.Options[HardWraps] = true + c.Options[optHardWraps] = true } func (o *withHardWraps) SetHTMLOption(c *Config) { @@ -95,13 +95,13 @@ func WithHardWraps() interface { } // XHTML is an option name used in WithXHTML. -const XHTML renderer.OptionName = "XHTML" +const optXHTML renderer.OptionName = "XHTML" type withXHTML struct { } func (o *withXHTML) SetConfig(c *renderer.Config) { - c.Options[XHTML] = true + c.Options[optXHTML] = true } func (o *withXHTML) SetHTMLOption(c *Config) { @@ -118,13 +118,13 @@ func WithXHTML() interface { } // Unsafe is an option name used in WithUnsafe. -const Unsafe renderer.OptionName = "Unsafe" +const optUnsafe renderer.OptionName = "Unsafe" type withUnsafe struct { } func (o *withUnsafe) SetConfig(c *renderer.Config) { - c.Options[Unsafe] = true + c.Options[optUnsafe] = true } func (o *withUnsafe) SetHTMLOption(c *Config) {