Enhance reader styles exports and settings

This commit is contained in:
shenw
2026-06-14 09:51:16 +08:00
parent 586d384da3
commit 63a07b00b8
22 changed files with 3572 additions and 202 deletions
+17 -4
View File
@@ -45,6 +45,9 @@ from .markdown_renderer import MarkdownRenderer
from .markdown_utils import slugify_heading
MAX_SYNTAX_HIGHLIGHT_CHARS = 1_000_000
class LineNumberArea(QWidget):
def __init__(self, editor: "MarkdownSourceEditor") -> None:
super().__init__(editor)
@@ -237,7 +240,8 @@ class MarkdownEditorDialog(QDialog):
font_scale: float,
document_font_family: str,
document_font_size: int,
math_engine: str,
document_style_css: str = "",
math_engine: str = "katex",
original_source: str | None = None,
file_signature: tuple[int, int] | None = None,
draft_callback: Callable[[str], None] | None = None,
@@ -255,6 +259,7 @@ class MarkdownEditorDialog(QDialog):
self.font_scale = font_scale
self.document_font_family = document_font_family
self.document_font_size = document_font_size
self.document_style_css = document_style_css
self.math_engine = math_engine
self.file_signature = file_signature
self.draft_callback = draft_callback
@@ -340,7 +345,11 @@ class MarkdownEditorDialog(QDialog):
editor_font.setStyleHint(QFont.StyleHint.Monospace)
self.editor.setFont(editor_font)
self._apply_editor_font()
self.highlighter = MarkdownSyntaxHighlighter(self.editor.document())
self.highlighter = (
MarkdownSyntaxHighlighter(self.editor.document())
if len(source) <= MAX_SYNTAX_HIGHLIGHT_CHARS
else None
)
self.editor.textChanged.connect(self._on_editor_text_changed)
self.editor.verticalScrollBar().valueChanged.connect(self._sync_preview_to_editor_scroll)
self.splitter.addWidget(self.editor)
@@ -401,7 +410,8 @@ class MarkdownEditorDialog(QDialog):
def apply_theme(self, dark: bool) -> None:
self.editor.apply_theme(dark)
self.highlighter.apply_theme(dark)
if self.highlighter is not None:
self.highlighter.apply_theme(dark)
if dark:
self.setStyleSheet(
"QDialog { background: #1f242b; color: #dbe2ea; }"
@@ -425,12 +435,14 @@ class MarkdownEditorDialog(QDialog):
font_scale: float,
document_font_family: str,
document_font_size: int,
math_engine: str,
document_style_css: str = "",
math_engine: str = "katex",
) -> None:
self.theme = theme
self.font_scale = font_scale
self.document_font_family = document_font_family
self.document_font_size = document_font_size
self.document_style_css = document_style_css
self.math_engine = math_engine
self.apply_theme(theme == "dark")
self._apply_editor_font()
@@ -716,6 +728,7 @@ class MarkdownEditorDialog(QDialog):
font_scale=self.font_scale,
document_font_family=self.document_font_family,
document_font_size=self.document_font_size,
document_style_css=self.document_style_css,
math_engine=self.math_engine,
)
base_path = str(self.save_target_path.parent.resolve()) + os.sep