-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from b3log/master
Fix some typos
- Loading branch information
Showing
7 changed files
with
96 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package parser | ||
|
||
import ( | ||
"github.com/yuin/goldmark/ast" | ||
"github.com/yuin/goldmark/text" | ||
"github.com/yuin/goldmark/util" | ||
) | ||
|
||
type ThematicBreakParser struct { | ||
} | ||
|
||
var defaultThematicBreakParser = &ThematicBreakParser{} | ||
|
||
// NewThematicBreakParser returns a new BlockParser that | ||
// parses thematic breaks. | ||
func NewThematicBreakParser() BlockParser { | ||
return defaultThematicBreakParser | ||
} | ||
|
||
func isThematicBreak(line []byte) bool { | ||
w, pos := util.IndentWidth(line, 0) | ||
if w > 3 { | ||
return false | ||
} | ||
mark := byte(0) | ||
count := 0 | ||
for i := pos; i < len(line); i++ { | ||
c := line[i] | ||
if util.IsSpace(c) { | ||
continue | ||
} | ||
if mark == 0 { | ||
mark = c | ||
count = 1 | ||
if mark == '*' || mark == '-' || mark == '_' { | ||
continue | ||
} | ||
return false | ||
} | ||
if c != mark { | ||
return false | ||
} | ||
count++ | ||
} | ||
return count > 2 | ||
} | ||
|
||
func (b *ThematicBreakParser) Open(parent ast.Node, reader text.Reader, pc Context) (ast.Node, State) { | ||
line, segment := reader.PeekLine() | ||
if isThematicBreak(line) { | ||
reader.Advance(segment.Len() - 1) | ||
return ast.NewThematicBreak(), NoChildren | ||
} | ||
return nil, NoChildren | ||
} | ||
|
||
func (b *ThematicBreakParser) Continue(node ast.Node, reader text.Reader, pc Context) State { | ||
return Close | ||
} | ||
|
||
func (b *ThematicBreakParser) Close(node ast.Node, reader text.Reader, pc Context) { | ||
// nothing to do | ||
} | ||
|
||
func (b *ThematicBreakParser) CanInterruptParagraph() bool { | ||
return true | ||
} | ||
|
||
func (b *ThematicBreakParser) CanAcceptIndentedLine() bool { | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters