e90d96961f
Restructured the plugin system. Multiple plugins can bind to the same hook now (not available for variadic hooks yet!) The parser is now benchmarked. The bench_round4 is run with both plugin_markdown and plugin_bbcode enabled. Added a benchmark for the BBCode plugin. Moved some of the template writing logic into a more generalised function. URLs are now recognised by the system and linked. Converted more custom errors into LocalError calls. Faster and less bandwidth intensive Emojis on Edge. Fixed a bug with replies not working.
29 lines
913 B
Go
29 lines
913 B
Go
package main
|
|
import "regexp"
|
|
|
|
var markdown_bold_italic *regexp.Regexp
|
|
var markdown_bold *regexp.Regexp
|
|
var markdown_italic *regexp.Regexp
|
|
|
|
func init() {
|
|
plugins["markdown"] = NewPlugin("markdown","Markdown","Azareal","http://github.com/Azareal","","","",init_markdown,nil,deactivate_markdown)
|
|
}
|
|
|
|
func init_markdown() {
|
|
plugins["markdown"].AddHook("parse_assign", markdown_parse)
|
|
markdown_bold_italic = regexp.MustCompile(`\*\*\*(.*)\*\*\*`)
|
|
markdown_bold = regexp.MustCompile(`\*\*(.*)\*\*`)
|
|
markdown_italic = regexp.MustCompile(`\*(.*)\*`)
|
|
}
|
|
|
|
func deactivate_markdown() {
|
|
plugins["markdown"].RemoveHook("parse_assign", markdown_parse)
|
|
}
|
|
|
|
func markdown_parse(data interface{}) interface{} {
|
|
msg := data.(string)
|
|
msg = markdown_bold_italic.ReplaceAllString(msg,"<i><b>$1</b></i>")
|
|
msg = markdown_bold.ReplaceAllString(msg,"<b>$1</b>")
|
|
msg = markdown_italic.ReplaceAllString(msg,"<i>$1</i>")
|
|
return msg
|
|
} |