File: matter.go

package info (click to toggle)
golang-github-gomarkdown-markdown 0.0~git20231115.a660076-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,168 kB
  • sloc: sh: 26; makefile: 5
file content (36 lines) | stat: -rw-r--r-- 716 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package parser

import (
	"bytes"

	"github.com/gomarkdown/markdown/ast"
)

func (p *Parser) documentMatter(data []byte) int {
	if data[0] != '{' {
		return 0
	}

	consumed := 0
	matter := ast.DocumentMatterNone
	if bytes.HasPrefix(data, []byte("{frontmatter}")) {
		consumed = len("{frontmatter}")
		matter = ast.DocumentMatterFront
	}
	if bytes.HasPrefix(data, []byte("{mainmatter}")) {
		consumed = len("{mainmatter}")
		matter = ast.DocumentMatterMain
	}
	if bytes.HasPrefix(data, []byte("{backmatter}")) {
		consumed = len("{backmatter}")
		matter = ast.DocumentMatterBack
	}
	if consumed == 0 {
		return 0
	}
	node := &ast.DocumentMatter{Matter: matter}
	p.AddBlock(node)
	p.Finalize(node)

	return consumed
}