tour: make space optional after "#appengine:" prefix

This change improves the algorithm that detects the "#appengine:"
blocks to make the space after colon optional rather than mandatory.

That makes it possible to have an empty line with the "#appengine:"
prefix, without requiring a trailing space after the colon. It's
convenient whenever such a block contains multiple paragraphs, e.g.:

	#appengine: * Go offline
	#appengine:
	#appengine: This tour is also available as a stand-alone program
	#appengine: that you can use without access to the internet.
	#appengine:
	#appengine: The stand-alone tour is faster, as it builds and runs
	#appengine: the code samples on your own machine.

People often have editors set to trim trailing whitespace on save,
so it's helpful to improve the algorithm, instead of having significant
trailing whitespace and relying on people to not accidentally remove it.

Now that the trailing whitespace is no longer signifiant, remove it.

Also fix a typo: s/non-blank like/non-blank line/.

Change-Id: I42d41634dd30e307ac98214cb94b1f97a8032f08
Reviewed-on: https://go-review.googlesource.com/c/tour/+/167837
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
Dmitri Shuralyov 2019-03-15 11:28:36 -04:00
Родитель 7de0bd1d74
Коммит db40fe78fe
3 изменённых файлов: 22 добавлений и 18 удалений

Просмотреть файл

@ -36,10 +36,10 @@ func gaeMain() {
}
// gaePrepContent returns a Reader that produces the content from the given
// Reader, but strips the prefix "#appengine: " from each line. It also drops
// any non-blank like that follows a series of 1 or more lines with the prefix.
// Reader, but strips the prefix "#appengine:", optionally followed by a space, from each line.
// It also drops any non-blank line that follows a series of 1 or more lines with the prefix.
func gaePrepContent(in io.Reader) io.Reader {
var prefix = []byte("#appengine: ")
var prefix = []byte("#appengine:")
out, w := io.Pipe()
go func() {
r := bufio.NewReader(in)
@ -52,6 +52,10 @@ func gaePrepContent(in io.Reader) io.Reader {
}
if bytes.HasPrefix(b, prefix) {
b = b[len(prefix):]
if b[0] == ' ' {
// Consume a single space after the prefix.
b = b[1:]
}
drop = true
} else if drop {
if len(b) > 1 {

Просмотреть файл

@ -17,7 +17,7 @@ By convention, the package name is the same as the last element of the import pa
#appengine: *Note:* The environment in which these programs are executed is
#appengine: deterministic, so each time you run the example program
#appengine: `rand.Intn` will return the same number.
#appengine:
#appengine:
#appengine: (To see a different number, seed the number generator; see [[https://golang.org/pkg/math/rand/#Seed][`rand.Seed`]].
#appengine: Time is constant in the playground, so you will need to use something else as the seed.)

Просмотреть файл

@ -70,41 +70,41 @@ The tour is available in other languages:
Click the [[javascript:highlightAndClick(".next-page")]["next"]] button or type `PageDown` to continue.
#appengine: * Go offline
#appengine:
#appengine:
#appengine: This tour is also available as a stand-alone program that you can use
#appengine: without access to the internet.
#appengine:
#appengine:
#appengine: The stand-alone tour is faster, as it builds and runs the code samples
#appengine: on your own machine.
#appengine:
#appengine:
#appengine: To run the tour locally install and run the tour binary:
#appengine:
#appengine:
#appengine: go get golang.org/x/tour
#appengine: tour
#appengine:
#appengine:
#appengine: The tour program will open a web browser displaying
#appengine: your local version of the tour.
#appengine:
#appengine:
#appengine: Or, of course, you can continue to take the tour through this web site.
#appengine: * The Go Playground
#appengine:
#appengine:
#appengine: This tour is built atop the [[https://play.golang.org/][Go Playground]], a
#appengine: web service that runs on [[https://golang.org/][golang.org]]'s servers.
#appengine:
#appengine:
#appengine: The service receives a Go program, compiles, links, and runs the program inside
#appengine: a sandbox, then returns the output.
#appengine:
#appengine:
#appengine: There are limitations to the programs that can be run in the playground:
#appengine:
#appengine:
#appengine: - In the playground the time begins at 2009-11-10 23:00:00 UTC (determining the significance of this date is an exercise for the reader). This makes it easier to cache programs by giving them deterministic output.
#appengine:
#appengine:
#appengine: - There are also limits on execution time and on CPU and memory usage, and the program cannot access external network hosts.
#appengine:
#appengine:
#appengine: The playground uses the latest stable release of Go.
#appengine:
#appengine:
#appengine: Read "[[https://blog.golang.org/playground][Inside the Go Playground]]" to learn more.
#appengine:
#appengine:
#appengine: .play welcome/sandbox.go
* Congratulations