diff options
| author | Shulhan <ms@kilabit.info> | 2022-12-16 02:39:55 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-12-16 02:39:55 +0700 |
| commit | 2dd794265dfda767e12a009b26296acc121ca458 (patch) | |
| tree | b75ac94f42b4f9322ced45e4f6a5433f4fe5584c /document_parser.go | |
| parent | 60a55a32252e349f2bdfeace983c251ee5865fb6 (diff) | |
| download | asciidoctor-go-2dd794265dfda767e12a009b26296acc121ca458.tar.xz | |
all: detach parsing preamble from content
This is to prevent empty preamble being rendered in HTML content.
Diffstat (limited to 'document_parser.go')
| -rw-r--r-- | document_parser.go | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/document_parser.go b/document_parser.go index 2a29152..45b7597 100644 --- a/document_parser.go +++ b/document_parser.go @@ -118,6 +118,27 @@ func (docp *documentParser) consumeLinesUntil(el *element, term int, terms []int return line } +// hasPreamble will return true if the contents contains preamble, indicated +// by the first section that found after current line. +func (docp *documentParser) hasPreamble() bool { + var ( + start = docp.lineNum + + line []byte + kind int + ) + for ; start < len(docp.lines); start++ { + line = docp.lines[start] + kind, _, _ = whatKindOfLine(line) + if kind == elKindSectionL1 || kind == elKindSectionL2 || + kind == elKindSectionL3 || kind == elKindSectionL4 || + kind == elKindSectionL5 { + return true + } + } + return false +} + func (docp *documentParser) include(el *elementInclude) { var ( content []byte = bytes.ReplaceAll(el.content, []byte("\r\n"), []byte("\n")) @@ -336,9 +357,15 @@ func (docp *documentParser) parseBlock(parent *element, term int) { el = new(element) continue - case elKindSectionL1, elKindSectionL2, - elKindSectionL3, elKindSectionL4, - elKindSectionL5: + case elKindSectionL1, elKindSectionL2, elKindSectionL3, elKindSectionL4, elKindSectionL5: + if parent.kind == elKindPreamble { + docp.kind = lineKindEmpty + docp.prevKind = lineKindEmpty + docp.lineNum-- + isTerm = true + continue + } + if term == elKindBlockOpen { line = docp.parseParagraph(parent, el, line, term) parent.addChild(el) |
