@@ -90,25 +90,25 @@ def find_parents(candidate, branches):
9090
9191
9292def split_on_separators (text , separators ):
93- """Split text on multiple separators using regex.
94-
95- Separators are expected to be defined without whitespace, but during
96- matching, leading and trailing whitespace around separators is ignored.
97-
98- Returns a list of stripped text parts, or [text] if no separators found
99- """
100- # Check each separator individually first
101- for sep in separators :
102- # Create pattern with optional whitespace around separator
103- pattern = f" \\ s* { sep } \\ s*"
104- if re . search ( pattern , text ):
105- # Found a separator, split on it
106- parts = re . split ( pattern , text )
107- result = [ part . strip () for part in parts if part . strip ()]
108- return result
109-
110- # No separators found
111- return [text ]
93+ """Split text on configured separators; returns [text] if none."""
94+ # Normalize and drop empty/whitespace-only separators
95+ if isinstance ( separators , str ):
96+ seps = [ separators ]
97+ else :
98+ seps = list ( separators or [])
99+ seps = [ s for s in seps if isinstance ( s , str ) and s . strip ()]
100+ if not seps :
101+ return [ text ]
102+
103+ # One regex: separators at token boundaries (no letters/digits touching)
104+ # (?<!\S) == start or whitespace; (?!\S) == end or whitespace
105+ alt = "|" . join ( re . escape ( s ) for s in seps ) # escape special chars
106+ pattern = rf"(?<!\S)(?: { alt } )(?!\S)"
107+
108+ if not re . search ( pattern , text , flags = re . IGNORECASE ):
109+ return [ text ]
110+ parts = re . split ( pattern , text , flags = re . IGNORECASE )
111+ return [p . strip () for p in parts if p . strip () ]
112112
113113
114114# Main plugin logic.
0 commit comments