MCPcopy Create free account
hub / github.com/Bleemsys/Artisan-Core / highlight_json

Method highlight_json

AGUI/JSONtreeview.py:278–296  ·  view source on GitHub ↗
(self, text_widget, json_text)

Source from the content-addressed store, hash-verified

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"""

Callers 2

Calls 1

startMethod · 0.80

Tested by

no test coverage detected