diff options
author | Chase Adams <[email protected]> | 2017-02-20 23:46:03 -0800 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2017-02-21 08:46:03 +0100 |
commit | 86e8dd62f0b1c8adf14e9369b089d209317aaf2d (patch) | |
tree | abd50df60bd2486cf71268bd15aacd24ccec3a78 /parser | |
parent | a3af4fe46e1e1d184538a83bc8375154a9669316 (diff) | |
download | hugo-86e8dd62f0b1c8adf14e9369b089d209317aaf2d.tar.gz hugo-86e8dd62f0b1c8adf14e9369b089d209317aaf2d.zip |
all: Add org-mode support
Fixes #1483
See #936
Diffstat (limited to 'parser')
-rw-r--r-- | parser/frontmatter.go | 7 | ||||
-rw-r--r-- | parser/page.go | 16 |
2 files changed, 20 insertions, 3 deletions
diff --git a/parser/frontmatter.go b/parser/frontmatter.go index ed25c08e1..e57a593ab 100644 --- a/parser/frontmatter.go +++ b/parser/frontmatter.go @@ -19,6 +19,7 @@ import ( "errors" "strings" + "github.com/chaseadamsio/goorgeous" toml "github.com/pelletier/go-toml" "gopkg.in/yaml.v2" @@ -154,6 +155,8 @@ func DetectFrontMatter(mark rune) (f *frontmatterType) { return &frontmatterType{[]byte(TOMLDelim), []byte(TOMLDelim), HandleTOMLMetaData, false} case '{': return &frontmatterType{[]byte{'{'}, []byte{'}'}, HandleJSONMetaData, true} + case '#': + return &frontmatterType{[]byte("#+"), []byte("\n"), HandleOrgMetaData, false} default: return nil } @@ -189,3 +192,7 @@ func HandleJSONMetaData(datum []byte) (interface{}, error) { err := json.Unmarshal(datum, &f) return f, err } + +func HandleOrgMetaData(datum []byte) (interface{}, error) { + return goorgeous.OrgHeaders(datum) +} diff --git a/parser/page.go b/parser/page.go index 57b2d3045..3347380d7 100644 --- a/parser/page.go +++ b/parser/page.go @@ -21,6 +21,8 @@ import ( "regexp" "strings" "unicode" + + "github.com/chaseadamsio/goorgeous" ) const ( @@ -91,9 +93,11 @@ func (p *page) Metadata() (meta interface{}, err error) { if len(frontmatter) != 0 { fm := DetectFrontMatter(rune(frontmatter[0])) - meta, err = fm.Parse(frontmatter) - if err != nil { - return + if fm != nil { + meta, err = fm.Parse(frontmatter) + if err != nil { + return + } } } return @@ -129,6 +133,12 @@ func ReadFrom(r io.Reader) (p Page, err error) { return nil, err } newp.frontmatter = fm + } else if newp.render && goorgeous.IsKeyword(firstLine) { + fm, err := goorgeous.ExtractOrgHeaders(reader) + if err != nil { + return nil, err + } + newp.frontmatter = fm } content, err := extractContent(reader) |