aboutsummaryrefslogtreecommitdiff
path: root/internal/liturgy/citation.go
blob: 2c545c2a789c18680b77bee822c2ecb919bb38a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package liturgy

import (
	"fmt"
	"regexp"
	"strings"
)

// citationRe captures a scripture reference in a trailing "(...)" of a section
// heading, e.g. "Ewangelia (J 20, 1. 11-18)" -> "J 20, 1. 11-18".
var citationRe = regexp.MustCompile(`\((.+)\)\s*$`)

// ExtractCitation returns the scripture reference carried in a section
// heading's trailing parentheses, or an error when the heading has none.
func ExtractCitation(heading string) (string, error) {
	m := citationRe.FindStringSubmatch(heading)
	if m == nil {
		return "", fmt.Errorf("no reference found in heading: %q", heading)
	}
	return strings.TrimSpace(m[1]), nil
}