Rename options names

This commit is contained in:
yuin 2019-05-06 01:14:17 +09:00
parent 28b28e34bb
commit d9164d2556
6 changed files with 29 additions and 34 deletions

View file

@ -161,7 +161,7 @@ You can overwrite the substitutions by `extensions.WithTypographicSubstitutions`
markdown := goldmark.New( markdown := goldmark.New(
goldmark.WithExtensions( goldmark.WithExtensions(
extension.NewTypographer( extension.NewTypographer(
extension.WithTypographicSubstitutions(extension.TypographerSubstitutions{ extension.WithTypographicSubstitutions(extension.TypographicSubstitutions{
extension.LeftSingleQuote: []byte("‚"), extension.LeftSingleQuote: []byte("‚"),
extension.RightSingleQuote: nil, // nil disables a substitution extension.RightSingleQuote: nil, // nil disables a substitution
}), }),

View file

@ -62,7 +62,7 @@ func newDefaultSubstitutions() [][]byte {
// SetOption implements SetOptioner. // SetOption implements SetOptioner.
func (b *TypographerConfig) SetOption(name parser.OptionName, value interface{}) { func (b *TypographerConfig) SetOption(name parser.OptionName, value interface{}) {
switch name { switch name {
case TypographicSubstitutions: case optTypographicSubstitutions:
b.Substitutions = value.([][]byte) b.Substitutions = value.([][]byte)
} }
} }
@ -73,19 +73,17 @@ type TypographerOption interface {
SetTypographerOption(*TypographerConfig) SetTypographerOption(*TypographerConfig)
} }
// TypographicSubstitutions is an otpion name that specify replacement text for const optTypographicSubstitutions parser.OptionName = "TypographicSubstitutions"
// punctuations.
const TypographicSubstitutions parser.OptionName = "TypographicSubstitutions"
// TypographerSubstitutions is a list of the substitutions for the Typographer extension. // TypographicSubstitutions is a list of the substitutions for the Typographer extension.
type TypographerSubstitutions map[TypographicPunctuation][]byte type TypographicSubstitutions map[TypographicPunctuation][]byte
type withTypographicSubstitutions struct { type withTypographicSubstitutions struct {
value [][]byte value [][]byte
} }
func (o *withTypographicSubstitutions) SetParserOption(c *parser.Config) { func (o *withTypographicSubstitutions) SetParserOption(c *parser.Config) {
c.Options[TypographicSubstitutions] = o.value c.Options[optTypographicSubstitutions] = o.value
} }
func (o *withTypographicSubstitutions) SetTypographerOption(p *TypographerConfig) { func (o *withTypographicSubstitutions) SetTypographerOption(p *TypographerConfig) {

View file

@ -15,9 +15,9 @@ type HeadingConfig struct {
// SetOption implements SetOptioner. // SetOption implements SetOptioner.
func (b *HeadingConfig) SetOption(name OptionName, value interface{}) { func (b *HeadingConfig) SetOption(name OptionName, value interface{}) {
switch name { switch name {
case AutoHeadingID: case optAutoHeadingID:
b.AutoHeadingID = true b.AutoHeadingID = true
case Attribute: case optAttribute:
b.Attribute = true b.Attribute = true
} }
} }
@ -29,13 +29,13 @@ type HeadingOption interface {
} }
// AutoHeadingID is an option name that enables auto IDs for headings. // AutoHeadingID is an option name that enables auto IDs for headings.
var AutoHeadingID OptionName = "AutoHeadingID" const optAutoHeadingID OptionName = "AutoHeadingID"
type withAutoHeadingID struct { type withAutoHeadingID struct {
} }
func (o *withAutoHeadingID) SetParserOption(c *Config) { func (o *withAutoHeadingID) SetParserOption(c *Config) {
c.Options[AutoHeadingID] = true c.Options[optAutoHeadingID] = true
} }
func (o *withAutoHeadingID) SetHeadingOption(p *HeadingConfig) { func (o *withAutoHeadingID) SetHeadingOption(p *HeadingConfig) {

View file

@ -17,25 +17,25 @@ type HTMLConfig struct {
// SetOption implements SetOptioner. // SetOption implements SetOptioner.
func (b *HTMLConfig) SetOption(name OptionName, value interface{}) { func (b *HTMLConfig) SetOption(name OptionName, value interface{}) {
switch name { switch name {
case FilterTags: case optFilterTags:
b.FilterTags = value.(map[string]bool) b.FilterTags = value.(map[string]bool)
} }
} }
// A HTMLOption interface sets options for the raw HTML parsers. // A HTMLOption interface sets options for the raw HTML parsers.
type HTMLOption interface { type HTMLOption interface {
Option
SetHTMLOption(*HTMLConfig) SetHTMLOption(*HTMLConfig)
} }
// FilterTags is an otpion name that specify forbidden tag names. const optFilterTags OptionName = "FilterTags"
const FilterTags OptionName = "FilterTags"
type withFilterTags struct { type withFilterTags struct {
value map[string]bool value map[string]bool
} }
func (o *withFilterTags) SetParserOption(c *Config) { func (o *withFilterTags) SetParserOption(c *Config) {
c.Options[FilterTags] = o.value c.Options[optFilterTags] = o.value
} }
func (o *withFilterTags) SetHTMLOption(p *HTMLConfig) { 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. // WithFilterTags is a functional otpion that specify forbidden tag names.
func WithFilterTags(names ...string) interface { func WithFilterTags(names ...string) HTMLOption {
Option
HTMLOption
} {
m := map[string]bool{} m := map[string]bool{}
for _, name := range names { for _, name := range names {
m[name] = true m[name] = true

View file

@ -382,13 +382,13 @@ type Option interface {
type OptionName string type OptionName string
// Attribute is an option name that spacify attributes of elements. // Attribute is an option name that spacify attributes of elements.
const Attribute OptionName = "Attribute" const optAttribute OptionName = "Attribute"
type withAttribute struct { type withAttribute struct {
} }
func (o *withAttribute) SetParserOption(c *Config) { func (o *withAttribute) SetParserOption(c *Config) {
c.Options[Attribute] = true c.Options[optAttribute] = true
} }
// WithAttribute is a functional option that enables custom attributes. // WithAttribute is a functional option that enables custom attributes.

View file

@ -31,13 +31,13 @@ func NewConfig() Config {
// SetOption implements renderer.NodeRenderer.SetOption. // SetOption implements renderer.NodeRenderer.SetOption.
func (c *Config) SetOption(name renderer.OptionName, value interface{}) { func (c *Config) SetOption(name renderer.OptionName, value interface{}) {
switch name { switch name {
case HardWraps: case optHardWraps:
c.HardWraps = value.(bool) c.HardWraps = value.(bool)
case XHTML: case optXHTML:
c.XHTML = value.(bool) c.XHTML = value.(bool)
case Unsafe: case optUnsafe:
c.Unsafe = value.(bool) c.Unsafe = value.(bool)
case TextWriter: case optTextWriter:
c.Writer = value.(Writer) c.Writer = value.(Writer)
} }
} }
@ -48,14 +48,14 @@ type Option interface {
} }
// TextWriter is an option name used in WithWriter. // TextWriter is an option name used in WithWriter.
const TextWriter renderer.OptionName = "Writer" const optTextWriter renderer.OptionName = "Writer"
type withWriter struct { type withWriter struct {
value Writer value Writer
} }
func (o *withWriter) SetConfig(c *renderer.Config) { func (o *withWriter) SetConfig(c *renderer.Config) {
c.Options[TextWriter] = o.value c.Options[optTextWriter] = o.value
} }
func (o *withWriter) SetHTMLOption(c *Config) { func (o *withWriter) SetHTMLOption(c *Config) {
@ -72,13 +72,13 @@ func WithWriter(writer Writer) interface {
} }
// HardWraps is an option name used in WithHardWraps. // HardWraps is an option name used in WithHardWraps.
const HardWraps renderer.OptionName = "HardWraps" const optHardWraps renderer.OptionName = "HardWraps"
type withHardWraps struct { type withHardWraps struct {
} }
func (o *withHardWraps) SetConfig(c *renderer.Config) { func (o *withHardWraps) SetConfig(c *renderer.Config) {
c.Options[HardWraps] = true c.Options[optHardWraps] = true
} }
func (o *withHardWraps) SetHTMLOption(c *Config) { func (o *withHardWraps) SetHTMLOption(c *Config) {
@ -95,13 +95,13 @@ func WithHardWraps() interface {
} }
// XHTML is an option name used in WithXHTML. // XHTML is an option name used in WithXHTML.
const XHTML renderer.OptionName = "XHTML" const optXHTML renderer.OptionName = "XHTML"
type withXHTML struct { type withXHTML struct {
} }
func (o *withXHTML) SetConfig(c *renderer.Config) { func (o *withXHTML) SetConfig(c *renderer.Config) {
c.Options[XHTML] = true c.Options[optXHTML] = true
} }
func (o *withXHTML) SetHTMLOption(c *Config) { func (o *withXHTML) SetHTMLOption(c *Config) {
@ -118,13 +118,13 @@ func WithXHTML() interface {
} }
// Unsafe is an option name used in WithUnsafe. // Unsafe is an option name used in WithUnsafe.
const Unsafe renderer.OptionName = "Unsafe" const optUnsafe renderer.OptionName = "Unsafe"
type withUnsafe struct { type withUnsafe struct {
} }
func (o *withUnsafe) SetConfig(c *renderer.Config) { func (o *withUnsafe) SetConfig(c *renderer.Config) {
c.Options[Unsafe] = true c.Options[optUnsafe] = true
} }
func (o *withUnsafe) SetHTMLOption(c *Config) { func (o *withUnsafe) SetHTMLOption(c *Config) {