File: common_render.go

package info (click to toggle)
golang-github-miekg-mmark 1.3.4%2Bgit20161103.9.2d4f1dd%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 636 kB
  • ctags: 635
  • sloc: makefile: 33
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
}