Browse Source

modules/markup: rename Markdown render fucntions

The unified function 'Markdown' accepts both string or []byte type
input and renders to HTML with []byte type.
pull/4017/merge
Unknwon 8 years ago
parent
commit
8da16ac302
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 19
      modules/markup/markdown.go
  2. 2
      routers/api/v1/misc/markdown.go
  3. 12
      routers/repo/issue.go
  4. 4
      routers/repo/release.go
  5. 4
      routers/repo/view.go
  6. 2
      routers/repo/wiki.go

19
modules/markup/markdown.go

@ -458,16 +458,21 @@ OUTER_LOOP:
return rawHTML
}
// Render renders Markdown to HTML with special links.
func Render(rawBytes []byte, urlPrefix string, metas map[string]string) []byte {
// Markdown takes a string or []byte and renders to HTML in Markdown syntax with special links.
func Markdown(input interface{}, urlPrefix string, metas map[string]string) []byte {
var rawBytes []byte
switch v := input.(type) {
case []byte:
rawBytes = v
case string:
rawBytes = []byte(v)
default:
panic(fmt.Sprintf("unexpected input content type: %T", input))
}
urlPrefix = strings.Replace(urlPrefix, space, spaceEncoded, -1)
result := RenderRaw(rawBytes, urlPrefix)
result = PostProcess(result, urlPrefix, metas)
result = SanitizeBytes(result)
return result
}
// RenderString renders Markdown to HTML with special links and returns string type.
func RenderString(raw, urlPrefix string, metas map[string]string) string {
return string(Render([]byte(raw), urlPrefix, metas))
}

2
routers/api/v1/misc/markdown.go

@ -25,7 +25,7 @@ func Markdown(ctx *context.APIContext, form api.MarkdownOption) {
switch form.Mode {
case "gfm":
ctx.Write(markup.Render([]byte(form.Text), form.Context, nil))
ctx.Write(markup.Markdown([]byte(form.Text), form.Context, nil))
default:
ctx.Write(markup.RenderRaw([]byte(form.Text), ""))
}

12
routers/repo/issue.go

@ -541,8 +541,7 @@ func viewIssue(ctx *context.Context, isPullList bool) {
ctx.Data["PageIsIssueList"] = true
}
issue.RenderedContent = string(markup.Render([]byte(issue.Content), ctx.Repo.RepoLink,
ctx.Repo.Repository.ComposeMetas()))
issue.RenderedContent = string(markup.Markdown(issue.Content, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
repo := ctx.Repo.Repository
@ -608,8 +607,7 @@ func viewIssue(ctx *context.Context, isPullList bool) {
participants[0] = issue.Poster
for _, comment = range issue.Comments {
if comment.Type == models.COMMENT_TYPE_COMMENT {
comment.RenderedContent = string(markup.Render([]byte(comment.Content), ctx.Repo.RepoLink,
ctx.Repo.Repository.ComposeMetas()))
comment.RenderedContent = string(markup.Markdown(comment.Content, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
// Check tag.
tag, ok = marked[comment.PosterID]
@ -728,7 +726,7 @@ func UpdateIssueContent(ctx *context.Context) {
}
ctx.JSON(200, map[string]interface{}{
"content": string(markup.Render([]byte(issue.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
"content": markup.Markdown(issue.Content, ctx.Query("context"), ctx.Repo.Repository.ComposeMetas()),
})
}
@ -939,7 +937,7 @@ func UpdateCommentContent(ctx *context.Context) {
}
ctx.JSON(200, map[string]interface{}{
"content": string(markup.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
"content": markup.Markdown(comment.Content, ctx.Query("context"), ctx.Repo.Repository.ComposeMetas()),
})
}
@ -1092,7 +1090,7 @@ func Milestones(ctx *context.Context) {
if m.NumOpenIssues+m.NumClosedIssues > 0 {
m.Completeness = m.NumClosedIssues * 100 / (m.NumOpenIssues + m.NumClosedIssues)
}
m.RenderedContent = string(markup.Render([]byte(m.Content), ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
m.RenderedContent = string(markup.Markdown(m.Content, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
}
ctx.Data["Milestones"] = miles

4
routers/repo/release.go

@ -83,7 +83,7 @@ func Releases(ctx *context.Context) {
return
}
r.Note = markup.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())
r.Note = string(markup.Markdown(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
results[i] = r
break
}
@ -132,7 +132,7 @@ func Releases(ctx *context.Context) {
return
}
r.Note = markup.RenderString(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas())
r.Note = string(markup.Markdown(r.Note, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
}
if len(drafts) > 0 {

4
routers/repo/view.go

@ -88,7 +88,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
switch {
case markup.IsMarkdownFile(readmeFile.Name()):
ctx.Data["IsMarkdown"] = true
buf = markup.Render(buf, treeLink, ctx.Repo.Repository.ComposeMetas())
buf = markup.Markdown(buf, treeLink, ctx.Repo.Repository.ComposeMetas())
default:
buf = bytes.Replace(buf, []byte("\n"), []byte(`<br>`), -1)
}
@ -160,7 +160,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
ctx.Data["IsIPythonNotebook"] = strings.HasSuffix(blob.Name(), ".ipynb")
if isMarkdown {
ctx.Data["FileContent"] = string(markup.Render(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
ctx.Data["FileContent"] = string(markup.Markdown(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
} else {
// Building code view blocks with line number on server side.
var fileContent string

2
routers/repo/wiki.go

@ -107,7 +107,7 @@ func renderWikiPage(ctx *context.Context, isViewPage bool) (*git.Repository, str
return nil, ""
}
if isViewPage {
ctx.Data["content"] = string(markup.Render(data, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
ctx.Data["content"] = string(markup.Markdown(data, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
} else {
ctx.Data["content"] = string(data)
}

Loading…
Cancel
Save