本文整理汇总了Golang中html.EscapeString函数的典型用法代码示例。如果您正苦于以下问题:Golang EscapeString函数的具体用法?Golang EscapeString怎么用?Golang EscapeString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EscapeString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: StoreMessage
func (h *Handler) StoreMessage(c web.C, w http.ResponseWriter, r *http.Request) {
room := r.PostFormValue("room")
if room == "" {
fmt.Fprintf(w, response.New().WithError(errors.New("No room specified. Skipping.")).Json())
return
}
msg := map[string]interface{}{
"room": html.EscapeString(r.PostFormValue("room")),
"author": html.EscapeString(r.PostFormValue("author")),
"message": html.EscapeString(r.PostFormValue("message")),
"at": serializer.ParseJavaScriptTime(r.PostFormValue("time")),
}
logForReq(c, fmt.Sprintf("Inserting %s", msg))
message, err := h.DB.InsertMessage(msg)
if err != nil {
errMsg := fmt.Sprintf("Could not insert message %s: %s", msg, err.Error())
http.Error(w, response.New().WithError(errors.New(errMsg)).Json(), 500)
return
}
fmt.Fprintf(w, response.New().WithMessage(message).Json())
}
示例2: Format
func (HTMLFormatter) Format(element Element) string {
switch el := element.(type) {
case *Document:
return `<!DOCTYPE html>
<html>
<head>
` + HTML.documentHeader(el) + `
</head>
<body>
<div class="container">
<h1 class="page-header">` + html.EscapeString(el.Title) + `</h1>
` + HTML.formatContent(el.Contents()) + `
</div>
<script src="/js/bootstrap.js" async></script>
</body>
</html>`
case *Italic:
return "<em>" + HTML.formatContent(el.Contents()) + "</em>"
case *Bold:
return "<strong>" + HTML.formatContent(el.Contents()) + "</strong>"
case *LineBreak:
return "<br>"
case *Paragraph:
return "<p>" + HTML.formatContent(el.Contents()) + "</p>"
case *Image:
return "<img src=\"" + html.EscapeString(el.URL) + "\" alt=\"" + html.EscapeString(el.Description) + "\" title=\"" + html.EscapeString(el.Description) + "\">"
case *Link:
return "<a href=\"" + html.EscapeString(el.URL) + "\">" + HTML.formatContent(el.Contents()) + "</a>"
case *LeafElement:
return html.EscapeString(el.Text)
case *Article:
return "<article><h1>" + el.Title + " <small>" + el.Timestamp.Format("15:04 2 Jan 2006") + "</small></h1>\n" + HTML.formatContent(el.Contents()) + "</article>"
}
return fmt.Sprintf("%#v", element)
}
示例3: getPackageNodes
func getPackageNodes(goCode []ParsedCode) (packageNodes []graph.PackageNode) {
packagesMap := make(map[string]*graph.PackageNode)
//Map the files to their graph.PackageNode
for _, parsedCode := range goCode {
//Get packageNode from map
nodePtr := packagesMap[parsedCode.PackageName()]
if nodePtr == nil {
node := graph.CreatePackageNode(
html.EscapeString(parsedCode.PackageName()),
html.EscapeString(parsedCode.PackagePath()),
nil)
nodePtr = &node
}
//add row
nodePtr.AddPackageNodeRow(graph.CreatePackageNodeRow(
html.EscapeString(parsedCode.FileName()),
htmlEscapeStringArray(parsedCode.Functions()),
htmlEscapeStringArray(parsedCode.Types()),
htmlEscapeStringArray(parsedCode.Variables())))
//put back in map
packagesMap[parsedCode.PackageName()] = nodePtr
}
//Take the graph.PackageNode out of the map and put in an array.
for _, packageNode := range packagesMap {
packageNodes = append(packageNodes, *packageNode)
}
return packageNodes
}
示例4: ServeHTTP
func (sh *SyncHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
sh.lk.Lock()
defer sh.lk.Unlock()
fmt.Fprintf(rw, "<h1>%s to %s Sync Status</h1><p><b>Current status: </b>%s</p>",
sh.fromName, sh.toName, html.EscapeString(sh.status))
fmt.Fprintf(rw, "<h2>Stats:</h2><ul>")
fmt.Fprintf(rw, "<li>Blobs copied: %d</li>", sh.totalCopies)
fmt.Fprintf(rw, "<li>Bytes copied: %d</li>", sh.totalCopyBytes)
if !sh.recentCopyTime.IsZero() {
fmt.Fprintf(rw, "<li>Most recent copy: %s</li>", sh.recentCopyTime.Format(time.RFC3339))
}
fmt.Fprintf(rw, "<li>Copy errors: %d</li>", sh.totalErrors)
fmt.Fprintf(rw, "</ul>")
if len(sh.blobStatus) > 0 {
fmt.Fprintf(rw, "<h2>Current Copies:</h2><ul>")
for blobstr, sfn := range sh.blobStatus {
fmt.Fprintf(rw, "<li>%s: %s</li>\n",
blobstr, html.EscapeString(sfn.String()))
}
fmt.Fprintf(rw, "</ul>")
}
if len(sh.recentErrors) > 0 {
fmt.Fprintf(rw, "<h2>Recent Errors:</h2><ul>")
for _, te := range sh.recentErrors {
fmt.Fprintf(rw, "<li>%s: %s</li>\n",
te.t.Format(time.RFC3339),
html.EscapeString(te.err.Error()))
}
fmt.Fprintf(rw, "</ul>")
}
}
示例5: handleDump
// HTTP handler for _dump
func (h *handler) handleDump() error {
viewName := h.PathVar("view")
base.LogTo("HTTP", "Dump view %q", viewName)
opts := db.Body{"stale": false, "reduce": false}
result, err := h.db.Bucket.View(db.DesignDocSyncGateway, viewName, opts)
if err != nil {
return err
}
title := fmt.Sprintf("/%s: “%s” View", html.EscapeString(h.db.Name), html.EscapeString(viewName))
h.setHeader("Content-Type", `text/html; charset="UTF-8"`)
h.response.Write([]byte(fmt.Sprintf(
`<!DOCTYPE html><html><head><title>%s</title></head><body>
<h1>%s</h1><code>
<table border=1>
`,
title, title)))
h.response.Write([]byte("\t<tr><th>Key</th><th>Value</th><th>ID</th></tr>\n"))
for _, row := range result.Rows {
key, _ := json.Marshal(row.Key)
value, _ := json.Marshal(row.Value)
h.response.Write([]byte(fmt.Sprintf("\t<tr><td>%s</td><td>%s</td><td><em>%s</em></td>",
html.EscapeString(string(key)), html.EscapeString(string(value)), html.EscapeString(row.ID))))
h.response.Write([]byte("</tr>\n"))
}
h.response.Write([]byte("</table>\n</code></html></body>"))
return nil
}
示例6: serveHTTP
func (pr *publishRequest) serveHTTP() {
if !pr.rootpn.Valid() {
pr.rw.WriteHeader(404)
return
}
if pr.Debug() {
pr.rw.Header().Set("Content-Type", "text/html")
pr.pf("I am publish handler at base %q, serving root %q (permanode=%s), suffix %q, subreq %q<hr>",
pr.base, pr.ph.RootName, pr.rootpn, html.EscapeString(pr.suffix), html.EscapeString(pr.subres))
}
if err := pr.findSubject(); err != nil {
if err == os.ErrNotExist {
pr.rw.WriteHeader(404)
return
}
log.Printf("Error looking up %s/%q: %v", pr.rootpn, pr.suffix, err)
pr.rw.WriteHeader(500)
return
}
if pr.Debug() {
pr.pf("<p><b>Subject:</b> <a href='/ui/?p=%s'>%s</a></p>", pr.subject, pr.subject)
return
}
switch pr.SubresourceType() {
case "":
pr.serveSubjectTemplate()
case "b":
// TODO: download a raw blob
case "f": // file download
pr.serveSubresFileDownload()
case "i": // image, scaled
pr.serveSubresImage()
case "s": // static
pr.req.URL.Path = pr.subres[len("/=s"):]
if len(pr.req.URL.Path) <= 1 {
http.Error(pr.rw, "Illegal URL.", http.StatusNotFound)
return
}
file := pr.req.URL.Path[1:]
if m := closurePattern.FindStringSubmatch(file); m != nil {
pr.req.URL.Path = "/" + m[1]
pr.ph.closureHandler.ServeHTTP(pr.rw, pr.req)
return
}
if file == "deps.js" {
serveDepsJS(pr.rw, pr.req, pr.ph.uiDir)
return
}
serveStaticFile(pr.rw, pr.req, uistatic.Files, file)
case "z":
pr.serveZip()
default:
pr.rw.WriteHeader(400)
pr.pf("<p>Invalid or unsupported resource request.</p>")
}
}
示例7: nodeTable
func nodeTable(name string, urls []string) string {
// escape name
name = html.EscapeString(name)
// turn big things like 'how do we eat bananas' into 'how ... bananas'
nameshow := name
if len(name) > 45 {
nameshow = name[:28] + " ... " + name[len(name)-12:]
}
// escape urls
for i := range urls {
urls[i] = html.EscapeString(urls[i])
}
table := fmt.Sprintf("<<table tooltip=\"%s\" border=\"0\" cellborder=\"0\" cellpadding=\"4\">", name)
table += fmt.Sprintf("<tr><td bgcolor=\"black\" align=\"center\"><font color=\"white\"><b> %s </b></font></td></tr>", nameshow)
for _, url := range urls {
// remove url endings on show
urlshow := url
if len(urlshow) > 45 {
urlshow = urlshow[:42] + "..."
}
table += fmt.Sprintf("<tr><td href=\"%s\" target=\"_blank\" tooltip=\"%s\">%s</td></tr>", url, url, url[7:])
}
table += "</table>>"
return table
}
示例8: MyContents
//line _test\conents.ego:1
func MyContents(w io.Writer, u *User) error {
//line _test\conents.ego:2
_, _ = fmt.Fprint(w, "\n\n")
//line _test\conents.ego:4
_, _ = fmt.Fprint(w, "\n\n <h1>Hello ")
//line _test\conents.ego:5
_, _ = fmt.Fprint(w, html.EscapeString(fmt.Sprintf("%v", strings.TrimSpace(u.FirstName))))
//line _test\conents.ego:5
_, _ = fmt.Fprint(w, "!</h1>\n\n <p>Here's a list of your favorite colors:</p>\n <ul>\n ")
//line _test\conents.ego:9
for _, colorName := range u.FavoriteColors {
//line _test\conents.ego:10
_, _ = fmt.Fprint(w, "\n <li>")
//line _test\conents.ego:10
_, _ = fmt.Fprint(w, html.EscapeString(fmt.Sprintf("%v", colorName)))
//line _test\conents.ego:10
_, _ = fmt.Fprint(w, "</li>\n ")
//line _test\conents.ego:11
}
//line _test\conents.ego:12
_, _ = fmt.Fprint(w, "\n </ul>\n\n")
//line _test\conents.ego:14
EgoLayout(w, MyLayout)
//line _test\conents.ego:15
_, _ = fmt.Fprint(w, "\n")
return nil
}
示例9: Execute
func (node *tagOptionNode) Execute(ctx *p2.ExecutionContext, writer p2.TemplateWriter) *p2.Error {
fieldObj := ctx.Public[node.field]
if nil == fieldObj {
return ctx.Error("field '"+node.field+"' is missing.", nil)
}
field, _ := fieldObj.(*revel.Field)
if nil == field {
return ctx.Error(fmt.Sprintf("field '"+node.field+"' isn't Field - %T.", fieldObj), nil)
}
val, err := node.value.Evaluate(ctx)
if err != nil {
return err
}
val_str := val.String()
selected := ""
if field.Flash() == val_str || (field.Flash() == "" && field.Value() == val_str) {
selected = " selected"
}
fmt.Fprintf(writer, `<option value="%s"%s>%s</option>`,
html.EscapeString(val_str), selected, html.EscapeString(node.label))
return nil
}
示例10: escHtml
func escHtml(s string) string {
ns := ""
noesc := false
w := ""
for _, r := range s {
switch {
case r == 1:
noesc = true
if w != "" {
ns += html.EscapeString(w)
w = ""
}
continue
case r == 2:
noesc = false
continue
case noesc:
ns += string(r)
default:
w += string(r)
}
}
if w != "" {
ns += html.EscapeString(w)
}
return ns
}
示例11: handlerLeader
func handlerLeader(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
fmt.Fprintf(w, "trying to set leader \n")
s := r.URL.Path
fmt.Fprintf(w, "\n\n", s, " \n\n")
x := html.EscapeString(r.URL.Path)
fmt.Fprintf(w, "\n x => ", x, " \n")
parts1 := strings.Split(s, "%")
for k1, v1 := range parts1 {
fmt.Fprintf(w, "\n k=", k1, ",v=", v1)
}
//fmt.Fprintf(w, parts[1]," \n")
u, err := url.Parse(s)
if err != nil {
fmt.Fprintf(w, "error receiving parameters, "+err.Error())
} else {
//fmt.Fprintf(w, "raw: ",u.RawQuery)
parts := strings.Split(u.Path, "/")
for k, v := range parts {
fmt.Fprintf(w, "\n k=", k, ",v=", v)
}
/*
if len(parts) != 2 {
fmt.Fprintf(w, "usage: setleader/ip-of-the-leader")
} else {
leaderIP := parts[1]
fmt.Fprintf(w, "leader = ",leaderIP)
}
*/
}
}
示例12: markupById
func markupById(id, text string) string {
color := generateRandomColorFromId(id)
format := "<span foreground=\"%s\">%s</span>"
return fmt.Sprintf(format,
html.EscapeString(color),
html.EscapeString(text))
}
示例13: Home
//line home.ego:1
func Home(w io.Writer, p *Page) error {
//line home.ego:2
_, _ = io.WriteString(w, "\n\n")
//line home.ego:3
Header(w, p)
//line home.ego:4
_, _ = io.WriteString(w, "\n<h1>Hello ")
//line home.ego:4
_, _ = io.WriteString(w, html.EscapeString(fmt.Sprintf("%v", p.Title)))
//line home.ego:4
_, _ = io.WriteString(w, "</h1>\n\n<p>Here's a list of your favorite colors:</p>\n\n<ul>\n\t")
//line home.ego:9
for _, colorName := range p.FavoriteColors {
//line home.ego:10
_, _ = io.WriteString(w, "\n\t<li>")
//line home.ego:10
_, _ = io.WriteString(w, html.EscapeString(fmt.Sprintf("%v", colorName)))
//line home.ego:10
_, _ = io.WriteString(w, "</li>\n\t")
//line home.ego:11
}
//line home.ego:12
_, _ = io.WriteString(w, "\n</ul>\n")
//line home.ego:13
Footer(w, p)
//line home.ego:14
_, _ = io.WriteString(w, "\n")
return nil
}
示例14: writeBrowsePage
func writeBrowsePage(w http.ResponseWriter, r *http.Request, diskSpace string, breadcrumbName []string, breadcrumbLink []string, listing []*pathEntry, uploadUrl string) {
shtml := assetAsString("static/index.html")
pathPart := assetAsString("static/path.htmlpart")
breadcrumbHtml := ""
for i, bn := range breadcrumbName {
bn = html.EscapeString(bn)
bl := html.EscapeString(breadcrumbLink[i])
if i < len(breadcrumbName)-1 {
breadcrumbHtml += " <li><a href='" + bl + "'>" + bn + "</a></li>"
} else {
breadcrumbHtml += " <li class='active'><a href='" + bl + "'>" + bn + "</a></li>"
}
}
pathHtml := ""
for _, path := range listing {
pp := strings.Replace(pathPart, "$PATH_LINK", path.pathLink, 1)
pp = strings.Replace(pp, "$PATH_ICON", path.pathIcon, 1)
pp = strings.Replace(pp, "$PATH_NAME", path.pathName, 1)
pp = strings.Replace(pp, "$FILE_SIZE", path.fileSize, 1)
pathHtml += pp
}
shtml = strings.Replace(shtml, "$DISK_SPACE", diskSpace, 1)
shtml = strings.Replace(shtml, "$BREADCRUMB", breadcrumbHtml, 1)
shtml = strings.Replace(shtml, "$DIRECTORY_LISTING", pathHtml, 1)
shtml = strings.Replace(shtml, "$UPLOAD_URL", uploadUrl, 1)
shtml = strings.Replace(shtml, "$PUBLIC_URL", public_url, 10)
fmt.Fprint(w, shtml)
}
示例15: formatline
func formatline(line string) (markup string) {
line = strings.Trim(line, "\t\r\n ")
if len(line) > 0 {
if strings.HasPrefix(line, ">") && !(strings.HasPrefix(line, ">>") && re_backlink.MatchString(strings.Split(line, " ")[0])) {
// le ebin meme arrows
markup += "<p><span class='memearrows'>"
markup += html.EscapeString(line)
markup += "</span></p>"
} else if strings.HasPrefix(line, "==") && strings.HasSuffix(line, "==") {
// redtext
markup += "<p><span class='redtext'>"
markup += html.EscapeString(line[2 : len(line)-2])
markup += "</span></p>"
} else {
// regular line
markup += "<p>"
// for each word
for _, word := range strings.Split(line, " ") {
// check for backlink
if re_backlink.MatchString(word) {
markup += backlink(word)
} else {
// linkify as needed
word = html.EscapeString(word)
markup += xurls.Strict.ReplaceAllString(word, `<a href="$1">$1</a>`)
}
markup += " "
}
markup += "</p>"
}
}
return
}