From b3c9be255de398479beef1ace84f203518831659 Mon Sep 17 00:00:00 2001 From: petertzy <97914108+petertzy@users.noreply.github.com> Date: Sat, 7 Mar 2026 15:40:20 +0100 Subject: [PATCH 1/2] initial fixed --- .vscode/settings.json | 3 ++- app.py | 22 +++++++++++++++++++--- markdown_reader/logic.py | 4 ++-- markdown_reader/ui.py | 1 + setup.py | 13 ++++++++++--- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index c9ebf2d..9431ac0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "python-envs.defaultEnvManager": "ms-python.python:system" + "python-envs.defaultEnvManager": "ms-python.python:system", + "git.ignoreLimitWarning": true } \ No newline at end of file diff --git a/app.py b/app.py index 21d704a..9db6d64 100644 --- a/app.py +++ b/app.py @@ -2,6 +2,7 @@ from markdown_reader.ui import MarkdownReader import sys import os +import traceback import ttkbootstrap as ttkb from ttkbootstrap.constants import * @@ -19,6 +20,18 @@ def handle_open_file(event): if __name__ == "__main__": + def _log_unhandled_exception(exc_type, exc_value, exc_tb): + try: + log_path = os.path.expanduser("~/Library/Logs/MarkdownReader-launch.log") + with open(log_path, "a", encoding="utf-8") as log_file: + log_file.write("\n=== Unhandled Exception ===\n") + traceback.print_exception(exc_type, exc_value, exc_tb, file=log_file) + except Exception: + pass + traceback.print_exception(exc_type, exc_value, exc_tb) + + sys.excepthook = _log_unhandled_exception + try: from tkinterdnd2 import TkinterDnD root = TkinterDnD.Tk() @@ -27,8 +40,8 @@ def handle_open_file(event): app_style = ttkb.Style(theme="darkly") print("TkinterDnD enabled - Drag and drop support available") - except ImportError as e: - print(f" Warning: tkinterdnd2 not installed, drag-and-drop will be disabled") + except (ImportError, RuntimeError) as e: + print(f" Warning: tkinterdnd2 not available, drag-and-drop will be disabled") print(f" Error: {e}") root = ttkb.Window(themename="darkly") @@ -38,7 +51,10 @@ def handle_open_file(event): app = MarkdownReader(root) # Handle file open events from macOS Finder - root.createcommand("::tk::mac::OpenDocument", lambda *args: handle_open_file(args[0])) + root.createcommand( + "::tk::mac::OpenDocument", + lambda *args: handle_open_file(args[0]) if args else None, + ) # Handle file opening from command line if len(sys.argv) > 1: diff --git a/markdown_reader/logic.py b/markdown_reader/logic.py index 20f527c..6693877 100644 --- a/markdown_reader/logic.py +++ b/markdown_reader/logic.py @@ -535,7 +535,7 @@ def _is_probably_math_token(token): if core.startswith(('http://', 'https://', 'www.', 'file://')): return False - if '$' in core or '\(' in core or '\)' in core or '\[' in core or '\]' in core: + if '$' in core or '(' in core or ')' in core or '[' in core or ']' in core: return False # Reject pure lowercase English words (at least 3 chars), but allow math vars @@ -602,7 +602,7 @@ def _is_markdown_media_line(stripped_line): def _auto_wrap_bare_math_spans(markdown_text): - """ + r""" Wrap likely inline bare math tokens with \(...\) in mixed prose lines. Returns list of (protected_text, replacements_dict) to preserve LaTeX delimiters. diff --git a/markdown_reader/ui.py b/markdown_reader/ui.py index 53d19b4..18bb6db 100644 --- a/markdown_reader/ui.py +++ b/markdown_reader/ui.py @@ -133,6 +133,7 @@ def create_widgets(self): style = ttkb.Style() menubar = tk.Menu(self.root) + filemenu = tk.Menu(menubar, tearoff=0) filemenu.add_command(label="New", command=self.new_file) filemenu.add_command(label="Open File", command=self.open_file) diff --git a/setup.py b/setup.py index 3205e58..02afe11 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,19 @@ +import sys from setuptools import setup +# Increase recursion limit to handle deep dependency trees +sys.setrecursionlimit(5000) + APP = ['app.py'] DATA_FILES = [] OPTIONS = { 'argv_emulation': False, 'iconfile': 'icon.icns', - 'packages': ['markdown_reader', 'pygments', 'tkinterdnd2'], - 'includes': ['tkinter', 'markdown2', 'docx', 'html2text', 'watchdog', 'tkinterdnd2', 'pygments.lexers', 'pygments.lexers.shell'], - 'excludes': ['PIL', 'numpy', 'scipy', 'matplotlib'], + 'packages': ['markdown_reader', 'pygments', 'tkinterdnd2', 'PIL'], + 'includes': ['tkinter', 'markdown2', 'docx', 'html2text', 'watchdog', 'tkinterdnd2', 'pygments.lexers', 'pygments.lexers.shell', 'PIL', 'PIL.Image'], + 'excludes': ['numpy', 'scipy', 'matplotlib', 'docling', 'pymupdf', 'datasets', 'torch', 'tensorflow', 'sympy', 'pandas', 'PyQt6', 'PyQt5', 'PySide6', 'PySide2', 'jupyter', 'ipython', 'IPython', 'sip', 'PyQt6.sip', 'PyQt5.sip'], + 'semi_standalone': False, + 'site_packages': False, 'plist': { 'CFBundleName': 'MarkdownReader', 'CFBundleDisplayName': 'MarkdownReader', @@ -15,6 +21,7 @@ 'CFBundleVersion': '1.0.0', 'CFBundleShortVersionString': '1.0.0', 'LSMinimumSystemVersion': '10.14.0', + 'NSHighResolutionCapable': True, 'CFBundleDocumentTypes': [ { 'CFBundleTypeName': 'Markdown File', From 88620e106886dec728c33883c9cbe767530a0e6c Mon Sep 17 00:00:00 2001 From: petertzy <97914108+petertzy@users.noreply.github.com> Date: Sat, 7 Mar 2026 15:48:12 +0100 Subject: [PATCH 2/2] Revert "initial fixed" This reverts commit b3c9be255de398479beef1ace84f203518831659. --- .vscode/settings.json | 3 +-- app.py | 22 +++------------------- markdown_reader/logic.py | 4 ++-- markdown_reader/ui.py | 1 - setup.py | 13 +++---------- 5 files changed, 9 insertions(+), 34 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 9431ac0..c9ebf2d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,3 @@ { - "python-envs.defaultEnvManager": "ms-python.python:system", - "git.ignoreLimitWarning": true + "python-envs.defaultEnvManager": "ms-python.python:system" } \ No newline at end of file diff --git a/app.py b/app.py index 9db6d64..21d704a 100644 --- a/app.py +++ b/app.py @@ -2,7 +2,6 @@ from markdown_reader.ui import MarkdownReader import sys import os -import traceback import ttkbootstrap as ttkb from ttkbootstrap.constants import * @@ -20,18 +19,6 @@ def handle_open_file(event): if __name__ == "__main__": - def _log_unhandled_exception(exc_type, exc_value, exc_tb): - try: - log_path = os.path.expanduser("~/Library/Logs/MarkdownReader-launch.log") - with open(log_path, "a", encoding="utf-8") as log_file: - log_file.write("\n=== Unhandled Exception ===\n") - traceback.print_exception(exc_type, exc_value, exc_tb, file=log_file) - except Exception: - pass - traceback.print_exception(exc_type, exc_value, exc_tb) - - sys.excepthook = _log_unhandled_exception - try: from tkinterdnd2 import TkinterDnD root = TkinterDnD.Tk() @@ -40,8 +27,8 @@ def _log_unhandled_exception(exc_type, exc_value, exc_tb): app_style = ttkb.Style(theme="darkly") print("TkinterDnD enabled - Drag and drop support available") - except (ImportError, RuntimeError) as e: - print(f" Warning: tkinterdnd2 not available, drag-and-drop will be disabled") + except ImportError as e: + print(f" Warning: tkinterdnd2 not installed, drag-and-drop will be disabled") print(f" Error: {e}") root = ttkb.Window(themename="darkly") @@ -51,10 +38,7 @@ def _log_unhandled_exception(exc_type, exc_value, exc_tb): app = MarkdownReader(root) # Handle file open events from macOS Finder - root.createcommand( - "::tk::mac::OpenDocument", - lambda *args: handle_open_file(args[0]) if args else None, - ) + root.createcommand("::tk::mac::OpenDocument", lambda *args: handle_open_file(args[0])) # Handle file opening from command line if len(sys.argv) > 1: diff --git a/markdown_reader/logic.py b/markdown_reader/logic.py index 6693877..20f527c 100644 --- a/markdown_reader/logic.py +++ b/markdown_reader/logic.py @@ -535,7 +535,7 @@ def _is_probably_math_token(token): if core.startswith(('http://', 'https://', 'www.', 'file://')): return False - if '$' in core or '(' in core or ')' in core or '[' in core or ']' in core: + if '$' in core or '\(' in core or '\)' in core or '\[' in core or '\]' in core: return False # Reject pure lowercase English words (at least 3 chars), but allow math vars @@ -602,7 +602,7 @@ def _is_markdown_media_line(stripped_line): def _auto_wrap_bare_math_spans(markdown_text): - r""" + """ Wrap likely inline bare math tokens with \(...\) in mixed prose lines. Returns list of (protected_text, replacements_dict) to preserve LaTeX delimiters. diff --git a/markdown_reader/ui.py b/markdown_reader/ui.py index 18bb6db..53d19b4 100644 --- a/markdown_reader/ui.py +++ b/markdown_reader/ui.py @@ -133,7 +133,6 @@ def create_widgets(self): style = ttkb.Style() menubar = tk.Menu(self.root) - filemenu = tk.Menu(menubar, tearoff=0) filemenu.add_command(label="New", command=self.new_file) filemenu.add_command(label="Open File", command=self.open_file) diff --git a/setup.py b/setup.py index 02afe11..3205e58 100644 --- a/setup.py +++ b/setup.py @@ -1,19 +1,13 @@ -import sys from setuptools import setup -# Increase recursion limit to handle deep dependency trees -sys.setrecursionlimit(5000) - APP = ['app.py'] DATA_FILES = [] OPTIONS = { 'argv_emulation': False, 'iconfile': 'icon.icns', - 'packages': ['markdown_reader', 'pygments', 'tkinterdnd2', 'PIL'], - 'includes': ['tkinter', 'markdown2', 'docx', 'html2text', 'watchdog', 'tkinterdnd2', 'pygments.lexers', 'pygments.lexers.shell', 'PIL', 'PIL.Image'], - 'excludes': ['numpy', 'scipy', 'matplotlib', 'docling', 'pymupdf', 'datasets', 'torch', 'tensorflow', 'sympy', 'pandas', 'PyQt6', 'PyQt5', 'PySide6', 'PySide2', 'jupyter', 'ipython', 'IPython', 'sip', 'PyQt6.sip', 'PyQt5.sip'], - 'semi_standalone': False, - 'site_packages': False, + 'packages': ['markdown_reader', 'pygments', 'tkinterdnd2'], + 'includes': ['tkinter', 'markdown2', 'docx', 'html2text', 'watchdog', 'tkinterdnd2', 'pygments.lexers', 'pygments.lexers.shell'], + 'excludes': ['PIL', 'numpy', 'scipy', 'matplotlib'], 'plist': { 'CFBundleName': 'MarkdownReader', 'CFBundleDisplayName': 'MarkdownReader', @@ -21,7 +15,6 @@ 'CFBundleVersion': '1.0.0', 'CFBundleShortVersionString': '1.0.0', 'LSMinimumSystemVersion': '10.14.0', - 'NSHighResolutionCapable': True, 'CFBundleDocumentTypes': [ { 'CFBundleTypeName': 'Markdown File',