Merge pull request #19 from b3log/master

Simplify logic
This commit is contained in:
Yusuke Inuzuka 2019-08-16 18:17:17 +09:00 committed by GitHub
commit 3190eb8348
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 19 deletions

View file

@ -48,10 +48,8 @@ func (b *tableParagraphTransformer) Transform(node *gast.Paragraph, reader text.
table := ast.NewTable()
table.Alignments = alignments
table.AppendChild(table, ast.NewTableHeader(header))
if lines.Len() > 2 {
for i := 2; i < lines.Len(); i++ {
table.AppendChild(table, b.parseRow(lines.At(i), alignments, false, reader))
}
for i := 2; i < lines.Len(); i++ {
table.AppendChild(table, b.parseRow(lines.At(i), alignments, false, reader))
}
node.Parent().InsertBefore(node.Parent(), node, table)
node.Parent().RemoveChild(node.Parent(), node)
@ -116,24 +114,12 @@ func (b *tableParagraphTransformer) parseDelimiter(segment text.Segment, reader
var alignments []ast.Alignment
for _, col := range cols {
if tableDelimLeft.Match(col) {
if alignments == nil {
alignments = []ast.Alignment{}
}
alignments = append(alignments, ast.AlignLeft)
} else if tableDelimRight.Match(col) {
if alignments == nil {
alignments = []ast.Alignment{}
}
alignments = append(alignments, ast.AlignRight)
} else if tableDelimCenter.Match(col) {
if alignments == nil {
alignments = []ast.Alignment{}
}
alignments = append(alignments, ast.AlignCenter)
} else if tableDelimNone.Match(col) {
if alignments == nil {
alignments = []ast.Alignment{}
}
alignments = append(alignments, ast.AlignNone)
} else {
return nil

View file

@ -79,10 +79,9 @@ func ReadWhile(source []byte, index [2]int, pred func(byte) bool) (int, bool) {
// IsBlank returns true if the given string is all space characters.
func IsBlank(bs []byte) bool {
for _, b := range bs {
if IsSpace(b) {
continue
if !IsSpace(b) {
return false
}
return false
}
return true
}