Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(internal/godocfx): Use default html rendering #6802

Merged
merged 2 commits into from Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion internal/godocfx/go.mod
Expand Up @@ -8,7 +8,6 @@ require (
cloud.google.com/go/datastore v1.8.0
cloud.google.com/go/storage v1.27.0
github.com/google/go-cmp v0.5.8
github.com/yuin/goldmark v1.4.12
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f
golang.org/x/tools v0.1.11
gopkg.in/yaml.v2 v2.4.0
Expand Down
2 changes: 0 additions & 2 deletions internal/godocfx/go.sum
Expand Up @@ -160,8 +160,6 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.12 h1:6hffw6vALvEDqJ19dOJvJKOoAOKe4NDaTqvd2sktGN0=
github.com/yuin/goldmark v1.4.12/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M=
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
Expand Down
74 changes: 0 additions & 74 deletions internal/godocfx/goldmark-codeblock/codeblock.go

This file was deleted.

25 changes: 9 additions & 16 deletions internal/godocfx/parse.go
Expand Up @@ -27,6 +27,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"go/doc"
"go/format"
"go/printer"
"go/token"
Expand All @@ -39,12 +40,8 @@ import (
"strings"
"sync"

goldmarkcodeblock "cloud.google.com/go/internal/godocfx/goldmark-codeblock"
"cloud.google.com/go/internal/godocfx/pkgload"
"cloud.google.com/go/third_party/go/doc"
"cloud.google.com/go/third_party/pkgsite"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/renderer/html"
"golang.org/x/tools/go/packages"
)

Expand Down Expand Up @@ -174,7 +171,7 @@ func parse(glob string, workingDir string, optionalExtraFiles []string, filter [
UID: pi.Doc.ImportPath,
Name: pi.Doc.ImportPath,
ID: pi.Doc.Name,
Summary: toHTML(pi.Doc.Doc),
Summary: toHTML(pi.Doc, pi.Doc.Doc),
Langs: onlyGo,
Type: "package",
Examples: processExamples(pi.Doc.Examples, pi.Fset),
Expand Down Expand Up @@ -622,23 +619,19 @@ func buildTOC(mod string, pis []pkgload.Info, extraFiles []extraFile) tableOfCon
return toc
}

func toHTML(s string) string {
func toHTML(p *doc.Package, s string) string {
buf := &bytes.Buffer{}
// First, convert to Markdown.
doc.ToMarkdown(buf, s, nil)

// Then, handle Markdown stuff, like lists and links.
md := goldmark.New(goldmark.WithRendererOptions(html.WithUnsafe()), goldmark.WithExtensions(goldmarkcodeblock.CodeBlock))
mdBuf := &bytes.Buffer{}
if err := md.Convert(buf.Bytes(), mdBuf); err != nil {
panic(err)
}
buf.Write(p.HTML(s))

// Replace * with * to avoid confusing the DocFX Markdown processor,
// which sometimes interprets * as <em>.
result := string(bytes.ReplaceAll(mdBuf.Bytes(), []byte("*"), []byte("&#42;")))
b := bytes.ReplaceAll(buf.Bytes(), []byte("*"), []byte("&#42;"))

return result
// Add prettyprint class to all pre elements.
b = bytes.ReplaceAll(b, []byte("<pre>"), []byte("<pre class=\"prettyprint\">"))

return string(b)
}

func hasPrefix(s string, prefixes []string) bool {
Expand Down
2 changes: 1 addition & 1 deletion internal/godocfx/pkgload/load.go
Expand Up @@ -17,13 +17,13 @@ package pkgload
import (
"fmt"
"go/ast"
"go/doc"
"go/parser"
"go/token"
"sort"
"strconv"
"strings"

"cloud.google.com/go/third_party/go/doc"
"golang.org/x/tools/go/packages"
)

Expand Down