aboutsummaryrefslogtreecommitdiff
path: root/mardown
diff options
context:
space:
mode:
Diffstat (limited to 'mardown')
-rw-r--r--mardown/ast.go20
-rw-r--r--mardown/ast_test.go20
-rw-r--r--mardown/lexer.go2
3 files changed, 39 insertions, 3 deletions
diff --git a/mardown/ast.go b/mardown/ast.go
index d9d2b1d..298b313 100644
--- a/mardown/ast.go
+++ b/mardown/ast.go
@@ -1,6 +1,7 @@
package mardown
import (
+ "encoding/json"
"errors"
"fmt"
"html/template"
@@ -17,7 +18,20 @@ type tree struct {
}
func (t *tree) Eval() (template.HTML, error) {
- return "", nil
+ var content template.HTML
+ for _, c := range t.blocks {
+ ct, err := c.Eval()
+ if err != nil {
+ return "", err
+ }
+ content += ct
+ }
+ return content, nil
+}
+
+func (t *tree) String() string {
+ b, _ := json.MarshalIndent(t, "", " ")
+ return string(b)
}
func ast(lxs *lexers) (*tree, error) {
@@ -29,7 +43,9 @@ func ast(lxs *lexers) (*tree, error) {
return nil, err
}
tr.blocks = append(tr.blocks, b)
- newLine = lxs.Current().Type == lexerBreak
+ if !lxs.Finished() {
+ newLine = lxs.Current().Type == lexerBreak
+ }
}
return tr, nil
}
diff --git a/mardown/ast_test.go b/mardown/ast_test.go
new file mode 100644
index 0000000..11a9639
--- /dev/null
+++ b/mardown/ast_test.go
@@ -0,0 +1,20 @@
+package mardown
+
+import "testing"
+
+func TestAst(t *testing.T) {
+ content := "bonsoir"
+ lxs := lex(content)
+ tree, err := ast(lxs)
+ if err != nil {
+ t.Fatal(err)
+ }
+ c, err := tree.Eval()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if c != "<p>bonsoir</p>" {
+ t.Errorf("failed, got %s", c)
+ t.Logf("lxs: %s\ntree: %s", lxs, tree)
+ }
+}
diff --git a/mardown/lexer.go b/mardown/lexer.go
index 7ab393f..4eaaf16 100644
--- a/mardown/lexer.go
+++ b/mardown/lexer.go
@@ -42,7 +42,7 @@ func (l *lexers) Current() lexer {
}
func (l *lexers) Finished() bool {
- return l.current >= len(l.lexers)-1
+ return l.current >= len(l.lexers)
}
func (l *lexers) String() string {