~shulhan/asciidoctor-go

741463b99f14f1869c804cd4c6b15be155a7c27e — Shulhan 3 months ago 8628bc2
all: add element kind Section 0

The elKindSection0 is the Document Title, the line that start
with "= ".
2 files changed, 6 insertions(+), 10 deletions(-)

M document_parser.go
M parser.go
M document_parser.go => document_parser.go +1 -1
@@ 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)


M parser.go => parser.go +5 -9
@@ 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: