From 53a64afd1dda7e7b67914cb1683528118fbe9b3d Mon Sep 17 00:00:00 2001 From: Michael Richardson Date: Thu, 8 Oct 2020 08:43:51 -0500 Subject: [PATCH 001/311] Update defs.bzl --- codelab-elements/tools/defs.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codelab-elements/tools/defs.bzl b/codelab-elements/tools/defs.bzl index 9457bcf16..7ba59af4b 100644 --- a/codelab-elements/tools/defs.bzl +++ b/codelab-elements/tools/defs.bzl @@ -26,7 +26,7 @@ load("@io_bazel_rules_webtesting//web:web.bzl", "web_test_suite") def concat(ext): """Returns a genrule command to concat files with the extension ext.""" - return "ls $(SRCS) | grep -E '\.{ext}$$' | xargs cat > $@".format(ext = ext) + return "ls $(SRCS) | grep -E '\\.{ext}$$' | xargs cat > $@".format(ext = ext) def closure_js_library(**kwargs): """Invokes closure_js_library with non-test compilation defaults. From 2cd336048d3dea76f5257b0610f5952aeeef068f Mon Sep 17 00:00:00 2001 From: Shawn Simister Date: Fri, 9 Oct 2020 09:06:38 -0400 Subject: [PATCH 002/311] Fix empty tables --- claat/render/md.go | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/claat/render/md.go b/claat/render/md.go index 6bf8a3480..554765c2d 100644 --- a/claat/render/md.go +++ b/claat/render/md.go @@ -30,21 +30,22 @@ import ( // MD renders nodes as markdown for the target env. func MD(ctx Context, nodes ...types.Node) (string, error) { var buf bytes.Buffer - if err := WriteMD(&buf, ctx.Env, nodes...); err != nil { + if err := WriteMD(&buf, ctx.Env, ctx.Format, nodes...); err != nil { return "", err } return buf.String(), nil } // WriteMD does the same as MD but outputs rendered markup to w. -func WriteMD(w io.Writer, env string, nodes ...types.Node) error { - mw := mdWriter{w: w, env: env, Prefix: []byte("")} +func WriteMD(w io.Writer, env string, fmt string, nodes ...types.Node) error { + mw := mdWriter{w: w, env: env, format: fmt, Prefix: []byte("")} return mw.write(nodes...) } type mdWriter struct { w io.Writer // output writer env string // target environment + format string // target template err error // error during any writeXxx methods lineStart bool isWritingTableCell bool // used to override lineStart for correct cell formatting @@ -323,6 +324,20 @@ func (mw *mdWriter) youtube(n *types.YouTubeNode) { } func (mw *mdWriter) table(n *types.GridNode) { + // Calculate table inner content length. + contentLength := 0 + for _, row := range n.Rows { + for _, cell := range row { + var nw bytes.Buffer + WriteMD(&nw, mw.env, mw.format, cell.Content.Nodes...) + contentLength += len(bytes.Trim(nw.Bytes(), " \t")) + } + } + // If table content is empty, don't output the table. + if contentLength == 0 { + return + } + mw.writeBytes(newLine) maxcols := maxColsInTable(n) for rowIndex, row := range n.Rows { @@ -330,14 +345,25 @@ func (mw *mdWriter) table(n *types.GridNode) { for _, cell := range row { mw.isWritingTableCell = true mw.writeString(" ") - for _, cn := range cell.Content.Nodes { - cn.MutateBlock(false) // don't treat content as a new block - mw.write(cn) + + // Check cell content for newlines and replace with inline HTML if newlines are present. + var nw bytes.Buffer + WriteMD(&nw, mw.env, mw.format, cell.Content.Nodes...) + if bytes.ContainsRune(nw.Bytes(), '\n') { + for _, cn := range cell.Content.Nodes { + cn.MutateBlock(false) // don't treat content as a new block + var nw2 bytes.Buffer + WriteHTML(&nw2, mw.env, mw.format, cn) + mw.writeBytes(bytes.ReplaceAll(nw2.Bytes(), []byte("\n"), []byte(""))) + } + } else { + mw.writeBytes(nw.Bytes()) } + mw.writeString(" |") } if rowIndex == 0 && len(row) < maxcols { - for i:= 0; i < maxcols - len(row); i++ { + for i := 0; i < maxcols-len(row); i++ { mw.writeString(" |") } } From cf6563700f2cdecbcb79b90c4de70e83d5dbde38 Mon Sep 17 00:00:00 2001 From: Shawn Busolits Date: Fri, 9 Oct 2020 13:42:11 -0400 Subject: [PATCH 003/311] When deep linking to a specific step, don't redirect to user's prior progress. --- codelab-elements/google-codelab/google_codelab.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/codelab-elements/google-codelab/google_codelab.js b/codelab-elements/google-codelab/google_codelab.js index 52d39e1df..80a561d29 100644 --- a/codelab-elements/google-codelab/google_codelab.js +++ b/codelab-elements/google-codelab/google_codelab.js @@ -853,10 +853,12 @@ class Codelab extends HTMLElement { this.renderDrawer_(); this.timeContainer_ = this.querySelectorAll('.codelab-time-container'); + let hasLocationHash = false; if (document.location.hash) { const h = parseInt(document.location.hash.substring(1), 10); if (!isNaN(h) && h) { this.setAttribute(SELECTED_ATTR, document.location.hash.substring(1)); + hasLocationHash = true; } } @@ -864,7 +866,9 @@ class Codelab extends HTMLElement { const progress = this.storage_.get(`progress_${this.id_}`); if (progress && progress !== '0') { this.resumed_ = true; - this.setAttribute(SELECTED_ATTR, progress); + if (!hasLocationHash) { + this.setAttribute(SELECTED_ATTR, progress); + } } this.hasSetup_ = true; From 30eda2f8ebe0777c32d37cb368ffc738a41e0dd7 Mon Sep 17 00:00:00 2001 From: Michael Richardson Date: Fri, 9 Oct 2020 13:56:42 -0500 Subject: [PATCH 004/311] Use bytes.Replace instead of bytes.ReplaceAll --- claat/render/md.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/claat/render/md.go b/claat/render/md.go index 554765c2d..36d3c369d 100644 --- a/claat/render/md.go +++ b/claat/render/md.go @@ -354,7 +354,7 @@ func (mw *mdWriter) table(n *types.GridNode) { cn.MutateBlock(false) // don't treat content as a new block var nw2 bytes.Buffer WriteHTML(&nw2, mw.env, mw.format, cn) - mw.writeBytes(bytes.ReplaceAll(nw2.Bytes(), []byte("\n"), []byte(""))) + mw.writeBytes(bytes.Replace(nw2.Bytes(), []byte("\n"), []byte("")), -1) } } else { mw.writeBytes(nw.Bytes()) From 6e88307a33adee309d5df5e07049ce9b0595bdd5 Mon Sep 17 00:00:00 2001 From: Michael Richardson Date: Fri, 9 Oct 2020 14:00:04 -0500 Subject: [PATCH 005/311] Call GridNode.Empty() instead of walking the table and counting. --- claat/render/md.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/claat/render/md.go b/claat/render/md.go index 36d3c369d..eb9b09ee0 100644 --- a/claat/render/md.go +++ b/claat/render/md.go @@ -324,17 +324,8 @@ func (mw *mdWriter) youtube(n *types.YouTubeNode) { } func (mw *mdWriter) table(n *types.GridNode) { - // Calculate table inner content length. - contentLength := 0 - for _, row := range n.Rows { - for _, cell := range row { - var nw bytes.Buffer - WriteMD(&nw, mw.env, mw.format, cell.Content.Nodes...) - contentLength += len(bytes.Trim(nw.Bytes(), " \t")) - } - } // If table content is empty, don't output the table. - if contentLength == 0 { + if n.Empty() { return } From 084d09e510c9eccd6acf060852e2d5544e46bd00 Mon Sep 17 00:00:00 2001 From: Shawn Busolits Date: Fri, 9 Oct 2020 15:00:35 -0400 Subject: [PATCH 006/311] Update md.go --- claat/render/md.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/claat/render/md.go b/claat/render/md.go index eb9b09ee0..7e2085349 100644 --- a/claat/render/md.go +++ b/claat/render/md.go @@ -345,7 +345,7 @@ func (mw *mdWriter) table(n *types.GridNode) { cn.MutateBlock(false) // don't treat content as a new block var nw2 bytes.Buffer WriteHTML(&nw2, mw.env, mw.format, cn) - mw.writeBytes(bytes.Replace(nw2.Bytes(), []byte("\n"), []byte("")), -1) + mw.writeBytes(bytes.Replace(nw2.Bytes(), []byte("\n"), []byte(""), -1)) } } else { mw.writeBytes(nw.Bytes()) From 887fa75e84af7b8172a08e6969b4d5bf0dcea455 Mon Sep 17 00:00:00 2001 From: Nicolas Garnier Date: Thu, 22 Oct 2020 03:54:46 +0200 Subject: [PATCH 007/311] Fix css specificity issue with codelabs. Upstream fixes of cl/338363637 --- codelab-elements/google-codelab/google_codelab.scss | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/codelab-elements/google-codelab/google_codelab.scss b/codelab-elements/google-codelab/google_codelab.scss index 1e209900e..af78da01b 100644 --- a/codelab-elements/google-codelab/google_codelab.scss +++ b/codelab-elements/google-codelab/google_codelab.scss @@ -22,6 +22,8 @@ google-codelab { padding-top: 64px; } +// stylelint-disable selector-max-id + google-codelab #main { display: flex; flex-direction: column; @@ -118,7 +120,9 @@ google-codelab #fabs .spacer { flex-grow: 1; } -#previous-step, #next-step, #done { +google-codelab #previous-step, +google-codelab #next-step, +google-codelab #done { border-radius: 4px; font-family: 'Google Sans', Arial, sans-serif; font-size: 14px; @@ -140,12 +144,12 @@ google-codelab #fabs .spacer { -webkit-font-smoothing: antialiased; } -#next-step { +google-codelab #next-step { color: #fff; background: #1A73E8; } -#done { +google-codelab #done { background: #1E8E3E; color: #fff; } @@ -154,7 +158,7 @@ google-codelab #fabs a[disappear] { transform: scale(0, 0); } -#done { +google-codelab #done { background: #0f9d58; } From b63f99afdf1f1ac2f74d5235295fdbc8274e9b5f Mon Sep 17 00:00:00 2001 From: Cassie Recher Date: Mon, 26 Oct 2020 23:43:03 +0000 Subject: [PATCH 008/311] Remove doubleQuote constant from HTML renderer. --- claat/render/html.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/claat/render/html.go b/claat/render/html.go index c5eca0e0c..695e456df 100644 --- a/claat/render/html.go +++ b/claat/render/html.go @@ -29,7 +29,6 @@ import ( // TODO: render HTML using golang/x/net/html or template. var ( - doubleQuote = []byte{'"'} lessThan = []byte{'<'} greaterThan = []byte{'>'} newLine = []byte{'\n'} @@ -182,7 +181,7 @@ func (hw *htmlWriter) image(n *types.ImageNode) { } hw.writeString(` src="`) hw.writeString(n.Src) - hw.writeBytes(doubleQuote) + hw.writeString(`"`) hw.writeBytes(greaterThan) } @@ -191,17 +190,17 @@ func (hw *htmlWriter) url(n *types.URLNode) { if n.URL != "" { hw.writeString(` href="`) hw.writeString(n.URL) - hw.writeBytes(doubleQuote) + hw.writeString(`"`) } if n.Name != "" { hw.writeString(` name="`) hw.writeEscape(n.Name) - hw.writeBytes(doubleQuote) + hw.writeString(`"`) } if n.Target != "" { hw.writeString(` target="`) hw.writeEscape(n.Target) - hw.writeBytes(doubleQuote) + hw.writeString(`"`) } hw.writeBytes(greaterThan) hw.write(n.Content.Nodes...) @@ -295,7 +294,7 @@ func (hw *htmlWriter) itemsList(n *types.ItemsListNode) { if n.ListType != "" { hw.writeString(` type="`) hw.writeString(n.ListType) - hw.writeBytes(doubleQuote) + hw.writeString(`"`) } if n.Start > 0 { hw.writeFmt(` start="%d"`, n.Start) @@ -340,8 +339,7 @@ func (hw *htmlWriter) infobox(n *types.InfoboxNode) { func (hw *htmlWriter) survey(n *types.SurveyNode) { hw.writeString(`\n") + hw.writeString("\">\n") for _, g := range n.Groups { hw.writeString("

") hw.writeEscape(g.Name) From ad65ed1c72be7aef1757d3a9d23340c201f87930 Mon Sep 17 00:00:00 2001 From: Cassie Recher Date: Tue, 27 Oct 2020 20:35:18 +0000 Subject: [PATCH 009/311] Skip HTML escaping inside inline blocks. --- claat/render/html.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/claat/render/html.go b/claat/render/html.go index c5eca0e0c..cf5a6dce4 100644 --- a/claat/render/html.go +++ b/claat/render/html.go @@ -146,6 +146,8 @@ func (hw *htmlWriter) writeEscape(s string) { } func (hw *htmlWriter) text(n *types.TextNode) { + s := n.Value + shouldEsc := true if n.Bold { hw.writeString("") } @@ -154,8 +156,11 @@ func (hw *htmlWriter) text(n *types.TextNode) { } if n.Code { hw.writeString("") + shouldEsc = false + } + if shouldEsc { + s = htmlTemplate.HTMLEscapeString(n.Value) } - s := htmlTemplate.HTMLEscapeString(n.Value) s = ReplaceDoubleCurlyBracketsWithEntity(s) hw.writeString(strings.Replace(s, "\n", "
", -1)) if n.Code { From 523466db5b199e0cfc0ec941677cb15bc80aa8df Mon Sep 17 00:00:00 2001 From: Cassie Recher Date: Tue, 27 Oct 2020 20:40:12 +0000 Subject: [PATCH 010/311] Remove lessThan constant from HTML renderer. --- claat/render/html.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/claat/render/html.go b/claat/render/html.go index 695e456df..ad3490f19 100644 --- a/claat/render/html.go +++ b/claat/render/html.go @@ -29,7 +29,6 @@ import ( // TODO: render HTML using golang/x/net/html or template. var ( - lessThan = []byte{'<'} greaterThan = []byte{'>'} newLine = []byte{'\n'} ) @@ -283,7 +282,7 @@ func (hw *htmlWriter) itemsList(n *types.ItemsListNode) { if n.Type() == types.NodeItemsList && (n.Start > 0 || n.ListType != "") { tag = "ol" } - hw.writeBytes(lessThan) + hw.writeString("<") hw.writeString(tag) switch n.Type() { case types.NodeItemsCheck: @@ -356,7 +355,7 @@ func (hw *htmlWriter) survey(n *types.SurveyNode) { func (hw *htmlWriter) header(n *types.HeaderNode) { tag := "h" + strconv.Itoa(n.Level) - hw.writeBytes(lessThan) + hw.writeString("<") hw.writeString(tag) switch n.Type() { case types.NodeHeaderCheck: From 3486d35edda6a31a89f2004aa97a7a7f97daa85f Mon Sep 17 00:00:00 2001 From: Cassie Recher Date: Wed, 28 Oct 2020 17:44:59 +0000 Subject: [PATCH 011/311] Remove greaterThan constant from HTML renderer. --- claat/render/html.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/claat/render/html.go b/claat/render/html.go index ad3490f19..a8b3726c5 100644 --- a/claat/render/html.go +++ b/claat/render/html.go @@ -29,8 +29,7 @@ import ( // TODO: render HTML using golang/x/net/html or template. var ( - greaterThan = []byte{'>'} - newLine = []byte{'\n'} + newLine = []byte{'\n'} ) // HTML renders nodes as the markup for the target env. @@ -181,7 +180,7 @@ func (hw *htmlWriter) image(n *types.ImageNode) { hw.writeString(` src="`) hw.writeString(n.Src) hw.writeString(`"`) - hw.writeBytes(greaterThan) + hw.writeString(">") } func (hw *htmlWriter) url(n *types.URLNode) { @@ -201,7 +200,7 @@ func (hw *htmlWriter) url(n *types.URLNode) { hw.writeEscape(n.Target) hw.writeString(`"`) } - hw.writeBytes(greaterThan) + hw.writeString(">") hw.write(n.Content.Nodes...) hw.writeString("") } @@ -214,7 +213,7 @@ func (hw *htmlWriter) button(n *types.ButtonNode) { if n.Raised { hw.writeString(" raised") } - hw.writeBytes(greaterThan) + hw.writeString(">") if n.Download { hw.writeString(``) } @@ -229,7 +228,7 @@ func (hw *htmlWriter) code(n *types.CodeNode) { if n.Lang != "" { hw.writeFmt(" language=%q class=%q", n.Lang, n.Lang) } - hw.writeBytes(greaterThan) + hw.writeString(">") } if hw.format == "devsite" { hw.writeString("{% verbatim %}") @@ -299,7 +298,7 @@ func (hw *htmlWriter) itemsList(n *types.ItemsListNode) { hw.writeFmt(` start="%d"`, n.Start) } } - hw.writeBytes(greaterThan) + hw.writeString(">") hw.writeBytes(newLine) for _, i := range n.Items { @@ -310,7 +309,7 @@ func (hw *htmlWriter) itemsList(n *types.ItemsListNode) { hw.writeString("") } func (hw *htmlWriter) grid(n *types.GridNode) { @@ -365,11 +364,11 @@ func (hw *htmlWriter) header(n *types.HeaderNode) { } hw.writeString(` is-upgraded`) - hw.writeBytes(greaterThan) + hw.writeString(">") hw.write(n.Content.Nodes...) hw.writeString("") } func (hw *htmlWriter) youtube(n *types.YouTubeNode) { From 9bd5a7c672243c518eb6ebba7872ada98f7b507d Mon Sep 17 00:00:00 2001 From: Cassie Recher Date: Wed, 28 Oct 2020 17:48:14 +0000 Subject: [PATCH 012/311] Remove newLine constant from HTML renderer. --- claat/render/html.go | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/claat/render/html.go b/claat/render/html.go index a8b3726c5..d96767a9c 100644 --- a/claat/render/html.go +++ b/claat/render/html.go @@ -28,10 +28,6 @@ import ( // TODO: render HTML using golang/x/net/html or template. -var ( - newLine = []byte{'\n'} -) - // HTML renders nodes as the markup for the target env. func HTML(ctx Context, nodes ...types.Node) (htmlTemplate.HTML, error) { var buf bytes.Buffer @@ -83,37 +79,37 @@ func (hw *htmlWriter) write(nodes ...types.Node) error { hw.button(n) case *types.CodeNode: hw.code(n) - hw.writeBytes(newLine) + hw.writeString("\n") case *types.ListNode: hw.list(n) - hw.writeBytes(newLine) + hw.writeString("\n") case *types.ImportNode: if len(n.Content.Nodes) == 0 { break } hw.list(n.Content) - hw.writeBytes(newLine) + hw.writeString("\n") case *types.ItemsListNode: hw.itemsList(n) - hw.writeBytes(newLine) + hw.writeString("\n") case *types.GridNode: hw.grid(n) - hw.writeBytes(newLine) + hw.writeString("\n") case *types.InfoboxNode: hw.infobox(n) - hw.writeBytes(newLine) + hw.writeString("\n") case *types.SurveyNode: hw.survey(n) - hw.writeBytes(newLine) + hw.writeString("\n") case *types.HeaderNode: hw.header(n) - hw.writeBytes(newLine) + hw.writeString("\n") case *types.YouTubeNode: hw.youtube(n) - hw.writeBytes(newLine) + hw.writeString("\n") case *types.IframeNode: hw.iframe(n) - hw.writeBytes(newLine) + hw.writeString("\n") } if hw.err != nil { return hw.err @@ -299,7 +295,7 @@ func (hw *htmlWriter) itemsList(n *types.ItemsListNode) { } } hw.writeString(">") - hw.writeBytes(newLine) + hw.writeString("\n") for _, i := range n.Items { hw.writeString("
  • ") From 67cbfe70d978b6cc05c64aba07f637f7e1f77d19 Mon Sep 17 00:00:00 2001 From: Cassie Recher Date: Wed, 28 Oct 2020 19:00:50 +0000 Subject: [PATCH 013/311] Remove writeBytes from HTML renderer via refactoring. --- claat/render/html.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/claat/render/html.go b/claat/render/html.go index d96767a9c..b5f7e2eec 100644 --- a/claat/render/html.go +++ b/claat/render/html.go @@ -118,21 +118,21 @@ func (hw *htmlWriter) write(nodes ...types.Node) error { return nil } -func (hw *htmlWriter) writeBytes(b []byte) { +// Writes a string to the htmlWriter unless a write error has occurred on this htmlWriter in the past. +// Will set a write error on this htmlWriter if the write fails. +func (hw *htmlWriter) writeString(s string) { if hw.err != nil { return } - _, hw.err = hw.w.Write(b) -} - -func (hw *htmlWriter) writeString(s string) { - hw.writeBytes([]byte(s)) + _, hw.err = hw.w.Write([]byte(s)) } +// Same as writeString, but with fmt.Sprintf arguments/semantics. func (hw *htmlWriter) writeFmt(f string, a ...interface{}) { hw.writeString(fmt.Sprintf(f, a...)) } +// Same as writeString, but performs HTML escaping and double curly bracket escaping. func (hw *htmlWriter) writeEscape(s string) { s = htmlTemplate.HTMLEscapeString(s) hw.writeString(ReplaceDoubleCurlyBracketsWithEntity(s)) From ef66dba1f9eeaf15f0e0daaa4386d40ad6158227 Mon Sep 17 00:00:00 2001 From: Cassie Recher Date: Wed, 28 Oct 2020 19:48:03 +0000 Subject: [PATCH 014/311] Make HTML renderer string code more compact. --- claat/render/html.go | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/claat/render/html.go b/claat/render/html.go index b5f7e2eec..b64a0e85c 100644 --- a/claat/render/html.go +++ b/claat/render/html.go @@ -173,18 +173,13 @@ func (hw *htmlWriter) image(n *types.ImageNode) { if n.Width > 0 { hw.writeFmt(` style="width: %.2fpx"`, n.Width) } - hw.writeString(` src="`) - hw.writeString(n.Src) - hw.writeString(`"`) - hw.writeString(">") + hw.writeFmt(" src=%q>", n.Src) } func (hw *htmlWriter) url(n *types.URLNode) { hw.writeString(" 0 { - hw.writeFmt(` start="%d"`, n.Start) + hw.writeFmt(` start=%q`, strconv.Itoa(n.Start)) } } - hw.writeString(">") - hw.writeString("\n") + hw.writeString(">\n") for _, i := range n.Items { hw.writeString("
  • ") @@ -303,9 +295,7 @@ func (hw *htmlWriter) itemsList(n *types.ItemsListNode) { hw.writeString("
  • \n") } - hw.writeString("") + hw.writeFmt("", tag) } func (hw *htmlWriter) grid(n *types.GridNode) { @@ -331,9 +321,7 @@ func (hw *htmlWriter) infobox(n *types.InfoboxNode) { } func (hw *htmlWriter) survey(n *types.SurveyNode) { - hw.writeString(`\n") + hw.writeString("\n", n.ID) for _, g := range n.Groups { hw.writeString("

    ") hw.writeEscape(g.Name) @@ -359,12 +347,9 @@ func (hw *htmlWriter) header(n *types.HeaderNode) { hw.writeString(` class="faq"`) } - hw.writeString(` is-upgraded`) - hw.writeString(">") + hw.writeString(` is-upgraded>`) hw.write(n.Content.Nodes...) - hw.writeString("") + hw.writeFmt("", tag) } func (hw *htmlWriter) youtube(n *types.YouTubeNode) { @@ -375,6 +360,5 @@ func (hw *htmlWriter) youtube(n *types.YouTubeNode) { } func (hw *htmlWriter) iframe(n *types.IframeNode) { - hw.writeFmt(``, - n.URL) + hw.writeFmt(``, n.URL) } From 42de29b54e27f1fabea13d4b1ccd86b2d7270dc7 Mon Sep 17 00:00:00 2001 From: Cassie Recher Date: Wed, 28 Oct 2020 19:50:20 +0000 Subject: [PATCH 015/311] Fix render/html.go --- claat/render/html.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/claat/render/html.go b/claat/render/html.go index b64a0e85c..6d7cd206d 100644 --- a/claat/render/html.go +++ b/claat/render/html.go @@ -321,7 +321,7 @@ func (hw *htmlWriter) infobox(n *types.InfoboxNode) { } func (hw *htmlWriter) survey(n *types.SurveyNode) { - hw.writeString("\n", n.ID) + hw.writeFmt("\n", n.ID) for _, g := range n.Groups { hw.writeString("

    ") hw.writeEscape(g.Name) From 717c0d817e1958dcbe382f3989aea3a5e5e228c6 Mon Sep 17 00:00:00 2001 From: Cassie Recher Date: Wed, 28 Oct 2020 19:50:32 +0000 Subject: [PATCH 016/311] Fix MD renderer. --- claat/render/md.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/claat/render/md.go b/claat/render/md.go index 7e2085349..13fdf4f31 100644 --- a/claat/render/md.go +++ b/claat/render/md.go @@ -81,9 +81,9 @@ func (mw *mdWriter) space() { func (mw *mdWriter) newBlock() { if !mw.lineStart { - mw.writeBytes(newLine) + mw.writeString("\n") } - mw.writeBytes(newLine) + mw.writeString("\n") } func (mw *mdWriter) matchEnv(v []string) bool { @@ -222,17 +222,17 @@ func (mw *mdWriter) code(n *types.CodeNode) { return } mw.newBlock() - defer mw.writeBytes(newLine) + defer mw.writeString("\n") mw.writeString("```") if n.Term { mw.writeString("console") } else { mw.writeString(n.Lang) } - mw.writeBytes(newLine) + mw.writeString("\n") mw.writeString(n.Value) if !mw.lineStart { - mw.writeBytes(newLine) + mw.writeString("\n") } mw.writeString("```") } @@ -243,7 +243,7 @@ func (mw *mdWriter) list(n *types.ListNode) { } mw.write(n.Nodes...) if !mw.lineStart && !mw.isWritingTableCell { - mw.writeBytes(newLine) + mw.writeString("\n") } } @@ -260,7 +260,7 @@ func (mw *mdWriter) itemsList(n *types.ItemsListNode) { mw.writeString(s) mw.write(item.Nodes...) if !mw.lineStart { - mw.writeBytes(newLine) + mw.writeString("\n") } } mw.isWritingList = false @@ -290,17 +290,17 @@ func (mw *mdWriter) infobox(n *types.InfoboxNode) { func (mw *mdWriter) survey(n *types.SurveyNode) { mw.newBlock() mw.writeString("
    ") - mw.writeBytes(newLine) + mw.writeString("\n") for _, g := range n.Groups { mw.writeString("") mw.writeEscape(g.Name) mw.writeString("") - mw.writeBytes(newLine) + mw.writeString("\n") for _, o := range g.Options { mw.writeString("") - mw.writeBytes(newLine) + mw.writeString("\n") } } mw.writeString("
    ") @@ -312,7 +312,7 @@ func (mw *mdWriter) header(n *types.HeaderNode) { mw.writeString(" ") mw.write(n.Content.Nodes...) if !mw.lineStart { - mw.writeBytes(newLine) + mw.writeString("\n") } } @@ -329,7 +329,7 @@ func (mw *mdWriter) table(n *types.GridNode) { return } - mw.writeBytes(newLine) + mw.writeString("\n") maxcols := maxColsInTable(n) for rowIndex, row := range n.Rows { mw.writeString("|") @@ -358,7 +358,7 @@ func (mw *mdWriter) table(n *types.GridNode) { mw.writeString(" |") } } - mw.writeBytes(newLine) + mw.writeString("\n") // Write header bottom border if rowIndex == 0 { @@ -366,7 +366,7 @@ func (mw *mdWriter) table(n *types.GridNode) { for i := 0; i < maxcols; i++ { mw.writeString(" --- |") } - mw.writeBytes(newLine) + mw.writeString("\n") } mw.isWritingTableCell = false From ec0aff6db32675a5313bbf798a5fa9d0f7e0c33f Mon Sep 17 00:00:00 2001 From: Cassie Recher Date: Wed, 28 Oct 2020 21:25:30 +0000 Subject: [PATCH 017/311] Further refactor code by inlining some escaping. --- claat/render/html.go | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/claat/render/html.go b/claat/render/html.go index 6d7cd206d..adf9e2771 100644 --- a/claat/render/html.go +++ b/claat/render/html.go @@ -132,10 +132,15 @@ func (hw *htmlWriter) writeFmt(f string, a ...interface{}) { hw.writeString(fmt.Sprintf(f, a...)) } +func escape(s string) string { + s = htmlTemplate.HTMLEscapeString(s) + s = ReplaceDoubleCurlyBracketsWithEntity(s) + return s +} + // Same as writeString, but performs HTML escaping and double curly bracket escaping. func (hw *htmlWriter) writeEscape(s string) { - s = htmlTemplate.HTMLEscapeString(s) - hw.writeString(ReplaceDoubleCurlyBracketsWithEntity(s)) + hw.writeString(escape(s)) } func (hw *htmlWriter) text(n *types.TextNode) { @@ -182,14 +187,10 @@ func (hw *htmlWriter) url(n *types.URLNode) { hw.writeFmt(" href=%q", n.URL) } if n.Name != "" { - hw.writeString(` name="`) - hw.writeEscape(n.Name) - hw.writeString(`"`) + hw.writeFmt(" name=%q", escape(n.Name)) } if n.Target != "" { - hw.writeString(` target="`) - hw.writeEscape(n.Target) - hw.writeString(`"`) + hw.writeFmt(" target=%q", escape(n.Target)) } hw.writeString(">") hw.write(n.Content.Nodes...) @@ -313,9 +314,7 @@ func (hw *htmlWriter) grid(n *types.GridNode) { } func (hw *htmlWriter) infobox(n *types.InfoboxNode) { - hw.writeString(`