Add support for SETUP_FILE
This commit is contained in:
parent
3ccbbc46ff
commit
c23f8cc281
6 changed files with 57 additions and 0 deletions
|
@ -1,8 +1,10 @@
|
||||||
package org
|
package org
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -52,6 +54,8 @@ func (d *Document) parseComment(i int, stop stopFn) (int, Node) {
|
||||||
func (d *Document) parseKeyword(i int, stop stopFn) (int, Node) {
|
func (d *Document) parseKeyword(i int, stop stopFn) (int, Node) {
|
||||||
k := parseKeyword(d.tokens[i])
|
k := parseKeyword(d.tokens[i])
|
||||||
switch k.Key {
|
switch k.Key {
|
||||||
|
case "SETUP_FILE":
|
||||||
|
return d.loadSetupFile(k)
|
||||||
case "INCLUDE":
|
case "INCLUDE":
|
||||||
return d.newInclude(k)
|
return d.newInclude(k)
|
||||||
case "CAPTION", "ATTR_HTML":
|
case "CAPTION", "ATTR_HTML":
|
||||||
|
@ -131,3 +135,28 @@ func (d *Document) newInclude(k Keyword) (int, Node) {
|
||||||
}
|
}
|
||||||
return 1, Include{k, resolve}
|
return 1, Include{k, resolve}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Document) loadSetupFile(k Keyword) (int, Node) {
|
||||||
|
path := k.Value
|
||||||
|
if !filepath.IsAbs(path) {
|
||||||
|
path = filepath.Join(filepath.Dir(d.Path), path)
|
||||||
|
}
|
||||||
|
bs, err := ioutil.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
if d.Debug {
|
||||||
|
log.Printf("Bad setup file: %#v: %s", k, err)
|
||||||
|
}
|
||||||
|
return 1, k
|
||||||
|
}
|
||||||
|
setupDocument := NewDocument().Parse(bytes.NewReader(bs))
|
||||||
|
if err := setupDocument.Error; err != nil {
|
||||||
|
if d.Debug {
|
||||||
|
log.Printf("Bad setup file: %#v: %s", k, err)
|
||||||
|
}
|
||||||
|
return 1, k
|
||||||
|
}
|
||||||
|
for k, v := range setupDocument.BufferSettings {
|
||||||
|
d.BufferSettings[k] = v
|
||||||
|
}
|
||||||
|
return 1, k
|
||||||
|
}
|
||||||
|
|
12
org/testdata/headlines.html
vendored
12
org/testdata/headlines.html
vendored
|
@ -45,3 +45,15 @@ This is inside the drawer
|
||||||
<p>
|
<p>
|
||||||
Still outside the drawer
|
Still outside the drawer
|
||||||
</p>
|
</p>
|
||||||
|
<h1>
|
||||||
|
<span class="todo">CUSTOM</span>
|
||||||
|
headline with custom status
|
||||||
|
</h1>
|
||||||
|
<p>
|
||||||
|
it's possible to use <code class="verbatim">#+SETUP_FILE</code> - in this case the setup file contains the following
|
||||||
|
</p>
|
||||||
|
<div class="highlight">
|
||||||
|
<pre>
|
||||||
|
#+TODO: TODO DONE CUSTOM
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
5
org/testdata/headlines.org
vendored
5
org/testdata/headlines.org
vendored
|
@ -1,3 +1,4 @@
|
||||||
|
#+SETUP_FILE: setup_file_org
|
||||||
* Simple Headline [1/2]
|
* Simple Headline [1/2]
|
||||||
- [X] checked
|
- [X] checked
|
||||||
- [ ] unchecked
|
- [ ] unchecked
|
||||||
|
@ -18,3 +19,7 @@ Still outside the drawer
|
||||||
This is inside the drawer
|
This is inside the drawer
|
||||||
:END:
|
:END:
|
||||||
Still outside the drawer
|
Still outside the drawer
|
||||||
|
* CUSTOM headline with custom status
|
||||||
|
it's possible to use =#+SETUP_FILE= - in this case the setup file contains the following
|
||||||
|
|
||||||
|
#+INCLUDE: "setup_file_org" src org
|
||||||
|
|
5
org/testdata/headlines.pretty_org
vendored
5
org/testdata/headlines.pretty_org
vendored
|
@ -1,3 +1,4 @@
|
||||||
|
#+SETUP_FILE: setup_file_org
|
||||||
* Simple Headline [1/2]
|
* Simple Headline [1/2]
|
||||||
- [X] checked
|
- [X] checked
|
||||||
- [ ] unchecked
|
- [ ] unchecked
|
||||||
|
@ -18,3 +19,7 @@ Still outside the drawer
|
||||||
This is inside the drawer
|
This is inside the drawer
|
||||||
:END:
|
:END:
|
||||||
Still outside the drawer
|
Still outside the drawer
|
||||||
|
* CUSTOM headline with custom status
|
||||||
|
it's possible to use =#+SETUP_FILE= - in this case the setup file contains the following
|
||||||
|
|
||||||
|
#+INCLUDE: "setup_file_org" src org
|
||||||
|
|
5
org/testdata/misc.html
vendored
5
org/testdata/misc.html
vendored
|
@ -43,6 +43,7 @@ src block
|
||||||
</p>
|
</p>
|
||||||
<div class="highlight">
|
<div class="highlight">
|
||||||
<pre>
|
<pre>
|
||||||
|
#+SETUP_FILE: setup_file_org
|
||||||
* Simple Headline [1/2]
|
* Simple Headline [1/2]
|
||||||
- [X] checked
|
- [X] checked
|
||||||
- [ ] unchecked
|
- [ ] unchecked
|
||||||
|
@ -63,6 +64,10 @@ Still outside the drawer
|
||||||
This is inside the drawer
|
This is inside the drawer
|
||||||
:END:
|
:END:
|
||||||
Still outside the drawer
|
Still outside the drawer
|
||||||
|
* CUSTOM headline with custom status
|
||||||
|
it's possible to use =#+SETUP_FILE= - in this case the setup file contains the following
|
||||||
|
|
||||||
|
#+INCLUDE: "setup_file_org" src org
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|
1
org/testdata/setup_file_org
vendored
Normal file
1
org/testdata/setup_file_org
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
#+TODO: TODO DONE CUSTOM
|
Loading…
Add table
Add a link
Reference in a new issue