Source File
list.go
Belonging Package
github.com/yuin/goldmark/parser
package parser
import (
)
type listItemType int
const (
notList listItemType = iota
bulletList
orderedList
)
func ( []byte) ([6]int, listItemType) {
:= 0
:= len()
:= [6]int{}
for ; < && [] == ' '; ++ {
:= []
if == '\t' {
return , notList
}
}
if > 3 {
return , notList
}
[0] = 0
[1] =
[2] =
var listItemType
if < && ([] == '-' || [] == '*' || [] == '+') {
++
[3] =
= bulletList
} else if < {
for ; < && util.IsNumeric([]); ++ {
}
[3] =
if [3] == [2] || [3]-[2] > 9 {
return , notList
}
if < && ([] == '.' || [] == ')') {
++
[3] =
} else {
return , notList
}
= orderedList
} else {
return , notList
}
if < && [] != '\n' {
, := util.IndentWidth([:], 0)
if == 0 {
return , notList
}
}
if >= {
[4] = -1
[5] = -1
return ,
}
[4] =
[5] = len()
if [[5]-1] == '\n' && [] != '\n' {
[5]--
}
return ,
}
func ( []byte, bool) ([6]int, listItemType) {
, := parseListItem()
if != notList && (! || && [1] < 4) {
return ,
}
return , notList
}
func ( []byte, [6]int) int {
:= 0
if [4] < 0 || util.IsBlank([[4]:]) { // list item starts with a blank line
= 1
} else {
, _ = util.IndentWidth([[4]:], [4])
if > 4 { // offseted codeblock
= 1
}
}
return
}
func ( ast.Node) int {
:= .LastChild()
if != nil {
return .(*ast.ListItem).Offset
}
return 0
}
type listParser struct {
}
var defaultListParser = &listParser{}
func () BlockParser {
return defaultListParser
}
func ( *listParser) () []byte {
return []byte{'-', '+', '*', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
}
func ( *listParser) ( ast.Node, text.Reader, Context) (ast.Node, State) {
:= .LastOpenedBlock().Node
if , := .(*ast.List); || .Get(skipListParser) != nil {
.Set(skipListParser, nil)
return nil, NoChildren
}
, := .PeekLine()
, := matchesListItem(, true)
if == notList {
return nil, NoChildren
}
:= -1
if == orderedList {
:= [[2] : [3]-1]
, _ = strconv.Atoi(string())
}
if == orderedList && != 1 {
return nil, NoChildren
if .ChildCount() == 1 && .LastChild().ChildCount() == 0 {
return Close
}
.Advance(len()-1)
return Continue | HasChildren
}
:= lastOffset()
, := util.IndentWidth(, .LineOffset())
if < {
if < 4 {
, := matchesListItem(, false) // may have a leading spaces more than 3
if != notList && [1]- < 4 {
:= [[3]-1]
if !.CanContinue(, == orderedList) {
return Close
if isThematicBreak([[3]-1:], 0) {
:= false
:= .LastOpenedBlock().Node
if ast.IsParagraph() {
, := matchesSetextHeadingBar([[3]-1:])
if && == '-' {
= true
}
}
if ! {
return Close
}
}
return Continue | HasChildren
}
}
return Close
}
return Continue | HasChildren
}
func ( *listParser) ( ast.Node, text.Reader, Context) {
:= .(*ast.List)
for := .FirstChild(); != nil && .IsTight; = .NextSibling() {
if .FirstChild() != nil && .FirstChild() != .LastChild() {
for := .FirstChild().NextSibling(); != nil; = .NextSibling() {
if , := .(ast.Node); && .HasBlankPreviousLines() {
.IsTight = false
break
}
}
}
if != .FirstChild() {
if , := .(ast.Node); && .HasBlankPreviousLines() {
.IsTight = false
}
}
}
if .IsTight {
for := .FirstChild(); != nil; = .NextSibling() {
for := .FirstChild(); != nil; = .NextSibling() {
, := .(*ast.Paragraph)
if {
:= ast.NewTextBlock()
.SetLines(.Lines())
.ReplaceChild(, , )
}
}
}
}
}
func ( *listParser) () bool {
return true
}
func ( *listParser) () bool {
return false
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |