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
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"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) {
|
||||
k := parseKeyword(d.tokens[i])
|
||||
switch k.Key {
|
||||
case "SETUP_FILE":
|
||||
return d.loadSetupFile(k)
|
||||
case "INCLUDE":
|
||||
return d.newInclude(k)
|
||||
case "CAPTION", "ATTR_HTML":
|
||||
|
@ -131,3 +135,28 @@ func (d *Document) newInclude(k Keyword) (int, Node) {
|
|||
}
|
||||
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>
|
||||
Still outside the drawer
|
||||
</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]
|
||||
- [X] checked
|
||||
- [ ] unchecked
|
||||
|
@ -18,3 +19,7 @@ Still outside the drawer
|
|||
This is inside the drawer
|
||||
:END:
|
||||
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]
|
||||
- [X] checked
|
||||
- [ ] unchecked
|
||||
|
@ -18,3 +19,7 @@ Still outside the drawer
|
|||
This is inside the drawer
|
||||
:END:
|
||||
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>
|
||||
<div class="highlight">
|
||||
<pre>
|
||||
#+SETUP_FILE: setup_file_org
|
||||
* Simple Headline [1/2]
|
||||
- [X] checked
|
||||
- [ ] unchecked
|
||||
|
@ -63,6 +64,10 @@ Still outside the drawer
|
|||
This is inside the drawer
|
||||
:END:
|
||||
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>
|
||||
</div>
|
||||
</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