Enhance debug JSON

This commit is contained in:
vvzvlad
2025-03-24 17:06:24 +03:00
parent c4eee8b13a
commit d3def58d93
+19 -3
View File
@@ -303,9 +303,25 @@ class PostParser:
# Add raw JSON debug output if debug is enabled
if debug:
debug_json = json.dumps(message, indent=2, ensure_ascii=False, default=str)
debug_json = debug_json.replace('\\', '').replace('"{', '{').replace('}"', '}').replace('\n', '<br>')
html_content.append(f'<pre class="debug-json" style="background: #f5f5f5; padding: 10px; margin-top: 20px; overflow-x: auto; font-size: 10px; white-space: pre-wrap;">{debug_json}</pre>')
try:
# Convert the message to a dictionary
message_dict = message.__dict__
# Format JSON properly with indents
debug_json = json.dumps(message_dict, indent=4, ensure_ascii=False, default=str)
# Create a div for JSON display with proper styling
json_lines = debug_json.split('\n')
json_html = []
for line in json_lines:
# HTML escape each line individually
escaped_line = html.escape(line)
json_html.append(f'<div class="json-line">{escaped_line}</div>')
formatted_json = '\n'.join(json_html)
html_content.append(f'<div class="debug-json" style="background: #f5f5f5; padding: 10px; margin-top: 20px; overflow-x: auto; font-family: monospace; font-size: 12px;">{formatted_json}</div>')
except Exception as e:
html_content.append(f'<div class="debug-error">Error formatting JSON: {str(e)}</div>')
html_content = '\n'.join(html_content)
return html_content