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,8 +36,8 @@ 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:")
out, w := io.Pipe()
@ -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 {