Improve document.GetOption: Merge default and buffer local options
Unlike the other BufferSettings, #+OPTIONS: specifies multiple options and we cannot just look it up in either BufferSettings or DefaultSettings - both have to be checked
This commit is contained in:
parent
f62a00863f
commit
c98cdea4f0
4 changed files with 35 additions and 26 deletions
|
@ -146,20 +146,27 @@ func (d *Document) Get(key string) string {
|
||||||
|
|
||||||
// see https://orgmode.org/manual/Export-settings.html
|
// see https://orgmode.org/manual/Export-settings.html
|
||||||
func (d *Document) GetOption(key string) bool {
|
func (d *Document) GetOption(key string) bool {
|
||||||
for _, field := range strings.Fields(d.Get("OPTIONS")) {
|
get := func(settings map[string]string) string {
|
||||||
if strings.HasPrefix(field, key) {
|
for _, field := range strings.Fields(settings["OPTIONS"]) {
|
||||||
switch field[len(key)+len(":"):] {
|
if strings.HasPrefix(field, key+":") {
|
||||||
case "t":
|
return field[len(key)+1:]
|
||||||
return true
|
|
||||||
case "nil":
|
|
||||||
return false
|
|
||||||
default:
|
|
||||||
d.Log.Printf("Bad value for export option %s (%s)", key, field)
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
value := get(d.BufferSettings)
|
||||||
|
if value == "" {
|
||||||
|
value = get(d.DefaultSettings)
|
||||||
|
}
|
||||||
|
switch value {
|
||||||
|
case "t":
|
||||||
|
return true
|
||||||
|
case "nil":
|
||||||
|
return false
|
||||||
|
default:
|
||||||
|
d.Log.Printf("Bad value for export option %s (%s)", key, value)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Document) parseOne(i int, stop stopFn) (consumed int, node Node) {
|
func (d *Document) parseOne(i int, stop stopFn) (consumed int, node Node) {
|
||||||
|
|
12
org/testdata/options.html
vendored
12
org/testdata/options.html
vendored
|
@ -1,13 +1,15 @@
|
||||||
<h1 id="headline-1">
|
<h1 id="headline-1">
|
||||||
<code class="verbatim">#+OPTIONS:</code> toggles supported by <code class="verbatim">go-org</code>
|
<span class="todo">DONE</span>
|
||||||
|
<span class="priority">[A]</span>
|
||||||
|
<code class="verbatim">#+OPTIONS:</code> toggles supported by <code class="verbatim">go-org</code>   <span class="tags"><span>tag1</span> <span>tag2</span></span>
|
||||||
</h1>
|
</h1>
|
||||||
<p>
|
<p>
|
||||||
<code class="verbatim">go-org</code> supports multiple export toggles as described in the <a href="https://orgmode.org/manual/Export-settings.html">export settings</a> Org mode manual.
|
<code class="verbatim">go-org</code> supports multiple export toggles as described in the <a href="https://orgmode.org/manual/Export-settings.html">export settings</a> section of the Org mode manual.
|
||||||
By default those toggles are enabled. This files starts with <code class="verbatim">#+OPTIONS:</code> (empty options) and thus
|
By default (most of?) those toggles are enabled. This file starts with <code class="verbatim">#+OPTIONS: toc:nil f:nil e:nil</code> and thus
|
||||||
disables all settings.
|
disables the table of contents, footnotes & entities.
|
||||||
That means, entities like <code class="verbatim">---</code> --- (mdash) will be left untouched, footnotes like <code class="verbatim">[fn:1]</code> will
|
That means, entities like <code class="verbatim">---</code> --- (mdash) will be left untouched, footnotes like <code class="verbatim">[fn:1]</code> will
|
||||||
not be exported and there won't be a table of contents at the top.
|
not be exported and there won't be a table of contents at the top.
|
||||||
Also, the above headline will be exported without priority, todo status & tags.
|
As buffer options are merged with the defaults, the above headline will be exported <strong>with</strong> priority, todo status & tags.
|
||||||
</p>
|
</p>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
|
|
10
org/testdata/options.org
vendored
10
org/testdata/options.org
vendored
|
@ -1,12 +1,12 @@
|
||||||
#+OPTIONS:
|
#+OPTIONS: toc:nil f:nil e:nil
|
||||||
|
|
||||||
* DONE [#A] =#+OPTIONS:= toggles supported by =go-org= :tag1:tag2:
|
* DONE [#A] =#+OPTIONS:= toggles supported by =go-org= :tag1:tag2:
|
||||||
=go-org= supports multiple export toggles as described in the [[https://orgmode.org/manual/Export-settings.html][export settings]] Org mode manual.
|
=go-org= supports multiple export toggles as described in the [[https://orgmode.org/manual/Export-settings.html][export settings]] section of the Org mode manual.
|
||||||
By default those toggles are enabled. This files starts with =#+OPTIONS:= (empty options) and thus
|
By default (most of?) those toggles are enabled. This file starts with =#+OPTIONS: toc:nil f:nil e:nil= and thus
|
||||||
disables all settings.
|
disables the table of contents, footnotes & entities.
|
||||||
That means, entities like =---= --- (mdash) will be left untouched, footnotes like =[fn:1]= [fn:1] will
|
That means, entities like =---= --- (mdash) will be left untouched, footnotes like =[fn:1]= [fn:1] will
|
||||||
not be exported and there won't be a table of contents at the top.
|
not be exported and there won't be a table of contents at the top.
|
||||||
Also, the above headline will be exported without priority, todo status & tags.
|
As buffer options are merged with the defaults, the above headline will be exported *with* priority, todo status & tags.
|
||||||
|
|
||||||
|
|
||||||
| key | description |
|
| key | description |
|
||||||
|
|
10
org/testdata/options.pretty_org
vendored
10
org/testdata/options.pretty_org
vendored
|
@ -1,12 +1,12 @@
|
||||||
#+OPTIONS:
|
#+OPTIONS: toc:nil f:nil e:nil
|
||||||
|
|
||||||
* DONE [#A] =#+OPTIONS:= toggles supported by =go-org= :tag1:tag2:
|
* DONE [#A] =#+OPTIONS:= toggles supported by =go-org= :tag1:tag2:
|
||||||
=go-org= supports multiple export toggles as described in the [[https://orgmode.org/manual/Export-settings.html][export settings]] Org mode manual.
|
=go-org= supports multiple export toggles as described in the [[https://orgmode.org/manual/Export-settings.html][export settings]] section of the Org mode manual.
|
||||||
By default those toggles are enabled. This files starts with =#+OPTIONS:= (empty options) and thus
|
By default (most of?) those toggles are enabled. This file starts with =#+OPTIONS: toc:nil f:nil e:nil= and thus
|
||||||
disables all settings.
|
disables the table of contents, footnotes & entities.
|
||||||
That means, entities like =---= --- (mdash) will be left untouched, footnotes like =[fn:1]= [fn:1] will
|
That means, entities like =---= --- (mdash) will be left untouched, footnotes like =[fn:1]= [fn:1] will
|
||||||
not be exported and there won't be a table of contents at the top.
|
not be exported and there won't be a table of contents at the top.
|
||||||
Also, the above headline will be exported without priority, todo status & tags.
|
As buffer options are merged with the defaults, the above headline will be exported *with* priority, todo status & tags.
|
||||||
|
|
||||||
|
|
||||||
| key | description |
|
| key | description |
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue