Skip to content

Commit

Permalink
Make inline callbacks changeable for users
Browse files Browse the repository at this point in the history
  • Loading branch information
kensanata committed Sep 12, 2023
1 parent 531d2d7 commit 302893f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion parser/inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (p *Parser) Inline(currBlock ast.Node, data []byte) {

n := len(data)
for end < n {
handler := p.inlineCallback[data[end]]
handler := p.InlineCallback[data[end]]
if handler == nil {
end++
continue
Expand Down
47 changes: 25 additions & 22 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,14 @@ type Parser struct {
// after parsing, this is AST root of parsed markdown text
Doc ast.Node

// InlineCallback maps special bytes that trigger inlineParser
// functions.
InlineCallback [256]inlineParser

extensions Extensions

refs map[string]*reference
refsRecord map[string]struct{}
inlineCallback [256]inlineParser
nesting int
maxNesting int
insideLink bool
Expand Down Expand Up @@ -149,33 +152,33 @@ func NewWithExtensions(extension Extensions) *Parser {
p.oldTip = p.Doc
p.lastMatchedContainer = p.Doc

p.inlineCallback[' '] = maybeLineBreak
p.inlineCallback['*'] = emphasis
p.inlineCallback['_'] = emphasis
p.InlineCallback[' '] = maybeLineBreak
p.InlineCallback['*'] = emphasis
p.InlineCallback['_'] = emphasis
if p.extensions&Strikethrough != 0 {
p.inlineCallback['~'] = emphasis
}
p.inlineCallback['`'] = codeSpan
p.inlineCallback['\n'] = lineBreak
p.inlineCallback['['] = link
p.inlineCallback['<'] = leftAngle
p.inlineCallback['\\'] = escape
p.inlineCallback['&'] = entity
p.inlineCallback['!'] = maybeImage
p.InlineCallback['~'] = emphasis
}
p.InlineCallback['`'] = codeSpan
p.InlineCallback['\n'] = lineBreak
p.InlineCallback['['] = link
p.InlineCallback['<'] = leftAngle
p.InlineCallback['\\'] = escape
p.InlineCallback['&'] = entity
p.InlineCallback['!'] = maybeImage
if p.extensions&Mmark != 0 {
p.inlineCallback['('] = maybeShortRefOrIndex
p.InlineCallback['('] = maybeShortRefOrIndex
}
p.inlineCallback['^'] = maybeInlineFootnoteOrSuper
p.InlineCallback['^'] = maybeInlineFootnoteOrSuper
if p.extensions&Autolink != 0 {
p.inlineCallback['h'] = maybeAutoLink
p.inlineCallback['m'] = maybeAutoLink
p.inlineCallback['f'] = maybeAutoLink
p.inlineCallback['H'] = maybeAutoLink
p.inlineCallback['M'] = maybeAutoLink
p.inlineCallback['F'] = maybeAutoLink
p.InlineCallback['h'] = maybeAutoLink
p.InlineCallback['m'] = maybeAutoLink
p.InlineCallback['f'] = maybeAutoLink
p.InlineCallback['H'] = maybeAutoLink
p.InlineCallback['M'] = maybeAutoLink
p.InlineCallback['F'] = maybeAutoLink
}
if p.extensions&MathJax != 0 {
p.inlineCallback['$'] = math
p.InlineCallback['$'] = math
}

return &p
Expand Down

0 comments on commit 302893f

Please sign in to comment.