diff --git a/godoc/static/static.go b/godoc/static/static.go index f8c29bcc..c8b53f49 100644 --- a/godoc/static/static.go +++ b/godoc/static/static.go @@ -2073,9 +2073,10 @@ div#playground .output { padding: 0; background: none; border: none; + outline: 0px solid transparent; overflow: auto; } -#content .playground .number { +#content .playground .number, #content .code .number { color: #999; } #content .code, #content .playground, #content .output { diff --git a/godoc/static/style.css b/godoc/static/style.css index 66d233c7..0d45d85b 100644 --- a/godoc/static/style.css +++ b/godoc/static/style.css @@ -548,9 +548,10 @@ div#playground .output { padding: 0; background: none; border: none; + outline: 0px solid transparent; overflow: auto; } -#content .playground .number { +#content .playground .number, #content .code .number { color: #999; } #content .code, #content .playground, #content .output { diff --git a/present/code.go b/present/code.go index 4d82d9ae..abad1429 100644 --- a/present/code.go +++ b/present/code.go @@ -41,9 +41,12 @@ func (c Code) TemplateName() string { return "code" } var ( highlightRE = regexp.MustCompile(`\s+HL([a-zA-Z0-9_]+)?$`) hlCommentRE = regexp.MustCompile(`(.+) // HL(.*)$`) - codeRE = regexp.MustCompile(`\.(code|play)\s+([^\s]+)(\s+)?(.*)?$`) + codeRE = regexp.MustCompile(`\.(code|play)\s+((?:(?:-edit|-numbers)\s+)*)([^\s]+)(?:\s+(.*))?$`) ) +// parseCode parses a code present directive. Its syntax: +// .code [-numbers] [-edit] [address] [highlight] +// The directive may also be ".play" if the snippet is executable. func parseCode(ctx *Context, sourceFile string, sourceLine int, cmd string) (Elem, error) { cmd = strings.TrimSpace(cmd) @@ -58,14 +61,14 @@ func parseCode(ctx *Context, sourceFile string, sourceLine int, cmd string) (Ele // Arguments: // args[0]: whole match // args[1]: .code/.play - // args[2]: file name - // args[3]: space, if any, before optional address + // args[2]: flags ("-edit -numbers") + // args[3]: file name // args[4]: optional address args := codeRE.FindStringSubmatch(cmd) if len(args) != 5 { return nil, fmt.Errorf("%s:%d: syntax error for .code/.play invocation", sourceFile, sourceLine) } - command, file, addr := args[1], args[2], strings.TrimSpace(args[4]) + command, flags, file, addr := args[1], args[2], args[3], strings.TrimSpace(args[4]) play := command == "play" && PlayEnabled // Read in code file and (optionally) match address. @@ -106,7 +109,11 @@ func parseCode(ctx *Context, sourceFile string, sourceLine int, cmd string) (Ele lines[i] = line } - data := &codeTemplateData{Lines: lines} + data := &codeTemplateData{ + Lines: lines, + Edit: strings.Contains(flags, "-edit"), + Numbers: strings.Contains(flags, "-numbers"), + } // Include before and after in a hidden span for playground code. if play { @@ -124,6 +131,7 @@ func parseCode(ctx *Context, sourceFile string, sourceLine int, cmd string) (Ele type codeTemplateData struct { Lines []codeLine Prefix, Suffix []byte + Edit, Numbers bool } var leadingSpaceRE = regexp.MustCompile(`^[ \t]*`) @@ -136,7 +144,8 @@ var codeTemplate = template.Must(template.New("code").Funcs(template.FuncMap{ const codeTemplateHTML = ` {{with .Prefix}}
{{printf "%s" .}}
{{end}} -
{{range .Lines}}{{/*
+{{/*
+	*/}}{{range .Lines}}{{/*
 	*/}}{{if .HL}}{{leadingSpace .L}}{{trimSpace .L}}{{/*
 	*/}}{{else}}{{.L}}{{end}}{{/*
 */}}
diff --git a/present/doc.go b/present/doc.go
index 32be1508..afd50e79 100644
--- a/present/doc.go
+++ b/present/doc.go
@@ -140,6 +140,12 @@ Such highlights are enabled only if the code invocation ends with
 "HL" followed by the word:
 	.code test.go /^type Foo/,/^}/ HLxxx
 
+The .code function may take one or more flags immediately preceding
+the filename. This command shows test.go in an editable text area:
+	.code -edit test.go
+This command shows test.go with line numbers:
+	.code -numbers test.go
+
 play:
 
 The function "play" is the same as "code" but puts a button