diff --git a/asciidoc/shorthand.go b/asciidoc/shorthand.go index 5c071ea6..f460262d 100644 --- a/asciidoc/shorthand.go +++ b/asciidoc/shorthand.go @@ -2,7 +2,6 @@ package asciidoc import ( "fmt" - "regexp" "strings" ) @@ -12,18 +11,18 @@ type ShorthandStyle struct { Set } -func NewShorthandStyle(value Set) *ShorthandStyle { +func NewShorthandStyle(value ...Element) *ShorthandStyle { return &ShorthandStyle{Set: value} } -func (sa *ShorthandStyle) Equals(osa *ShorthandStyle) bool { - if sa == nil { - return osa == nil - } - if osa == nil { - return false +func (sa *ShorthandStyle) Equals(osa Element) bool { + if osa, ok := osa.(*ShorthandStyle); ok { + if osa == nil { + return sa == nil + } + return sa.Set.Equals(osa.Set) } - return sa.Set.Equals(osa.Set) + return false } type ShorthandID struct { @@ -32,18 +31,18 @@ type ShorthandID struct { Set } -func NewShorthandID(value Set) *ShorthandID { +func NewShorthandID(value ...Element) *ShorthandID { return &ShorthandID{Set: value} } -func (sa *ShorthandID) Equals(osa *ShorthandID) bool { - if sa == nil { - return osa == nil - } - if osa == nil { - return false +func (sa *ShorthandID) Equals(osa Element) bool { + if osa, ok := osa.(*ShorthandID); ok { + if osa == nil { + return sa == nil + } + return sa.Set.Equals(osa.Set) } - return sa.Set.Equals(osa.Set) + return false } type ShorthandRole struct { @@ -52,18 +51,18 @@ type ShorthandRole struct { Set } -func NewShorthandRole(value Set) *ShorthandRole { +func NewShorthandRole(value ...Element) *ShorthandRole { return &ShorthandRole{Set: value} } -func (sa *ShorthandRole) Equals(osa *ShorthandRole) bool { - if sa == nil { - return osa == nil - } - if osa == nil { - return false +func (sa *ShorthandRole) Equals(osa Element) bool { + if osa, ok := osa.(*ShorthandRole); ok { + if osa == nil { + return sa == nil + } + return sa.Set.Equals(osa.Set) } - return sa.Set.Equals(osa.Set) + return false } type ShorthandOption struct { @@ -72,18 +71,19 @@ type ShorthandOption struct { Set } -func NewShorthandOption(value Set) *ShorthandOption { +func NewShorthandOption(value ...Element) *ShorthandOption { return &ShorthandOption{Set: value} } -func (sa *ShorthandOption) Equals(osa *ShorthandOption) bool { - if sa == nil { - return osa == nil - } - if osa == nil { - return false +func (sa *ShorthandOption) Equals(osa Element) bool { + if osa, ok := osa.(*ShorthandOption); ok { + if osa == nil { + return sa == nil + } + eq := sa.Set.Equals(osa.Set) + return eq } - return sa.Set.Equals(osa.Set) + return false } type ShorthandAttribute struct { @@ -119,9 +119,11 @@ func (ta *ShorthandAttribute) Equals(oa Attribute) bool { return false } if !ta.Style.Equals(ota.Style) { + fmt.Printf("styles not equal\n") return false } if !ta.ID.Equals(ota.ID) { + fmt.Printf("ids not equal\n") return false } if len(ta.Roles) != len(ota.Roles) { @@ -130,12 +132,19 @@ func (ta *ShorthandAttribute) Equals(oa Attribute) bool { for i, r := range ta.Roles { or := ota.Roles[i] if !r.Equals(or) { + fmt.Printf("role not equal\n") + return false } } + if len(ta.Options) != len(ota.Options) { + return false + } for i, r := range ta.Options { or := ota.Options[i] if !r.Equals(or) { + fmt.Printf("option not equal\n") + return false } } @@ -193,9 +202,6 @@ func NewShorthandAttribute(style any, values []any) (*ShorthandAttribute, error) return sha, nil } -var shorthandAttributePattern = regexp.MustCompile(`^(?P