From 67a1c1ba6e45e125a6511c2a0708b38bb65d12ec Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Mon, 24 Mar 2025 17:17:45 +0300 Subject: [PATCH] Streamline debug JSON output formatting in PostParser --- post_parser.py | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/post_parser.py b/post_parser.py index 852c575..192cb1a 100644 --- a/post_parser.py +++ b/post_parser.py @@ -303,25 +303,9 @@ class PostParser: # Add raw JSON debug output if debug is enabled if debug: - 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'
{escaped_line}
') - - formatted_json = '\n'.join(json_html) - html_content.append(f'
{formatted_json}
') - except Exception as e: - html_content.append(f'
Error formatting JSON: {str(e)}
') - + debug_json = json.dumps(message, indent=2, ensure_ascii=False, default=str) + debug_json = debug_json.replace('\\n', '
').replace('\\"', '"') + html_content.append(f'
{debug_json}
') html_content = '\n'.join(html_content) return html_content