mirror of
https://github.com/facundoolano/jorge.git
synced 2024-12-26 21:58:51 +01:00
test (and fix) org mode output
This commit is contained in:
parent
c4486f5a07
commit
b7d8d12df7
2 changed files with 47 additions and 3 deletions
|
@ -65,7 +65,11 @@ func Parse(path string) (*Template, error) {
|
|||
}
|
||||
|
||||
func (templ Template) Ext() string {
|
||||
return filepath.Ext(templ.srcPath)
|
||||
ext := filepath.Ext(templ.srcPath)
|
||||
if ext == ".org" {
|
||||
ext = ".html"
|
||||
}
|
||||
return ext
|
||||
}
|
||||
|
||||
func (templ Template) Render() ([]byte, error) {
|
||||
|
@ -87,7 +91,7 @@ func (templ Template) Render() ([]byte, error) {
|
|||
contents = append(contents, scanner.Text()+"\n"...)
|
||||
}
|
||||
|
||||
if templ.Ext() == ".org" {
|
||||
if strings.HasSuffix(templ.srcPath, ".org") {
|
||||
// if it's an org file, convert to html
|
||||
doc := org.New().Parse(bytes.NewReader(contents), templ.srcPath)
|
||||
html, err := doc.Write(org.NewHTMLWriter())
|
||||
|
|
|
@ -119,7 +119,47 @@ tags: ["software", "web"]
|
|||
}
|
||||
|
||||
func TestRenderOrg(t *testing.T) {
|
||||
// TODO
|
||||
input := `---
|
||||
title: my new post
|
||||
subtitle: a blog post
|
||||
tags: ["software", "web"]
|
||||
---
|
||||
#+OPTIONS: toc:nil num:nil
|
||||
* My title
|
||||
** my Subtitle
|
||||
- list 1
|
||||
- list 2
|
||||
`
|
||||
|
||||
file := newFile("test*.org", input)
|
||||
defer os.Remove(file.Name())
|
||||
|
||||
templ, err := Parse(file.Name())
|
||||
assertEqual(t, err, nil)
|
||||
assertEqual(t, templ.Ext(), ".html")
|
||||
|
||||
content, err := templ.Render()
|
||||
assertEqual(t, err, nil)
|
||||
expected := `<div id="outline-container-headline-1" class="outline-2">
|
||||
<h2 id="headline-1">
|
||||
My title
|
||||
</h2>
|
||||
<div id="outline-text-headline-1" class="outline-text-2">
|
||||
<div id="outline-container-headline-2" class="outline-3">
|
||||
<h3 id="headline-2">
|
||||
my Subtitle
|
||||
</h3>
|
||||
<div id="outline-text-headline-2" class="outline-text-3">
|
||||
<ul>
|
||||
<li>list 1</li>
|
||||
<li>list 2</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
assertEqual(t, string(content), expected)
|
||||
}
|
||||
|
||||
func TestRenderLiquidLayout(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue