mirror of
https://github.com/go-gitea/gitea
synced 2024-11-19 00:11:24 +01:00
86e2789960
* update github.com/PuerkitoBio/goquery * update github.com/alecthomas/chroma * update github.com/blevesearch/bleve/v2 * update github.com/caddyserver/certmagic * update github.com/go-enry/go-enry/v2 * update github.com/go-git/go-billy/v5 * update github.com/go-git/go-git/v5 * update github.com/go-redis/redis/v8 * update github.com/go-testfixtures/testfixtures/v3 * update github.com/jaytaylor/html2text * update github.com/json-iterator/go * update github.com/klauspost/compress * update github.com/markbates/goth * update github.com/mattn/go-isatty * update github.com/mholt/archiver/v3 * update github.com/microcosm-cc/bluemonday * update github.com/minio/minio-go/v7 * update github.com/prometheus/client_golang * update github.com/unrolled/render * update github.com/xanzy/go-gitlab * update github.com/yuin/goldmark * update github.com/yuin/goldmark-highlighting Co-authored-by: techknowlogick <techknowlogick@gitea.io>
120 lines
2.4 KiB
Go
Vendored
120 lines
2.4 KiB
Go
Vendored
package cascadia
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// implements the reverse operation Sel -> string
|
|
|
|
func (c tagSelector) String() string {
|
|
return c.tag
|
|
}
|
|
|
|
func (c idSelector) String() string {
|
|
return "#" + c.id
|
|
}
|
|
|
|
func (c classSelector) String() string {
|
|
return "." + c.class
|
|
}
|
|
|
|
func (c attrSelector) String() string {
|
|
val := c.val
|
|
if c.operation == "#=" {
|
|
val = c.regexp.String()
|
|
} else if c.operation != "" {
|
|
val = fmt.Sprintf(`"%s"`, val)
|
|
}
|
|
return fmt.Sprintf(`[%s%s%s]`, c.key, c.operation, val)
|
|
}
|
|
|
|
func (c relativePseudoClassSelector) String() string {
|
|
return fmt.Sprintf(":%s(%s)", c.name, c.match.String())
|
|
}
|
|
func (c containsPseudoClassSelector) String() string {
|
|
s := "contains"
|
|
if c.own {
|
|
s += "Own"
|
|
}
|
|
return fmt.Sprintf(`:%s("%s")`, s, c.value)
|
|
}
|
|
func (c regexpPseudoClassSelector) String() string {
|
|
s := "matches"
|
|
if c.own {
|
|
s += "Own"
|
|
}
|
|
return fmt.Sprintf(":%s(%s)", s, c.regexp.String())
|
|
}
|
|
func (c nthPseudoClassSelector) String() string {
|
|
if c.a == 0 && c.b == 1 { // special cases
|
|
s := ":first-"
|
|
if c.last {
|
|
s = ":last-"
|
|
}
|
|
if c.ofType {
|
|
s += "of-type"
|
|
} else {
|
|
s += "child"
|
|
}
|
|
return s
|
|
}
|
|
var name string
|
|
switch [2]bool{c.last, c.ofType} {
|
|
case [2]bool{true, true}:
|
|
name = "nth-last-of-type"
|
|
case [2]bool{true, false}:
|
|
name = "nth-last-child"
|
|
case [2]bool{false, true}:
|
|
name = "nth-of-type"
|
|
case [2]bool{false, false}:
|
|
name = "nth-child"
|
|
}
|
|
return fmt.Sprintf(":%s(%dn+%d)", name, c.a, c.b)
|
|
}
|
|
func (c onlyChildPseudoClassSelector) String() string {
|
|
if c.ofType {
|
|
return ":only-of-type"
|
|
}
|
|
return ":only-child"
|
|
}
|
|
func (c inputPseudoClassSelector) String() string {
|
|
return ":input"
|
|
}
|
|
func (c emptyElementPseudoClassSelector) String() string {
|
|
return ":empty"
|
|
}
|
|
func (c rootPseudoClassSelector) String() string {
|
|
return ":root"
|
|
}
|
|
|
|
func (c compoundSelector) String() string {
|
|
if len(c.selectors) == 0 && c.pseudoElement == "" {
|
|
return "*"
|
|
}
|
|
chunks := make([]string, len(c.selectors))
|
|
for i, sel := range c.selectors {
|
|
chunks[i] = sel.String()
|
|
}
|
|
s := strings.Join(chunks, "")
|
|
if c.pseudoElement != "" {
|
|
s += "::" + c.pseudoElement
|
|
}
|
|
return s
|
|
}
|
|
|
|
func (c combinedSelector) String() string {
|
|
start := c.first.String()
|
|
if c.second != nil {
|
|
start += fmt.Sprintf(" %s %s", string(c.combinator), c.second.String())
|
|
}
|
|
return start
|
|
}
|
|
|
|
func (c SelectorGroup) String() string {
|
|
ck := make([]string, len(c))
|
|
for i, s := range c {
|
|
ck[i] = s.String()
|
|
}
|
|
return strings.Join(ck, ", ")
|
|
}
|