aboutsummaryrefslogtreecommitdiff
path: root/markdown/ast_header.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-10-02 19:52:38 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2025-10-02 19:52:38 +0200
commit94dceb4f7c1740de9215b36ec183f93ca4337ee7 (patch)
tree5ad184efb0b74dd3aa4da7585f88a3e3f6cb4ecc /markdown/ast_header.go
parent8b249c9ce8bd1c351daf80c6c9b095fb1bccafe2 (diff)
style(markdown): fix typo in package name
Diffstat (limited to 'markdown/ast_header.go')
-rw-r--r--markdown/ast_header.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/markdown/ast_header.go b/markdown/ast_header.go
new file mode 100644
index 0000000..d51b046
--- /dev/null
+++ b/markdown/ast_header.go
@@ -0,0 +1,39 @@
+package markdown
+
+import (
+ "errors"
+ "fmt"
+ "html/template"
+)
+
+var ErrInvalidHeader = errors.New("invalid header")
+
+type astHeader struct {
+ level uint
+ content *astParagraph
+}
+
+func (a *astHeader) Eval() (template.HTML, *ParseError) {
+ if a.level > 6 {
+ return "", &ParseError{lxs: lexers{}, internal: ErrInvalidCodeFormat}
+ }
+ var content template.HTML
+ content, err := a.content.Eval()
+ if err != nil {
+ return "", err
+ }
+ return template.HTML(fmt.Sprintf("<h%d>%s</h%d>", a.level, trimSpace(content), a.level)), nil
+}
+
+func header(lxs *lexers) (*astHeader, *ParseError) {
+ b := &astHeader{level: uint(len(lxs.Current().Value))}
+ if !lxs.Next() {
+ return nil, &ParseError{lxs: *lxs, internal: ErrInvalidHeader}
+ }
+ var err *ParseError
+ b.content, err = paragraph(lxs, true)
+ if err != nil {
+ return nil, err
+ }
+ return b, nil
+}