Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export inlineParser to allow more concise and readable custom parser functions #306

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var mds = `This is a [[wiki link]].
// wikiLink returns an inline parser function. This indirection is
// required because we want to call the previous definition in case
// this is not a wikiLink.
func wikiLink(p *parser.Parser, fn func(p *parser.Parser, data []byte, offset int) (int, ast.Node)) func(p *parser.Parser, data []byte, offset int) (int, ast.Node) {
func wikiLink(p *parser.Parser, fn parser.InlineParser) parser.InlineParser {
return func (p *parser.Parser, original []byte, offset int) (int, ast.Node) {
data := original[offset:]
n := len(data)
Expand Down
6 changes: 3 additions & 3 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const (
)

// for each character that triggers a response when parsing inline data.
type inlineParser func(p *Parser, data []byte, offset int) (int, ast.Node)
type InlineParser func(p *Parser, data []byte, offset int) (int, ast.Node)

// ReferenceOverrideFunc is expected to be called with a reference string and
// return either a valid Reference type that the reference string maps to or
Expand Down Expand Up @@ -98,7 +98,7 @@ type Parser struct {

refs map[string]*reference
refsRecord map[string]struct{}
inlineCallback [256]inlineParser
inlineCallback [256]InlineParser
nesting int
maxNesting int
insideLink bool
Expand Down Expand Up @@ -181,7 +181,7 @@ func NewWithExtensions(extension Extensions) *Parser {
return &p
}

func (p *Parser) RegisterInline(n byte, fn inlineParser) inlineParser {
func (p *Parser) RegisterInline(n byte, fn InlineParser) InlineParser {
prev := p.inlineCallback[n]
p.inlineCallback[n] = fn
return prev
Expand Down
Loading