| 1 | package template |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "strings" |
| 6 | ) |
| 7 | |
| 8 | // Extract returns the content between marker comments in a Confluence XML document. |
| 9 | func Extract(xmlDoc, markerStart, markerEnd string) (string, error) { |
| 10 | startIdx := strings.Index(xmlDoc, markerStart) |
| 11 | if startIdx == -1 { |
| 12 | return "", fmt.Errorf("start marker %q not found in document", markerStart) |
| 13 | } |
| 14 | endIdx := strings.Index(xmlDoc, markerEnd) |
| 15 | if endIdx == -1 { |
| 16 | return "", fmt.Errorf("end marker %q not found in document", markerEnd) |
| 17 | } |
| 18 | if endIdx < startIdx { |
| 19 | return "", fmt.Errorf("end marker appears before start marker") |
| 20 | } |
| 21 | |
| 22 | content := xmlDoc[startIdx+len(markerStart) : endIdx] |
| 23 | return strings.TrimSpace(content), nil |
| 24 | } |
| 25 | |