(self, text_widget, json_text)
| 276 | text_widget.tag_configure('value', foreground='darkorange') |
| 277 | |
| 278 | def highlight_json(self, text_widget, json_text): |
| 279 | import re |
| 280 | """Apply highlighting to JSON text""" |
| 281 | text_widget.delete(1.0, tk.END) |
| 282 | text_widget.insert(1.0, json_text) |
| 283 | |
| 284 | # Patterns for key, string, number, boolean, null |
| 285 | patterns = { |
| 286 | 'brace': r'[{[\]}]', |
| 287 | 'key': r'\"(.*?)\"\s*:', |
| 288 | 'value': r'(?<=:\s)(\".*?\"|\d+(\.\d+)?|true|false|null)' |
| 289 | } |
| 290 | |
| 291 | # Apply tags based on patterns |
| 292 | for tag, pattern in patterns.items(): |
| 293 | for match in re.finditer(pattern, json_text): |
| 294 | start_idx = f"1.0 + {match.start()} chars" |
| 295 | end_idx = f"1.0 + {match.end()} chars" |
| 296 | text_widget.tag_add(tag, start_idx, end_idx) |
| 297 | |
| 298 | def rehighlight_json_on_enter(self, event): |
| 299 | """Event handler to rehighlight JSON on pressing Enter key""" |
no test coverage detected