|
|
|
@ -91,7 +91,9 @@ func (options *CustomRender) Link(out *bytes.Buffer, link []byte, title []byte, |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
mentionPattern = regexp.MustCompile(`@[0-9a-zA-Z_]{1,}`) |
|
|
|
|
commitPattern = regexp.MustCompile(`[^>]http[s]{0,}.*commit/[0-9a-zA-Z]{1,}`) |
|
|
|
|
commitPattern = regexp.MustCompile(`(\s|^)https?.*commit/[0-9a-zA-Z]+(#+[0-9a-zA-Z-]*)?`) |
|
|
|
|
issueFullPattern = regexp.MustCompile(`(\s|^)https?.*issues/[0-9]+(#+[0-9a-zA-Z-]*)?`) |
|
|
|
|
issueIndexPattern = regexp.MustCompile(`(\s|^)#[0-9]+`) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte { |
|
|
|
@ -102,8 +104,31 @@ func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte { |
|
|
|
|
} |
|
|
|
|
ms = commitPattern.FindAll(rawBytes, -1) |
|
|
|
|
for _, m := range ms { |
|
|
|
|
rawBytes = bytes.Replace(rawBytes, m, |
|
|
|
|
[]byte(fmt.Sprintf(`<code><a href="%s">%s</a></code>`, m, m)), -1) |
|
|
|
|
m = bytes.TrimPrefix(m, []byte(" ")) |
|
|
|
|
i := strings.Index(string(m), "commit/") |
|
|
|
|
j := strings.Index(string(m), "#") |
|
|
|
|
if j == -1 { |
|
|
|
|
j = len(m) |
|
|
|
|
} |
|
|
|
|
rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf( |
|
|
|
|
` <code><a href="%s">%s</a></code>`, m, ShortSha(string(m[i+7:j])))), -1) |
|
|
|
|
} |
|
|
|
|
ms = issueFullPattern.FindAll(rawBytes, -1) |
|
|
|
|
for _, m := range ms { |
|
|
|
|
m = bytes.TrimPrefix(m, []byte(" ")) |
|
|
|
|
i := strings.Index(string(m), "issues/") |
|
|
|
|
j := strings.Index(string(m), "#") |
|
|
|
|
if j == -1 { |
|
|
|
|
j = len(m) |
|
|
|
|
} |
|
|
|
|
rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf( |
|
|
|
|
` <a href="%s">#%s</a>`, m, ShortSha(string(m[i+7:j])))), -1) |
|
|
|
|
} |
|
|
|
|
ms = issueIndexPattern.FindAll(rawBytes, -1) |
|
|
|
|
for _, m := range ms { |
|
|
|
|
m = bytes.TrimPrefix(m, []byte(" ")) |
|
|
|
|
rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf( |
|
|
|
|
` <a href="%s/issues/%s">%s</a>`, urlPrefix, m[1:], m)), -1) |
|
|
|
|
} |
|
|
|
|
return rawBytes |
|
|
|
|
} |
|
|
|
@ -122,10 +147,10 @@ func RenderMarkdown(rawBytes []byte, urlPrefix string) []byte { |
|
|
|
|
htmlFlags |= gfm.HTML_GITHUB_BLOCKCODE |
|
|
|
|
htmlFlags |= gfm.HTML_OMIT_CONTENTS |
|
|
|
|
// htmlFlags |= gfm.HTML_COMPLETE_PAGE
|
|
|
|
|
renderer := &CustomRender{ |
|
|
|
|
Renderer: gfm.HtmlRenderer(htmlFlags, "", ""), |
|
|
|
|
urlPrefix: urlPrefix, |
|
|
|
|
} |
|
|
|
|
// renderer := &CustomRender{
|
|
|
|
|
// Renderer: gfm.HtmlRenderer(htmlFlags, "", ""),
|
|
|
|
|
// urlPrefix: urlPrefix,
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// set up the parser
|
|
|
|
|
extensions := 0 |
|
|
|
@ -138,7 +163,7 @@ func RenderMarkdown(rawBytes []byte, urlPrefix string) []byte { |
|
|
|
|
extensions |= gfm.EXTENSION_SPACE_HEADERS |
|
|
|
|
extensions |= gfm.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK |
|
|
|
|
|
|
|
|
|
body = gfm.Markdown(body, renderer, extensions) |
|
|
|
|
fmt.Println(string(body)) |
|
|
|
|
// body = gfm.Markdown(body, renderer, extensions)
|
|
|
|
|
// fmt.Println(string(body))
|
|
|
|
|
return body |
|
|
|
|
} |
|
|
|
|