aboutsummaryrefslogtreecommitdiff
path: root/modules/markup/markdown.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-03-31 16:37:30 -0400
committerUnknwon <u@gogs.io>2017-03-31 16:37:30 -0400
commit8da16ac302b78c4c6bad90cd5c8765de110c42af (patch)
treeaa2ed0872bd03e4d7f53586dda0efdd60f3a354a /modules/markup/markdown.go
parent761bb3cf53960485921ad045bae5a79340d66f97 (diff)
modules/markup: rename Markdown render fucntions
The unified function 'Markdown' accepts both string or []byte type input and renders to HTML with []byte type.
Diffstat (limited to 'modules/markup/markdown.go')
-rw-r--r--modules/markup/markdown.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/modules/markup/markdown.go b/modules/markup/markdown.go
index 51afe48e..e59ae9a6 100644
--- a/modules/markup/markdown.go
+++ b/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))
-}