diff --git a/cmd/mungedocs/toc.go b/cmd/mungedocs/toc.go index 9011e117db9..de0bdca6ecb 100644 --- a/cmd/mungedocs/toc.go +++ b/cmd/mungedocs/toc.go @@ -23,10 +23,12 @@ import ( "strings" ) +const tocMungeTag = "GENERATED_TOC" + // inserts/updates a table of contents in markdown file. // // First, builds a ToC. -// Then, finds and , and replaces anything between those with +// Then, finds the magic macro block tags and replaces anything between those with // the ToC, thereby updating any previously inserted ToC. // // TODO(erictune): put this in own package with tests @@ -36,7 +38,7 @@ func updateTOC(filePath string, markdown []byte) ([]byte, error) { return nil, err } lines := splitLines(markdown) - updatedMarkdown, err := updateMacroBlock(lines, "", "", string(toc)) + updatedMarkdown, err := updateMacroBlock(lines, beginMungeTag(tocMungeTag), endMungeTag(tocMungeTag), string(toc)) if err != nil { return nil, err } diff --git a/cmd/mungedocs/toc_test.go b/cmd/mungedocs/toc_test.go index 5175d8089f1..4875d93c049 100644 --- a/cmd/mungedocs/toc_test.go +++ b/cmd/mungedocs/toc_test.go @@ -29,8 +29,10 @@ func Test_buildTOC(t *testing.T) { }{ {"", ""}, {"Lorem ipsum\ndolor sit amet\n", ""}, - {"# Title\nLorem ipsum \n## Section Heading\ndolor sit amet\n", - "- [Title](#title)\n - [Section Heading](#section-heading)\n"}, + { + "# Title\nLorem ipsum \n## Section Heading\ndolor sit amet\n", + "- [Title](#title)\n - [Section Heading](#section-heading)\n", + }, } for _, c := range cases { actual, err := buildTOC([]byte(c.in)) @@ -47,10 +49,14 @@ func Test_updateTOC(t *testing.T) { out string }{ {"", ""}, - {"Lorem ipsum\ndolor sit amet\n", - "Lorem ipsum\ndolor sit amet\n"}, - {"# Title\nLorem ipsum \n**table of contents**\n\nold cruft\n\n## Section Heading\ndolor sit amet\n", - "# Title\nLorem ipsum \n**table of contents**\n\n- [Title](#title)\n - [Section Heading](#section-heading)\n\n\n## Section Heading\ndolor sit amet\n"}, + { + "Lorem ipsum\ndolor sit amet\n", + "Lorem ipsum\ndolor sit amet\n", + }, + { + "# Title\nLorem ipsum \n**table of contents**\n\nold cruft\n\n## Section Heading\ndolor sit amet\n", + "# Title\nLorem ipsum \n**table of contents**\n\n- [Title](#title)\n - [Section Heading](#section-heading)\n\n\n## Section Heading\ndolor sit amet\n", + }, } for _, c := range cases { actual, err := updateTOC("filename.md", []byte(c.in)) diff --git a/cmd/mungedocs/unversioned_warning.go b/cmd/mungedocs/unversioned_warning.go index 8939fce4532..7768fe38a95 100644 --- a/cmd/mungedocs/unversioned_warning.go +++ b/cmd/mungedocs/unversioned_warning.go @@ -16,9 +16,12 @@ limitations under the License. package main -var beginUnversionedWarning = "" -var endUnversionedWarning = "" -var unversionedWarning = ` +const unversionedWarningTag = "UNVERSIONED_WARNING" + +var beginUnversionedWarning = beginMungeTag(unversionedWarningTag) +var endUnversionedWarning = endMungeTag(unversionedWarningTag) + +const unversionedWarning = `