diff --git a/lib/godoc/package.html b/lib/godoc/package.html
index 1df1f9151df..1fe6e7595fd 100644
--- a/lib/godoc/package.html
+++ b/lib/godoc/package.html
@@ -10,7 +10,11 @@
correspond to Go identifiers).
-->
{{with .PDoc}}
- {{if not $.IsMain}}
+ {{if $.IsMain}}
+ {{/* command documentation */}}
+ {{comment_html .Doc}}
+ {{else}}
+ {{/* package documentation */}}
import "{{html .ImportPath}}"
@@ -160,8 +164,6 @@
{{example_html $name $.Examples $.FSet}}
{{end}}
{{end}}
- {{else}} {{/* not a package; is a command */}}
- {{comment_html .Doc}}
{{end}}
{{with $.Notes}}
diff --git a/lib/godoc/package.txt b/lib/godoc/package.txt
index 94239ca1a54..de40a749b6b 100644
--- a/lib/godoc/package.txt
+++ b/lib/godoc/package.txt
@@ -2,14 +2,15 @@
---------------------------------------
-*/}}{{with .PDoc}}{{if not $.IsMain}}PACKAGE
+*/}}{{with .PDoc}}{{if $.IsMain}}COMMAND DOCUMENTATION
+
+{{comment_text .Doc " " "\t"}}
+{{else}}PACKAGE DOCUMENTATION
package {{.Name}}
import "{{.ImportPath}}"
-{{else}}COMMAND DOCUMENTATION
-
-{{end}}{{comment_text .Doc " " "\t"}}
+{{comment_text .Doc " " "\t"}}
{{example_text "" $.Examples $.FSet " "}}{{/*
---------------------------------------
@@ -58,7 +59,7 @@ TYPES
{{end}}{{range .Methods}}{{node .Decl $.FSet}}
{{comment_text .Doc " " "\t"}}
{{$name := printf "%s_%s" $tname .Name}}{{example_text $name $.Examples $.FSet " "}}
-{{end}}{{end}}{{end}}{{/*
+{{end}}{{end}}{{end}}{{end}}{{/*
---------------------------------------