aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--document_parser.go2
-rw-r--r--parser.go14
2 files changed, 6 insertions, 10 deletions
diff --git a/document_parser.go b/document_parser.go
index 3b529fc..5f13fcf 100644
--- a/document_parser.go
+++ b/document_parser.go
@@ -702,7 +702,7 @@ func (docp *documentParser) parseHeader() {
if !ok {
return
}
- if docp.kind == lineKindText && isTitle(line) {
+ if docp.kind == elKindSectionL0 {
docp.doc.header.Write(bytes.TrimSpace(line[2:]))
docp.doc.Title.raw = string(docp.doc.header.raw)
diff --git a/parser.go b/parser.go
index 1f46b94..cab7abe 100644
--- a/parser.go
+++ b/parser.go
@@ -15,6 +15,7 @@ const (
elKindDocHeader // Wrapper.
elKindPreamble // Wrapper.
elKindDocContent // Wrapper.
+ elKindSectionL0 // Line started with "="
elKindSectionL1 // Line started with "=="
elKindSectionL2 // 5: Line started with "==="
elKindSectionL3 // Line started with "===="
@@ -535,15 +536,6 @@ func isStyleVerse(style int64) bool {
return style&styleVerse > 0
}
-func isTitle(line []byte) bool {
- if line[0] == '=' || line[0] == '#' {
- if len(line) > 1 && (line[1] == ' ' || line[1] == '\t') {
- return true
- }
- }
- return false
-}
-
// isValidID will return true if id is valid HTML ref ID according to
// [Mozilla specification], where the first character is either '-', '_', or
// ASCII letter, and the rest is either '-', '_', ASCII letter or digit.
@@ -841,6 +833,8 @@ func whatKindOfLine(line []byte) (kind int, spaces, got []byte) {
var subs = bytes.Fields(line)
switch string(subs[0]) {
+ case `=`:
+ kind = elKindSectionL0
case `==`:
kind = elKindSectionL1
case `===`:
@@ -852,6 +846,8 @@ func whatKindOfLine(line []byte) (kind int, spaces, got []byte) {
case `======`:
kind = elKindSectionL5
}
+ return kind, spaces, line
+
case '.':
switch {
case len(line) <= 1: