Added [h1] to Plugin BBcode.

Added two tests for Plugin Markdown.
Added two tests for Plugin BBCode.
This commit is contained in:
Azareal 2019-04-09 21:52:09 +10:00
parent d52def14eb
commit d5acb92aef
2 changed files with 12 additions and 3 deletions

View File

@ -18,7 +18,8 @@ var bbcodeMissingTag []byte
var bbcodeBold *regexp.Regexp
var bbcodeItalic *regexp.Regexp
var bbcodeUnderline *regexp.Regexp
var bbcodeStrikethrough *regexp.Regexp
var bbcodeStrike *regexp.Regexp
var bbcodeH1 *regexp.Regexp
var bbcodeURL *regexp.Regexp
var bbcodeURLLabel *regexp.Regexp
var bbcodeQuotes *regexp.Regexp
@ -38,7 +39,8 @@ func initBbcode(plugin *common.Plugin) error {
bbcodeBold = regexp.MustCompile(`(?s)\[b\](.*)\[/b\]`)
bbcodeItalic = regexp.MustCompile(`(?s)\[i\](.*)\[/i\]`)
bbcodeUnderline = regexp.MustCompile(`(?s)\[u\](.*)\[/u\]`)
bbcodeStrikethrough = regexp.MustCompile(`(?s)\[s\](.*)\[/s\]`)
bbcodeStrike = regexp.MustCompile(`(?s)\[s\](.*)\[/s\]`)
bbcodeH1 = regexp.MustCompile(`(?s)\[h1\](.*)\[/h1\]`)
urlpattern := `(http|https|ftp|mailto*)(:??)\/\/([\.a-zA-Z\/]+)`
bbcodeURL = regexp.MustCompile(`\[url\]` + urlpattern + `\[/url\]`)
bbcodeURLLabel = regexp.MustCompile(`(?s)\[url=` + urlpattern + `\](.*)\[/url\]`)
@ -57,10 +59,11 @@ func bbcodeRegexParse(msg string) string {
msg = bbcodeBold.ReplaceAllString(msg, "<b>$1</b>")
msg = bbcodeItalic.ReplaceAllString(msg, "<i>$1</i>")
msg = bbcodeUnderline.ReplaceAllString(msg, "<u>$1</u>")
msg = bbcodeStrikethrough.ReplaceAllString(msg, "<s>$1</s>")
msg = bbcodeStrike.ReplaceAllString(msg, "<s>$1</s>")
msg = bbcodeURL.ReplaceAllString(msg, "<a href=''$1$2//$3' rel='nofollow'>$1$2//$3</i>")
msg = bbcodeURLLabel.ReplaceAllString(msg, "<a href=''$1$2//$3' rel='nofollow'>$4</i>")
msg = bbcodeQuotes.ReplaceAllString(msg, "<blockquote>$1</blockquote>")
msg = bbcodeH1.ReplaceAllString(msg, "<h2>$1</h2>")
//msg = bbcodeCode.ReplaceAllString(msg,"<span class='codequotes'>$1</span>")
return msg
}
@ -321,10 +324,12 @@ func bbcodeFullParse(msg string) string {
msg = string(msgbytes[0 : len(msgbytes)-10])
}
// TODO: Optimise these
//msg = bbcode_url.ReplaceAllString(msg,"<a href=\"$1$2//$3\" rel=\"nofollow\">$1$2//$3</i>")
msg = bbcodeURLLabel.ReplaceAllString(msg, "<a href='$1$2//$3' rel='nofollow'>$4</i>")
msg = bbcodeQuotes.ReplaceAllString(msg, "<blockquote>$1</blockquote>")
msg = bbcodeCode.ReplaceAllString(msg, "<span class='codequotes'>$1</span>")
msg = bbcodeH1.ReplaceAllString(msg, "<h2>$1</h2>")
} else {
msg = string(msgbytes[0 : len(msgbytes)-10])
}

View File

@ -48,6 +48,8 @@ func TestBBCodeRender(t *testing.T) {
msgList.Add("[i]hi[/i]", "<i>hi</i>")
msgList.Add("[s]hi[/s]", "<s>hi</s>")
msgList.Add("[c]hi[/c]", "[c]hi[/c]")
msgList.Add("[h1]hi", "[h1]hi")
msgList.Add("[h1]hi[/h1]", "<h2>hi</h2>")
if !testing.Short() {
//msgList.Add("[b]hi[/i]", "[b]hi[/i]")
//msgList.Add("[/b]hi[b]", "[/b]hi[b]")
@ -250,6 +252,8 @@ func TestMarkdownRender(t *testing.T) {
msgList2.Add("#", "#")
msgList2.Add("#h", "<h2>h</h2>")
msgList2.Add("#hi", "<h2>hi</h2>")
msgList2.Add("# hi", "<h2>hi</h2>")
msgList2.Add("# hi", "<h2>hi</h2>")
msgList.Add("\n#", "\n#")
msgList.Add("\n#h", "\n<h2>h</h2>")
msgList.Add("\n#hi", "\n<h2>hi</h2>")