From 7a2cd1abb182f462ec953e0f145e86acae4d7be3 Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Mon, 20 Jan 2020 17:51:58 +0100 Subject: [PATCH] Refactor: Return string value from GetOption Turns out org export options can have meaningful values beside true and false - let's make it possible to use them. --- org/document.go | 14 +++++--------- org/html_writer.go | 16 ++++++++-------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/org/document.go b/org/document.go index 3c60e5b..b9b82bf 100644 --- a/org/document.go +++ b/org/document.go @@ -174,7 +174,7 @@ func (d *Document) Get(key string) string { // - pri (export headline priority) // - tags (export headline tags) // see https://orgmode.org/manual/Export-settings.html for more information -func (d *Document) GetOption(key string) bool { +func (d *Document) GetOption(key string) string { get := func(settings map[string]string) string { for _, field := range strings.Fields(settings["OPTIONS"]) { if strings.HasPrefix(field, key+":") { @@ -187,15 +187,11 @@ func (d *Document) GetOption(key string) bool { 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 + if value == "" { + value = "nil" + d.Log.Printf("Missing value for export option %s", key) } + return value } func (d *Document) parseOne(i int, stop stopFn) (consumed int, node Node) { diff --git a/org/html_writer.go b/org/html_writer.go index d630db5..a170184 100644 --- a/org/html_writer.go +++ b/org/html_writer.go @@ -155,7 +155,7 @@ func (w *HTMLWriter) WriteFootnoteDefinition(f FootnoteDefinition) { } func (w *HTMLWriter) WriteFootnotes(d *Document) { - if !w.document.GetOption("f") || len(w.footnotes.list) == 0 { + if w.document.GetOption("f") == "nil" || len(w.footnotes.list) == 0 { return } w.WriteString(`
` + "\n") @@ -183,7 +183,7 @@ func (w *HTMLWriter) WriteFootnotes(d *Document) { } func (w *HTMLWriter) WriteOutline(d *Document) { - if w.document.GetOption("toc") && len(d.Outline.Children) != 0 { + if w.document.GetOption("toc") != "nil" && len(d.Outline.Children) != 0 { w.WriteString("