diff options
| author | Shulhan <ms@kilabit.info> | 2024-08-13 00:21:14 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2024-08-13 00:21:14 +0700 |
| commit | 741463b99f14f1869c804cd4c6b15be155a7c27e (patch) | |
| tree | ea793bb911a250e5bbc5d5bc8e0e69409eb9163b | |
| parent | 8628bc2cc75ad1069fcb1e633e02e04132c348e9 (diff) | |
| download | asciidoctor-go-741463b99f14f1869c804cd4c6b15be155a7c27e.tar.xz | |
all: add element kind Section 0
The elKindSection0 is the Document Title, the line that start
with "= ".
| -rw-r--r-- | document_parser.go | 2 | ||||
| -rw-r--r-- | parser.go | 14 |
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) @@ -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: |
