File: common_render.go

package info (click to toggle)
golang-github-miekg-mmark 1.3.6%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 616 kB
  • sloc: makefile: 35
file content (18 lines) | stat: -rw-r--r-- 499 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Common functions used in the render backends.

package mmark

import "bytes"

// blockCodePrefix adds the prefix to each line of text and returns it as a byte slice.
// If prefix is empty, text is returned as-is.
func blockCodePrefix(prefix string, text []byte) []byte {
	if prefix == "" {
		return text
	}

	nl := bytes.Count(text, []byte{'\n'})
	prefixText := bytes.Replace(text, []byte{'\n'}, []byte("\n"+prefix), nl-1)
	prefixText = append([]byte(prefix), prefixText...)
	return prefixText
}