-
Notifications
You must be signed in to change notification settings - Fork 186
How to extend inline markdown parsing? #291
Copy link
Copy link
Closed
Description
I'd be interested in parsing [[links]] and #hashtags but don't know where to start.
My naïve approach would be something like the following for hashtags (untested, since it doesn't compile). I'm pretty new to Go so I'm guessing the reason this fails is because I have no access to Parser.inlineCallback. I think the best solution would be to add something to Options that would allow passing a additional values for inlineCallback?
func hashtag(p *parser.Parser, data []byte, offset int) (int, ast.Node) {
data = data[offset:]
i := 0
n := len(data)
for i < n && !parser.IsSpace(data[i]) {
i++
}
if i == 0 {
return 0, nil
}
link := &ast.Link{
Destination: append([]byte("/search?q=%23"), data[1:i]...),
Title: data[0:i],
}
return i + 1, link
}
// renderHtml renders the Page.Body to HTML and sets Page.Html.
func (p *Page) renderHtml() {
parser := parser.New()
parser.inlineCallback['#'] = hashtag
maybeUnsafeHTML := markdown.ToHTML(p.Body, parser, nil)
p.Html = sanitizeBytes(maybeUnsafeHTML)
p.Language = language(p.plainText())
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels