aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-07-17 17:19:15 +0700
committerShulhan <ms@kilabit.info>2022-07-17 17:23:28 +0700
commit9decc98ee17cd4153ea43dff14a142472c29a137 (patch)
tree6cc0b1c6e585a05743a240fee32c478c49f41589
parenta62a9e10086bb24cda6831f147e573d00f39e28a (diff)
downloadasciidoctor-go-9decc98ee17cd4153ea43dff14a142472c29a137.tar.xz
all: trim the right spaces on each line during parsing kind of line
This is to prevent empty lines that contains only white spaces considered as non-empty line. While at it, fix typo in the comment.
-rw-r--r--document_parser_test.go38
-rw-r--r--parser.go5
2 files changed, 42 insertions, 1 deletions
diff --git a/document_parser_test.go b/document_parser_test.go
index e75781b..b5ed4d1 100644
--- a/document_parser_test.go
+++ b/document_parser_test.go
@@ -242,6 +242,44 @@ A B <a@b>; C <c@c>; D e_f G <>;`,
}
}
+func TestDocumentParser_parseHeader(t *testing.T) {
+ type testCase struct {
+ expDoc func() *Document
+ desc string
+ content string
+ expPreamble string
+ }
+
+ var cases = []testCase{{
+ desc: "With empty line contains white spaces",
+ content: "//// block\ncomment.\n////\n\t \n= Title\n",
+ expDoc: func() (doc *Document) {
+ doc = newDocument()
+ return doc
+ },
+ expPreamble: "= Title",
+ }}
+
+ var (
+ c testCase
+ expDoc *Document
+ gotDoc *Document
+ )
+
+ for _, c = range cases {
+ t.Log(c.desc)
+
+ expDoc = c.expDoc()
+ gotDoc = Parse([]byte(c.content))
+
+ test.Assert(t, "Title", expDoc.Title.raw, gotDoc.Title.raw)
+ test.Assert(t, "rawAuthors", expDoc.rawAuthors, gotDoc.rawAuthors)
+ test.Assert(t, "rawRevision", expDoc.rawRevision, gotDoc.rawRevision)
+ test.Assert(t, "Attributes", expDoc.Attributes, gotDoc.Attributes)
+ test.Assert(t, "Preamble text", c.expPreamble, gotDoc.preamble.toText())
+ }
+}
+
func TestDocumentParser_parseListDescription_withOpenBlock(t *testing.T) {
var content = []byte(`
Description:: Description body with open block.
diff --git a/parser.go b/parser.go
index 3ab28e8..f8b658b 100644
--- a/parser.go
+++ b/parser.go
@@ -690,6 +690,9 @@ func parseStyle(styleName string) (styleKind int64) {
// It will return lineKindText if the line does not match with known syntax.
func whatKindOfLine(line []byte) (kind int, spaces, got []byte) {
kind = lineKindText
+
+ line = bytes.TrimRight(line, " \f\n\r\t\v")
+
if len(line) == 0 {
return lineKindEmpty, nil, line
}
@@ -777,7 +780,7 @@ func whatKindOfLine(line []byte) (kind int, spaces, got []byte) {
spaces = line[:x]
line = line[x:]
- // A line idented with space only allowed on list item,
+ // A line indented with space only allowed on list item,
// otherwise it would be set as literal paragraph.
if isLineDescriptionItem(line) {