mirror of
https://github.com/RWejlgaard/org.git
synced 2026-05-06 04:34:45 +00:00
fix: custom states not parsed correctly has been fixed
This commit is contained in:
parent
eb5f9a16ce
commit
cad43fcb8a
2 changed files with 24 additions and 3 deletions
|
|
@ -40,7 +40,7 @@ func main() {
|
|||
}
|
||||
|
||||
// Parse the org file
|
||||
orgFile, err := parser.ParseOrgFile(filePath)
|
||||
orgFile, err := parser.ParseOrgFile(filePath, cfg)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error parsing org file: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/rwejlgaard/org/internal/config"
|
||||
"github.com/rwejlgaard/org/internal/model"
|
||||
)
|
||||
|
||||
// Parser patterns
|
||||
var (
|
||||
headingPattern = regexp.MustCompile(`^(\*+)\s+(?:(TODO|PROG|BLOCK|DONE)\s+)?(?:\[#([A-C])\]\s+)?(.+?)(?:\s+(:[[:alnum:]_@#%:]+:)\s*)?$`)
|
||||
scheduledPattern = regexp.MustCompile(`SCHEDULED:\s*<([^>]+)>`)
|
||||
deadlinePattern = regexp.MustCompile(`DEADLINE:\s*<([^>]+)>`)
|
||||
clockPattern = regexp.MustCompile(`CLOCK:\s*\[([^\]]+)\](?:--\[([^\]]+)\])?`)
|
||||
|
|
@ -23,8 +23,29 @@ var (
|
|||
codeBlockEnd = regexp.MustCompile(`^\s*#\+END_SRC`)
|
||||
)
|
||||
|
||||
// buildHeadingPattern creates a regex pattern that matches configured states
|
||||
func buildHeadingPattern(cfg *config.Config) *regexp.Regexp {
|
||||
stateNames := cfg.GetStateNames()
|
||||
var statesPattern string
|
||||
if len(stateNames) > 0 {
|
||||
// Escape state names and join with |
|
||||
escapedStates := make([]string, len(stateNames))
|
||||
for i, state := range stateNames {
|
||||
escapedStates[i] = regexp.QuoteMeta(state)
|
||||
}
|
||||
statesPattern = strings.Join(escapedStates, "|")
|
||||
} else {
|
||||
// Fallback to default states if none configured
|
||||
statesPattern = "TODO|PROG|BLOCK|DONE"
|
||||
}
|
||||
|
||||
pattern := `^(\*+)\s+(?:(` + statesPattern + `)\s+)?(?:\[#([A-C])\]\s+)?(.+?)(?:\s+(:[[:alnum:]_@#%:]+:)\s*)?$`
|
||||
return regexp.MustCompile(pattern)
|
||||
}
|
||||
|
||||
// ParseOrgFile reads and parses an org-mode file
|
||||
func ParseOrgFile(path string) (*model.OrgFile, error) {
|
||||
func ParseOrgFile(path string, cfg *config.Config) (*model.OrgFile, error) {
|
||||
headingPattern := buildHeadingPattern(cfg)
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
// If file doesn't exist, return empty org file
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue