mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
Use a common set of tag prefixes for munges
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.
This commit is contained in:
parent
8fceb754d8
commit
ad8f8731b6
@ -23,10 +23,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const tocMungeTag = "GENERATED_TOC"
|
||||||
|
|
||||||
// inserts/updates a table of contents in markdown file.
|
// inserts/updates a table of contents in markdown file.
|
||||||
//
|
//
|
||||||
// First, builds a ToC.
|
// 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.
|
// the ToC, thereby updating any previously inserted ToC.
|
||||||
//
|
//
|
||||||
// TODO(erictune): put this in own package with tests
|
// TODO(erictune): put this in own package with tests
|
||||||
@ -36,7 +38,7 @@ func updateTOC(filePath string, markdown []byte) ([]byte, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
lines := splitLines(markdown)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,10 @@ func Test_buildTOC(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{"", ""},
|
{"", ""},
|
||||||
{"Lorem ipsum\ndolor sit amet\n", ""},
|
{"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 {
|
for _, c := range cases {
|
||||||
actual, err := buildTOC([]byte(c.in))
|
actual, err := buildTOC([]byte(c.in))
|
||||||
@ -47,10 +49,14 @@ func Test_updateTOC(t *testing.T) {
|
|||||||
out string
|
out string
|
||||||
}{
|
}{
|
||||||
{"", ""},
|
{"", ""},
|
||||||
{"Lorem ipsum\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 GENERATED TOC -->\nold cruft\n<!-- END GENERATED TOC -->\n## Section Heading\ndolor sit amet\n",
|
"Lorem ipsum\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"},
|
},
|
||||||
|
{
|
||||||
|
"# 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 {
|
for _, c := range cases {
|
||||||
actual, err := updateTOC("filename.md", []byte(c.in))
|
actual, err := updateTOC("filename.md", []byte(c.in))
|
||||||
|
@ -16,9 +16,12 @@ limitations under the License.
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
var beginUnversionedWarning = "<!-- BEGIN UNVERSIONED_WARNING -->"
|
const unversionedWarningTag = "UNVERSIONED_WARNING"
|
||||||
var endUnversionedWarning = "<!-- END UNVERSIONED_WARNING -->"
|
|
||||||
var unversionedWarning = `
|
var beginUnversionedWarning = beginMungeTag(unversionedWarningTag)
|
||||||
|
var endUnversionedWarning = endMungeTag(unversionedWarningTag)
|
||||||
|
|
||||||
|
const unversionedWarning = `
|
||||||
<!-- BEGIN STRIP_FOR_RELEASE -->
|
<!-- BEGIN STRIP_FOR_RELEASE -->
|
||||||
|
|
||||||
<h1>*** PLEASE NOTE: This document applies to the HEAD of the source
|
<h1>*** PLEASE NOTE: This document applies to the HEAD of the source
|
||||||
|
@ -98,3 +98,15 @@ func hasMacroBlock(lines []string, begin string, end string) bool {
|
|||||||
}
|
}
|
||||||
return false
|
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)
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Networking in Kubernetes
|
# Networking in Kubernetes
|
||||||
**Table of Contents**
|
**Table of Contents**
|
||||||
<!-- BEGIN GENERATED TOC -->
|
<!-- BEGIN MUNGE: GENERATED_TOC -->
|
||||||
- [Networking in Kubernetes](#networking-in-kubernetes)
|
- [Networking in Kubernetes](#networking-in-kubernetes)
|
||||||
- [Summary](#summary)
|
- [Summary](#summary)
|
||||||
- [Docker model](#docker-model)
|
- [Docker model](#docker-model)
|
||||||
@ -14,7 +14,7 @@
|
|||||||
- [Calico](#calico)
|
- [Calico](#calico)
|
||||||
- [Other reading](#other-reading)
|
- [Other reading](#other-reading)
|
||||||
|
|
||||||
<!-- END GENERATED TOC -->
|
<!-- END MUNGE: GENERATED_TOC -->
|
||||||
|
|
||||||
Kubernetes approaches networking somewhat differently than Docker does by
|
Kubernetes approaches networking somewhat differently than Docker does by
|
||||||
default. There are 4 distinct networking problems to solve:
|
default. There are 4 distinct networking problems to solve:
|
||||||
|
Loading…
Reference in New Issue
Block a user