MCPcopy Create free account
hub / github.com/gogs/gogs / Render

Function Render

internal/markup/markup.go:343–367  ·  view source on GitHub ↗

Render takes a string or []byte and renders to sanitized HTML in given type of syntax with special links.

(typ Type, input any, urlPrefix string, metas map[string]string)

Source from the content-addressed store, hash-verified

341
342// Render takes a string or []byte and renders to sanitized HTML in given type of syntax with special links.
343func Render(typ Type, input any, urlPrefix string, metas map[string]string) []byte {
344 var rawBytes []byte
345 switch v := input.(type) {
346 case []byte:
347 rawBytes = v
348 case string:
349 rawBytes = []byte(v)
350 default:
351 panic(fmt.Sprintf("unrecognized input content type: %T", input))
352 }
353
354 urlPrefix = strings.TrimRight(strings.ReplaceAll(urlPrefix, " ", "%20"), "/")
355 var rawHTML []byte
356 switch typ {
357 case TypeMarkdown:
358 rawHTML = RawMarkdown(rawBytes, urlPrefix)
359 case TypeOrgMode:
360 rawHTML = RawOrgMode(rawBytes, urlPrefix)
361 default:
362 return rawBytes // Do nothing if syntax type is not recognized
363 }
364
365 rawHTML = postProcessHTML(rawHTML, urlPrefix, metas)
366 return SanitizeBytes(rawHTML)
367}

Callers 2

MarkdownFunction · 0.85
OrgModeFunction · 0.85

Calls 5

RawMarkdownFunction · 0.85
RawOrgModeFunction · 0.85
postProcessHTMLFunction · 0.85
SanitizeBytesFunction · 0.85
ReplaceAllMethod · 0.80

Tested by

no test coverage detected