internal/web: stop double-escaping of code in non-playground examples

4c9e549253 introduced an issue causing non-playground
code examples to be double-escaped, causing HTML escape sequences and elements
to appear in the code, such as the examples in crypto/rsa, as reported in golang/go#46839.
This change treats the code as `template.HTML` rather than `string` after running
through `(*Page).Node` (which formats the code as HTML) and doing some basic transformations,
preventing this double-escaping from occurring.

Fixes golang/go#46839
This commit is contained in:
Carson Hoffman 2021-07-05 11:56:16 -04:00
Родитель d6de7f00de
Коммит e5adf7c7f5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 05B660CB452C657F
1 изменённых файлов: 3 добавлений и 2 удалений

Просмотреть файл

@ -74,9 +74,10 @@ func (p *Page) Example(funcName string) template.HTML {
newPage := *p
newPage.Data = struct {
Name, Doc, Code, Play, Output string
Name, Doc, Play, Output string
Code template.HTML
}{
eg.Name, eg.Doc, code, play, out,
eg.Name, eg.Doc, play, out, template.HTML(code),
}
err := t.Execute(&buf, &newPage)
if err != nil {