Allow customizing reading of #+INCLUDE files
It's not always sensible to allow #+INCLUDE of arbitrary files (e.g. user provided content)
This commit is contained in:
parent
2347800922
commit
9de65240a0
2 changed files with 8 additions and 6 deletions
|
@ -27,6 +27,7 @@ type Configuration struct {
|
|||
AutoLink bool // Try to convert text passages that look like hyperlinks into hyperlinks.
|
||||
DefaultSettings map[string]string // Default values for settings that are overriden by setting the same key in BufferSettings.
|
||||
Log *log.Logger // Log is used to print warnings during parsing.
|
||||
ReadFile func(filename string) ([]byte, error) // ReadFile is used to read e.g. #+INCLUDE files.
|
||||
}
|
||||
|
||||
// Document contains the parsing results and a pointer to the Configuration.
|
||||
|
@ -83,6 +84,7 @@ func New() *Configuration {
|
|||
"OPTIONS": "toc:t <:t e:t f:t pri:t todo:t tags:t",
|
||||
},
|
||||
Log: log.New(os.Stderr, "go-org: ", 0),
|
||||
ReadFile: ioutil.ReadFile,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ func (d *Document) newInclude(k Keyword) (int, Node) {
|
|||
path = filepath.Join(filepath.Dir(d.Path), path)
|
||||
}
|
||||
resolve = func() Node {
|
||||
bs, err := ioutil.ReadFile(path)
|
||||
bs, err := d.ReadFile(path)
|
||||
if err != nil {
|
||||
d.Log.Printf("Bad include %#v: %s", k, err)
|
||||
return k
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue