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:
Niklas Fasching 2019-01-01 22:06:08 +01:00
parent f62a00863f
commit c98cdea4f0
4 changed files with 35 additions and 26 deletions

View file

@ -146,20 +146,27 @@ func (d *Document) Get(key string) string {
// see https://orgmode.org/manual/Export-settings.html
func (d *Document) GetOption(key string) bool {
for _, field := range strings.Fields(d.Get("OPTIONS")) {
if strings.HasPrefix(field, key) {
switch field[len(key)+len(":"):] {
get := func(settings map[string]string) string {
for _, field := range strings.Fields(settings["OPTIONS"]) {
if strings.HasPrefix(field, key+":") {
return field[len(key)+1:]
}
}
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, field)
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) {

View file

@ -1,13 +1,15 @@
<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>&#xa0;&#xa0;&#xa0;<span class="tags"><span>tag1</span>&#xa0;<span>tag2</span></span>
</h1>
<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.
By default those toggles are enabled. This files starts with <code class="verbatim">#+OPTIONS:</code> (empty options) and thus
disables all settings.
<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 (most of?) those toggles are enabled. This file starts with <code class="verbatim">#+OPTIONS: toc:nil f:nil e:nil</code> and thus
disables the table of contents, footnotes &amp; entities.
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&#39;t be a table of contents at the top.
Also, the above headline will be exported without priority, todo status &amp; tags.
As buffer options are merged with the defaults, the above headline will be exported <strong>with</strong> priority, todo status &amp; tags.
</p>
<table>
<thead>

View file

@ -1,12 +1,12 @@
#+OPTIONS:
#+OPTIONS: toc:nil f:nil e:nil
* 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.
By default those toggles are enabled. This files starts with =#+OPTIONS:= (empty options) and thus
disables all settings.
=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 (most of?) those toggles are enabled. This file starts with =#+OPTIONS: toc:nil f:nil e:nil= and thus
disables the table of contents, footnotes & entities.
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.
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 |

View file

@ -1,12 +1,12 @@
#+OPTIONS:
#+OPTIONS: toc:nil f:nil e:nil
* 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.
By default those toggles are enabled. This files starts with =#+OPTIONS:= (empty options) and thus
disables all settings.
=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 (most of?) those toggles are enabled. This file starts with =#+OPTIONS: toc:nil f:nil e:nil= and thus
disables the table of contents, footnotes & entities.
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.
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 |