Merge pull request #43 from mrvdb/hashlink

Hashtag linking improvements
This commit is contained in:
Matt Baer 2019-02-01 14:39:01 +01:00 committed by GitHub
commit ee6046bdbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -31,7 +31,7 @@ var (
endBlockReg = regexp.MustCompile("</([a-z]+)>\n</(ul|ol|blockquote)>") endBlockReg = regexp.MustCompile("</([a-z]+)>\n</(ul|ol|blockquote)>")
youtubeReg = regexp.MustCompile("(https?://www.youtube.com/embed/[a-zA-Z0-9\\-_]+)(\\?[^\t\n\f\r \"']+)?") youtubeReg = regexp.MustCompile("(https?://www.youtube.com/embed/[a-zA-Z0-9\\-_]+)(\\?[^\t\n\f\r \"']+)?")
titleElementReg = regexp.MustCompile("</?h[1-6]>") titleElementReg = regexp.MustCompile("</?h[1-6]>")
hashtagReg = regexp.MustCompile(`#([\p{L}\p{M}\d]+)`) hashtagReg = regexp.MustCompile(`(?m)(^| )#([\p{L}\p{M}\d]+)`)
markeddownReg = regexp.MustCompile("<p>(.+)</p>") markeddownReg = regexp.MustCompile("<p>(.+)</p>")
) )
@ -46,7 +46,7 @@ func (p *Post) formatContent(c *Collection, isOwner bool) {
// URL, so we rely on p.Tags as the final word on whether or not to link // URL, so we rely on p.Tags as the final word on whether or not to link
// a tag. // a tag.
for _, t := range p.Tags { for _, t := range p.Tags {
if string(b) == "#"+t { if strings.TrimSpace(string(b)) == "#"+t {
return bytes.Replace(b, []byte("#"+t), []byte("<a href=\""+baseURL+"tag:"+t+"\" class=\"hashtag\"><span>#</span><span class=\"p-category\">"+t+"</span></a>"), -1) return bytes.Replace(b, []byte("#"+t), []byte("<a href=\""+baseURL+"tag:"+t+"\" class=\"hashtag\"><span>#</span><span class=\"p-category\">"+t+"</span></a>"), -1)
} }
} }