diff --git a/Makefile b/Makefile index 58aea64..9def1cb 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,9 @@ case=example render: go run main.go org/testdata/$(case).org html | html2text +.PHONY: generate +generate: generate-gh-pages generate-html-fixtures + .PHONY: generate-gh-pages generate-gh-pages: build ./etc/generate-gh-pages diff --git a/README.org b/README.org index d03d3ec..4d9fa18 100644 --- a/README.org +++ b/README.org @@ -4,13 +4,9 @@ A basic org-mode parser in go - have a org-mode AST to play around with building an org-mode language server - hopefully add reasonable org-mode support to hugo - sadly [[https://github.com/chaseadamsio/goorgeous][goorgeous]] is broken & abandoned * next -- handle #+RESULTS: raw and stuff +- lists with checkboxes +- property drawers - support more keywords: https://orgmode.org/manual/In_002dbuffer-settings.html - - #+LINK - - #+INCLUDE -*** TODO [[https://github.com/chaseadamsio/goorgeous/issues/10][#10]]: Support noexport -*** TODO [[https://github.com/chaseadamsio/goorgeous/issues/31][#31]]: Support #+INCLUDE -- see https://orgmode.org/manual/Include-files.html * resources - syntax - https://orgmode.org/worg/dev/org-syntax.html diff --git a/main.go b/main.go index f07cc32..e2b1edf 100644 --- a/main.go +++ b/main.go @@ -21,20 +21,22 @@ func main() { log.Println("USAGE: org FILE OUTPUT_FORMAT") log.Fatal("supported output formats: org, html, html-chroma") } - bs, err := ioutil.ReadFile(os.Args[1]) + path := os.Args[1] + bs, err := ioutil.ReadFile(path) if err != nil { log.Fatal(err) } - r, out, err := bytes.NewReader(bs), "", nil + out, err := "", nil + d := org.NewDocument().SetPath(path).Parse(bytes.NewReader(bs)) switch strings.ToLower(os.Args[2]) { case "org": - out, err = org.NewDocument().Parse(r).Write(org.NewOrgWriter()) + out, err = d.Write(org.NewOrgWriter()) case "html": - out, err = org.NewDocument().Parse(r).Write(org.NewHTMLWriter()) + out, err = d.Write(org.NewHTMLWriter()) case "html-chroma": writer := org.NewHTMLWriter() writer.HighlightCodeBlock = highlightCodeBlock - out, err = org.NewDocument().Parse(r).Write(writer) + out, err = d.Write(writer) default: log.Fatal("Unsupported output format") } diff --git a/org/document.go b/org/document.go index 9791de0..6a62d79 100644 --- a/org/document.go +++ b/org/document.go @@ -111,6 +111,11 @@ func (d *Document) Parse(input io.Reader) *Document { return d } +func (d *Document) SetPath(path string) *Document { + d.Path = path + return d +} + func (d *Document) FrontMatter(input io.Reader, f func(string, string) interface{}) (_ map[string]interface{}, err error) { defer func() { d.tokens = nil diff --git a/org/html.go b/org/html.go index 30d6570..d42d94f 100644 --- a/org/html.go +++ b/org/html.go @@ -11,7 +11,6 @@ import ( type HTMLWriter struct { stringBuilder - document *Document HighlightCodeBlock func(source, lang string) string } @@ -65,6 +64,8 @@ func (w *HTMLWriter) writeNodes(ns ...Node) { switch n := n.(type) { case Keyword: w.writeKeyword(n) + case Include: + w.writeInclude(n) case Comment: continue case NodeWithMeta: @@ -144,6 +145,10 @@ func (w *HTMLWriter) writeKeyword(k Keyword) { } } +func (w *HTMLWriter) writeInclude(i Include) { + w.writeNodes(i.Resolve()) +} + func (w *HTMLWriter) writeFootnoteDefinition(f FootnoteDefinition) { n := f.Name w.WriteString(`
-this one is cheating a little as tags are ALWAYS printed right aligned to a given column number… -
diff --git a/org/testdata/headlines.org b/org/testdata/headlines.org index f94fca0..30781d8 100644 --- a/org/testdata/headlines.org +++ b/org/testdata/headlines.org @@ -2,4 +2,4 @@ * TODO [#B] Headline with todo status & priority * DONE Headline with TODO status * [#A] Headline with tags & priority :foo:bar: -this one is cheating a little as tags are ALWAYS printed right aligned to a given column number... + diff --git a/org/testdata/misc.html b/org/testdata/misc.html index cabceb8..8ef9cf7 100644 --- a/org/testdata/misc.html +++ b/org/testdata/misc.html @@ -15,6 +15,74 @@ or even a totally custom kind of block crazy ain't it?+Note that only src/example/export block inclusion is supported for now. +There's quite a lot more to include (see the org manual for include files) but I +don't have a use case for this yet and stuff like namespacing footnotes of included files +adds quite a bit of complexity. +
++for now files can be included as: +
++src block +
+
+* Simple Headline
+* TODO [#B] Headline with todo status & priority
+* DONE Headline with TODO status
+* [#A] Headline with tags & priority :foo:bar:
+
+
+
++export block +
++Paragraphs are the default element. +
++Empty lines and other elements end paragraphs - but paragraphs +can +obviously +span +multiple +lines. +
++Paragraphs can contain inline markup like emphasis strong and links example.com and stuff. +
+ ++example block +
++language: go +script: + - make test + - make generate-gh-pages +deploy: + provider: pages + github-token: $GITHUB_TOKEN # From travis-ci.org repository settings + local-dir: gh-pages + target-branch: gh-pages + skip-cleanup: true + verbose: true + on: + branch: master + ++