aboutsummaryrefslogtreecommitdiff
path: root/parser.go
diff options
context:
space:
mode:
Diffstat (limited to 'parser.go')
-rw-r--r--parser.go213
1 files changed, 0 insertions, 213 deletions
diff --git a/parser.go b/parser.go
index 67f43b4..979811e 100644
--- a/parser.go
+++ b/parser.go
@@ -654,216 +654,3 @@ func parseStyle(styleName string) (styleKind int64) {
return 0
}
-
-// whatKindOfLine return the kind of line.
-// 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")
-
- // All of the comparison MUST be in order.
-
- if len(line) == 0 {
- return lineKindEmpty, nil, line
- }
- if bytes.HasPrefix(line, []byte(`////`)) {
- // Check for comment block first, since we use HasPrefix to
- // check for single line comment.
- return lineKindBlockComment, spaces, line
- }
- if bytes.HasPrefix(line, []byte(`//`)) {
- // Use HasPrefix to allow single line comment without space,
- // for example "//comment".
- return lineKindComment, spaces, line
- }
-
- var strline = string(line)
-
- switch strline {
- case `'''`, `---`, `- - -`, `***`, `* * *`:
- return lineKindHorizontalRule, spaces, line
- case `<<<`:
- return lineKindPageBreak, spaces, line
- case `--`:
- return elKindBlockOpen, spaces, line
- case `____`:
- return elKindBlockExcerpts, spaces, line
- case `....`:
- return elKindBlockLiteral, nil, line
- case `++++`:
- return elKindBlockPassthrough, spaces, line
- case `****`:
- return elKindBlockSidebar, nil, line
- case `====`:
- return elKindBlockExample, spaces, line
- case `[listing]`:
- return elKindBlockListingNamed, nil, line
- case `[literal]`:
- return elKindBlockLiteralNamed, nil, line
- case `toc::[]`:
- return elKindMacroTOC, spaces, line
- }
-
- if bytes.HasPrefix(line, []byte(`|===`)) {
- return elKindTable, nil, line
- }
- if bytes.HasPrefix(line, []byte(`image::`)) {
- return elKindBlockImage, spaces, line
- }
- if bytes.HasPrefix(line, []byte(`include::`)) {
- return lineKindInclude, nil, line
- }
- if bytes.HasPrefix(line, []byte(`video::`)) {
- return elKindBlockVideo, nil, line
- }
- if bytes.HasPrefix(line, []byte(`audio::`)) {
- return elKindBlockAudio, nil, line
- }
- if isAdmonition(line) {
- return lineKindAdmonition, nil, line
- }
-
- var (
- x int
- r byte
- hasSpace bool
- )
- for x, r = range line {
- if r == ' ' || r == '\t' {
- hasSpace = true
- continue
- }
- break
- }
- if hasSpace {
- spaces = line[:x]
- line = line[x:]
-
- // A line indented with space only allowed on list item,
- // otherwise it would be set as literal paragraph.
-
- if isLineDescriptionItem(line) {
- return elKindListDescriptionItem, spaces, line
- }
-
- if line[0] != '*' && line[0] != '-' && line[0] != '.' {
- return elKindLiteralParagraph, spaces, line
- }
- }
-
- switch line[0] {
- case ':':
- kind = lineKindAttribute
- case '[':
- var (
- newline = bytes.TrimRight(line, " \t")
- l = len(newline)
- )
-
- if newline[l-1] != ']' {
- return lineKindText, nil, line
- }
- if l >= 5 {
- // [[x]]
- if newline[1] == '[' && newline[l-2] == ']' {
- return lineKindID, nil, line
- }
- }
- if l >= 4 {
- // [#x]
- if line[1] == '#' {
- return lineKindIDShort, nil, line
- }
- // [.x]
- if line[1] == '.' {
- return lineKindStyleClass, nil, line
- }
- }
- return lineKindAttributeElement, spaces, line
- case '=':
- var subs = bytes.Fields(line)
-
- switch string(subs[0]) {
- case `=`:
- kind = elKindSectionL0
- case `==`:
- kind = elKindSectionL1
- case `===`:
- kind = elKindSectionL2
- case `====`:
- kind = elKindSectionL3
- case `=====`:
- kind = elKindSectionL4
- case `======`:
- kind = elKindSectionL5
- }
- return kind, spaces, line
-
- case '.':
- switch {
- case len(line) <= 1:
- kind = lineKindText
- case ascii.IsAlnum(line[1]):
- kind = lineKindBlockTitle
- default:
- x = 0
- for ; x < len(line); x++ {
- if line[x] == '.' {
- continue
- }
- if line[x] == ' ' || line[x] == '\t' {
- kind = elKindListOrderedItem
- return kind, spaces, line
- }
- }
- }
- case '*', '-':
- if len(line) <= 1 {
- kind = lineKindText
- return kind, spaces, line
- }
-
- var (
- listItemChar = line[0]
- count = 0
- )
- x = 0
- for ; x < len(line); x++ {
- if line[x] == listItemChar {
- count++
- continue
- }
- if line[x] == ' ' || line[x] == '\t' {
- kind = elKindListUnorderedItem
- return kind, spaces, line
- }
- // Break on the first non-space, so from above
- // condition we have,
- // - item
- // -- item
- // --- item
- // ---- // block listing
- // --unknown // break here
- break
- }
- if listItemChar == '-' && count == 4 && x == len(line) {
- kind = elKindBlockListing
- } else {
- kind = lineKindText
- }
- return kind, spaces, line
- default:
- switch string(line) {
- case `+`:
- kind = lineKindListContinue
- case `----`:
- kind = elKindBlockListing
- default:
- if isLineDescriptionItem(line) {
- kind = elKindListDescriptionItem
- }
- }
- }
- return kind, spaces, line
-}