diff --git a/org/document.go b/org/document.go index 7f12479..4b240b4 100644 --- a/org/document.go +++ b/org/document.go @@ -85,6 +85,7 @@ func NewDocument() *Document { DefaultSettings: map[string]string{ "TODO": "TODO | DONE", "EXCLUDE_TAGS": "noexport", + "OPTIONS": "toc:t e:t f:t pri:t todo:t tags:t", }, Log: log.New(os.Stderr, "go-org: ", 0), } @@ -180,6 +181,24 @@ func (d *Document) Get(key string) string { return "" } +// 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(":"):] { + case "t": + return true + case "nil": + return false + default: + d.Log.Printf("Bad value for export option %s (%s)", key, field) + return false + } + } + } + return false +} + func (d *Document) parseOne(i int, stop stopFn) (consumed int, node Node) { switch d.tokens[i].kind { case "unorderedList", "orderedList": diff --git a/org/html_writer.go b/org/html_writer.go index b9fa41c..9cb2014 100644 --- a/org/html_writer.go +++ b/org/html_writer.go @@ -14,9 +14,9 @@ import ( type HTMLWriter struct { stringBuilder + document *Document HighlightCodeBlock func(source, lang string) string htmlEscape bool - excludeTags []string log *log.Logger } @@ -67,7 +67,7 @@ func (w *HTMLWriter) nodesAsString(nodes ...Node) string { } func (w *HTMLWriter) before(d *Document) { - w.excludeTags = strings.Fields(d.Get("EXCLUDE_TAGS")) + w.document = d w.log = d.Log w.writeOutline(d) } @@ -193,7 +193,7 @@ func (w *HTMLWriter) writeFootnoteDefinition(f FootnoteDefinition) { } func (w *HTMLWriter) writeFootnotes(d *Document) { - if len(d.Footnotes.Definitions) == 0 { + if !w.document.GetOption("f") || len(d.Footnotes.Definitions) == 0 { return } w.WriteString(`