Skip to content

Commit

Permalink
Use a common set of tag prefixes for munges
Browse files Browse the repository at this point in the history
All munges now start with `<!-- BEGIN MUNGE:` and end with `<!-- END MUNGE:`.
This lets me (in a followup) filter them better to normalize contents during
verification of generated docs.
  • Loading branch information
thockin committed Jul 13, 2015
1 parent 8fceb75 commit ad8f873
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
6 changes: 4 additions & 2 deletions cmd/mungedocs/toc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <!-- BEGIN GENERATED TOC --> and <!-- END GENERATED TOC -->, 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
Expand All @@ -36,7 +38,7 @@ func updateTOC(filePath string, markdown []byte) ([]byte, error) {
return nil, err
}
lines := splitLines(markdown)
updatedMarkdown, err := updateMacroBlock(lines, "<!-- BEGIN GENERATED TOC -->", "<!-- END GENERATED TOC -->", string(toc))
updatedMarkdown, err := updateMacroBlock(lines, beginMungeTag(tocMungeTag), endMungeTag(tocMungeTag), string(toc))
if err != nil {
return nil, err
}
Expand Down
18 changes: 12 additions & 6 deletions cmd/mungedocs/toc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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<!-- BEGIN GENERATED TOC -->\nold cruft\n<!-- END GENERATED TOC -->\n## Section Heading\ndolor sit amet\n",
"# Title\nLorem ipsum \n**table of contents**\n<!-- BEGIN GENERATED TOC -->\n- [Title](#title)\n - [Section Heading](#section-heading)\n\n<!-- END GENERATED TOC -->\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<!-- BEGIN MUNGE: GENERATED_TOC -->\nold cruft\n<!-- END MUNGE: GENERATED_TOC -->\n## Section Heading\ndolor sit amet\n",
"# Title\nLorem ipsum \n**table of contents**\n<!-- BEGIN MUNGE: GENERATED_TOC -->\n- [Title](#title)\n - [Section Heading](#section-heading)\n\n<!-- END MUNGE: GENERATED_TOC -->\n## Section Heading\ndolor sit amet\n",
},
}
for _, c := range cases {
actual, err := updateTOC("filename.md", []byte(c.in))
Expand Down
9 changes: 6 additions & 3 deletions cmd/mungedocs/unversioned_warning.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ limitations under the License.

package main

var beginUnversionedWarning = "<!-- BEGIN UNVERSIONED_WARNING -->"
var endUnversionedWarning = "<!-- END UNVERSIONED_WARNING -->"
var unversionedWarning = `
const unversionedWarningTag = "UNVERSIONED_WARNING"

var beginUnversionedWarning = beginMungeTag(unversionedWarningTag)
var endUnversionedWarning = endMungeTag(unversionedWarningTag)

const unversionedWarning = `
<!-- BEGIN STRIP_FOR_RELEASE -->
<h1>*** PLEASE NOTE: This document applies to the HEAD of the source
Expand Down
12 changes: 12 additions & 0 deletions cmd/mungedocs/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,15 @@ func hasMacroBlock(lines []string, begin string, end string) bool {
}
return false
}

// Returns the canonical begin-tag for a given description. This does not
// include the trailing newline.
func beginMungeTag(desc string) string {
return fmt.Sprintf("<!-- BEGIN MUNGE: %s -->", desc)
}

// Returns the canonical end-tag for a given description. This does not
// include the trailing newline.
func endMungeTag(desc string) string {
return fmt.Sprintf("<!-- END MUNGE: %s -->", desc)
}
4 changes: 2 additions & 2 deletions docs/networking.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Networking in Kubernetes
**Table of Contents**
<!-- BEGIN GENERATED TOC -->
<!-- BEGIN MUNGE: GENERATED_TOC -->
- [Networking in Kubernetes](#networking-in-kubernetes)
- [Summary](#summary)
- [Docker model](#docker-model)
Expand All @@ -14,7 +14,7 @@
- [Calico](#calico)
- [Other reading](#other-reading)

<!-- END GENERATED TOC -->
<!-- END MUNGE: GENERATED_TOC -->

Kubernetes approaches networking somewhat differently than Docker does by
default. There are 4 distinct networking problems to solve:
Expand Down

0 comments on commit ad8f873

Please sign in to comment.