~bigbes/confluence-md-utilities

ref: 4692639972ac74f39389c2d9767aa0bd2072bdf6 confluence-md-utilities/template/extract.go -rw-r--r-- 684 bytes
46926399 — Eugene Blikh Move CLI to cmd/mdcx/, add justfile and CLAUDE.md 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package template

import (
	"fmt"
	"strings"
)

// Extract returns the content between marker comments in a Confluence XML document.
func Extract(xmlDoc, markerStart, markerEnd string) (string, error) {
	startIdx := strings.Index(xmlDoc, markerStart)
	if startIdx == -1 {
		return "", fmt.Errorf("start marker %q not found in document", markerStart)
	}
	endIdx := strings.Index(xmlDoc, markerEnd)
	if endIdx == -1 {
		return "", fmt.Errorf("end marker %q not found in document", markerEnd)
	}
	if endIdx < startIdx {
		return "", fmt.Errorf("end marker appears before start marker")
	}

	content := xmlDoc[startIdx+len(markerStart) : endIdx]
	return strings.TrimSpace(content), nil
}