diff --git a/pkg/tfgen/docs.go b/pkg/tfgen/docs.go index 320546a859..4a16add5e3 100644 --- a/pkg/tfgen/docs.go +++ b/pkg/tfgen/docs.go @@ -674,7 +674,6 @@ func (p *tfMarkdownParser) parse(tfMarkdown []byte) (entityDocs, error) { goldmark.WithParserOptions(parser.WithASTTransformers( util.Prioritized(exampleTransformer, 2000), )), - goldmark.WithRenderer(parse.RenderMarkdown()), ).Convert(tfMarkdown, &out) if err != nil { return entityDocs{}, err diff --git a/pkg/tfgen/docs_test.go b/pkg/tfgen/docs_test.go index 0b8ab2c003..ce774bcf67 100644 --- a/pkg/tfgen/docs_test.go +++ b/pkg/tfgen/docs_test.go @@ -1315,7 +1315,6 @@ func TestReformatExamples(t *testing.T) { goldmark.WithParserOptions(parser.WithASTTransformers( util.Prioritized(exampleTransformer{}, 2000), )), - goldmark.WithRenderer(parse.RenderMarkdown()), ).Convert([]byte(input), &out) require.NoError(t, err) diff --git a/pkg/tfgen/parse/extension.go b/pkg/tfgen/parse/extension.go index 03813d15de..aa2fa96574 100644 --- a/pkg/tfgen/parse/extension.go +++ b/pkg/tfgen/parse/extension.go @@ -17,6 +17,7 @@ package parse import ( "bytes" "fmt" + "strings" "github.com/olekukonko/tablewriter" "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract" @@ -140,12 +141,15 @@ func (t tableRenderer) RegisterFuncs(r renderer.NodeRendererFuncRegisterer) { }) } -func (t tableRenderer) render(writer util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) { - writer.WriteRune('\n') +func (t tableRenderer) render( + writer util.BufWriter, source []byte, n ast.Node, entering bool, +) (ast.WalkStatus, error) { + _, err := writer.WriteRune('\n') + contract.AssertNoErrorf(err, "impossible") var inHeader bool header := make([]string, 0, len(n.(*extast.Table).Alignments)) var rows [][]string - err := ast.Walk(n, func(n ast.Node, entering bool) (ast.WalkStatus, error) { + err = ast.Walk(n, func(n ast.Node, entering bool) (ast.WalkStatus, error) { switch n := n.(type) { case *extast.Table: return ast.WalkContinue, nil @@ -160,14 +164,22 @@ func (t tableRenderer) render(writer util.BufWriter, source []byte, n ast.Node, case *extast.TableCell: if entering { var cell bytes.Buffer - err := t.r.Render(&cell, source, n) + b := ast.NewTextBlock() + for c := n.FirstChild(); c != nil; c = c.NextSibling() { + b.AppendChild(b, c) + } + + err := t.r.Render(&cell, source, b) if err != nil { return ast.WalkStop, err } + + content := strings.TrimSpace(cell.String()) + if inHeader { - header = append(header, string(n.Text(source))) + header = append(header, content) } else { - rows[len(rows)-1] = append(rows[len(rows)-1], string(n.Text(source))) + rows[len(rows)-1] = append(rows[len(rows)-1], content) } } return ast.WalkSkipChildren, nil diff --git a/pkg/tfgen/parse/extension_test.go b/pkg/tfgen/parse/extension_test.go index 2a0ba86985..270093eeef 100644 --- a/pkg/tfgen/parse/extension_test.go +++ b/pkg/tfgen/parse/extension_test.go @@ -48,6 +48,21 @@ func TestRenderTable(t *testing.T) { |------|------| | r1c1 | r1c2 | | r2c1 | r2c2 | +`), + }, + { + name: "with-in table effects", + input: ` +| t1 | *t2* | +|------|------| +| __r1c1__ | r1c2 | +| r2c1 | r2c2 | +`, + expected: autogold.Expect(` +| t1 | *t2* | +|----------|------| +| **r1c1** | r1c2 | +| r2c1 | r2c2 | `), }, }