| Index: pkg/present/code.go |
| =================================================================== |
| --- a/pkg/present/code.go |
| +++ b/pkg/present/code.go |
| @@ -7,7 +7,6 @@ |
| import ( |
| "fmt" |
| "html/template" |
| - "io/ioutil" |
| "log" |
| "path/filepath" |
| "regexp" |
| @@ -42,7 +41,7 @@ |
| var highlightRE = regexp.MustCompile(`\s+HL([a-zA-Z0-9_]+)?$`) |
| var codeRE = regexp.MustCompile(`\.(code|play)\s+([^\s]+)(\s+)?(.*)?$`) |
| -func parseCode(sourceFile string, sourceLine int, cmd string) (Elem, error) { |
| +func parseCode(ctx *Context, sourceFile string, sourceLine int, cmd string) (Elem, error) { |
| cmd = strings.TrimSpace(cmd) |
| // Pull off the HL, if any, from the end of the input line. |
| @@ -68,7 +67,7 @@ |
| // Read in code file and (optionally) match address. |
| filename := filepath.Join(filepath.Dir(sourceFile), file) |
| - textBytes, err := ioutil.ReadFile(filename) |
| + textBytes, err := ctx.ReadFile(filename) |
| if err != nil { |
| return nil, fmt.Errorf("%s:%d: %v", sourceFile, sourceLine, err) |
| } |
| @@ -168,8 +167,8 @@ |
| } |
| // oneLine returns the single line generated by a two-argument code invocation. |
| -func oneLine(file, text string, arg interface{}) (line, before, after string, err error) { |
| - contentBytes, err := ioutil.ReadFile(file) |
| +func oneLine(ctx *Context, file, text string, arg interface{}) (line, before, after string, err error) { |
| + contentBytes, err := ctx.ReadFile(file) |
| if err != nil { |
| return "", "", "", err |
| } |
| @@ -192,8 +191,8 @@ |
| } |
| // multipleLines returns the text generated by a three-argument code invocation. |
| -func multipleLines(file string, arg1, arg2 interface{}) (line, before, after string, err error) { |
| - contentBytes, err := ioutil.ReadFile(file) |
| +func multipleLines(ctx *Context, file string, arg1, arg2 interface{}) (line, before, after string, err error) { |
| + contentBytes, err := ctx.ReadFile(file) |
| lines := strings.SplitAfter(string(contentBytes), "\n") |
| if err != nil { |
| return "", "", "", err |