本文整理汇总了Golang中html/template.HTMLEscape函数的典型用法代码示例。如果您正苦于以下问题:Golang HTMLEscape函数的具体用法?Golang HTMLEscape怎么用?Golang HTMLEscape使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了HTMLEscape函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: formatCode

func formatCode(src []byte, annotations []doc.TypeAnnotation) htemp.HTML {

    // Collect comment positions.
    var (
        comments []doc.TypeAnnotation
        s        scanner.Scanner
    )
    fset := token.NewFileSet()
    file := fset.AddFile("", fset.Base(), len(src))
    s.Init(file, src, nil, scanner.ScanComments)
commentLoop:
    for {
        pos, tok, lit := s.Scan()
        switch tok {
        case token.EOF:
            break commentLoop
        case token.COMMENT:
            p := file.Offset(pos)
            comments = append(comments, doc.TypeAnnotation{Pos: p, End: p + len(lit)})
        }
    }

    // Merge type annotations and comments without modifying the caller's slice
    // of annoations.
    switch {
    case len(comments) == 0:
        // nothing to do
    case len(annotations) == 0:
        annotations = comments
    default:
        annotations = append(comments, annotations...)
        sort.Sort(sortByPos(annotations))
    }

    var buf bytes.Buffer
    last := 0
    for _, a := range annotations {
        htemp.HTMLEscape(&buf, src[last:a.Pos])
        if a.Name != "" {
            p := a.ImportPath
            if p != "" {
                p = "/" + p
            }
            buf.WriteString(`<a href="`)
            buf.WriteString(escapePath(p))
            buf.WriteByte('#')
            buf.WriteString(escapePath(a.Name))
            buf.WriteString(`">`)
            htemp.HTMLEscape(&buf, src[a.Pos:a.End])
            buf.WriteString(`</a>`)
        } else {
            buf.WriteString(`<span class="com">`)
            htemp.HTMLEscape(&buf, src[a.Pos:a.End])
            buf.WriteString(`</span>`)
        }
        last = a.End
    }
    htemp.HTMLEscape(&buf, src[last:])
    return htemp.HTML(buf.String())
}

开发者ID:sbryant,项目名称:gopkgdoc,代码行数:60,代码来源:template.go

示例2: renderElement

func renderElement(element interface{}, contextChain []interface{}, buf io.Writer) error {
    switch elem := element.(type) {
    case *textElement:
        buf.Write(elem.text)
    case *varElement:
        defer func() {
            if r := recover(); r != nil {
                fmt.Printf("Panic while looking up %q: %s\n", elem.name, r)
            }
        }()
        val, err := lookup(contextChain, elem.name, AllowMissingVariables)
        if err != nil {
            return err
        }

        if val.IsValid() {
            if elem.raw {
                fmt.Fprint(buf, val.Interface())
            } else {
                s := fmt.Sprint(val.Interface())
                template.HTMLEscape(buf, []byte(s))
            }
        }
    case *sectionElement:
        if err := renderSection(elem, contextChain, buf); err != nil {
            return err
        }
    case *Template:
        if err := elem.renderTemplate(contextChain, buf); err != nil {
            return err
        }
    }
    return nil
}

开发者ID:ae0000,项目名称:mustache,代码行数:34,代码来源:mustache.go

示例3: login

func login(w http.ResponseWriter, r *http.Request) {
    fmt.Println("method:", r.Method)
    if r.Method == "GET" {
        crutime := time.Now().Unix()
        fmt.Println("crutime = ", crutime)
        h := md5.New()
        s := strconv.FormatInt(crutime, 10)
        fmt.Println("s = ", s)
        io.WriteString(h, s)
        fmt.Println("h's md5 = ", h.Sum(nil))
        token := fmt.Sprintf("%x", h.Sum(nil))
        t, _ := template.ParseFiles("login.gtpl")
        t.Execute(w, token)
    } else {
        r.ParseForm()
        token := r.Form.Get("token")
        if token != "" {
            fmt.Println("token is ", token)
        } else {
            fmt.Println("token is not exists ")
        }
        fmt.Println("username length:", len(r.Form["username"][0]))
        fmt.Println("username:", template.HTMLEscapeString(r.Form.Get("username")))
        fmt.Println("password:", template.HTMLEscapeString(r.Form.Get("password")))
        template.HTMLEscape(w, []byte(r.Form.Get("username")))
    }
}

开发者ID:vinniey,项目名称:findme.biz,代码行数:27,代码来源:http.go

示例4: Example_escape

func Example_escape() {
    const s = `"Fran & Freddie's Diner" <[email protected]>`
    v := []interface{}{`"Fran & Freddie's Diner"`, ' ', `<[email protected]>`}

    fmt.Println(template.HTMLEscapeString(s))
    template.HTMLEscape(os.Stdout, []byte(s))
    fmt.Fprintln(os.Stdout, "")
    fmt.Println(template.HTMLEscaper(v...))

    fmt.Println(template.JSEscapeString(s))
    template.JSEscape(os.Stdout, []byte(s))
    fmt.Fprintln(os.Stdout, "")
    fmt.Println(template.JSEscaper(v...))

    fmt.Println(template.URLQueryEscaper(v...))

    // Output:
    // &#34;Fran &amp; Freddie&#39;s Diner&#34; &lt;[email protected]&gt;
    // &#34;Fran &amp; Freddie&#39;s Diner&#34; &lt;[email protected]&gt;
    // &#34;Fran &amp; Freddie&#39;s Diner&#34;32&lt;[email protected]&gt;
    // \"Fran & Freddie\'s Diner\" \[email protected]\x3E
    // \"Fran & Freddie\'s Diner\" \[email protected]\x3E
    // \"Fran & Freddie\'s Diner\"32\[email protected]\x3E
    // %22Fran+%26+Freddie%27s+Diner%2232%3Ctasty%40example.com%3E

}

开发者ID:wheelcomplex,项目名称:go-1,代码行数:26,代码来源:example_test.go

示例5: login

func login(w http.ResponseWriter, r *http.Request) {
    fmt.Println("method: ", r.Method)
    if r.Method == "GET" {
        curtime := time.Now().Unix()
        h := md5.New()
        io.WriteString(h, strconv.FormatInt(curtime, 10))
        token := fmt.Sprintf("%x", h.Sum(nil))
        t, _ := template.ParseFiles("login.html")
        t.Execute(w, token)
    } else {
        r.ParseForm()
        token := r.Form.Get("token")
        if token != "" {
            fmt.Println("token is ok")
        } else {
            fmt.Println("token is error")
        }
        slice := []string{"apple", "pear", "banana"}
        log.Println(r.Form.Get("fruit"))
        for _, v := range slice {
            if v == r.Form.Get("fruit") {
                fmt.Println(v)
            }

        }
        log.Println("username: ", r.Form["username"])
        log.Println("password: ", r.Form["password"])
        template.HTMLEscape(w, []byte(r.Form.Get("username")))
    }
}

开发者ID:szqh97,项目名称:test,代码行数:30,代码来源:web.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng