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)
| 341 | |
| 342 | // Render takes a string or []byte and renders to sanitized HTML in given type of syntax with special links. |
| 343 | func 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 | } |
no test coverage detected