fix: protect editor content and harden document exports
Protect pending edits on window close, keep save-as paths and drafts consistent, copy relative image resources, reject oversized table imports without truncation, and preserve independent preview scrolling during refresh. Archive rendered MHTML resources with portable references and embedded local fonts. Preserve existing outputs on export cancellation or failure. Convert editor match positions and filter directory results in linear passes. Include the previously completed editor image/table/history improvements, undoable replacement, export snapshots, shared page settings, and cancellable PDF/Word export workflow. Update documentation and version to 0.3.1. Validation: 142 pytest cases passed; GUI smoke, improvements integration, and offline MHTML/scroll reliability smoke checks passed.
This commit is contained in:
@@ -63,6 +63,25 @@ class MarkdownRenderer:
|
||||
self.markdown.core.ruler.push("mdhelper_heading_ids", self._add_heading_ids)
|
||||
self.markdown.core.ruler.push("mdhelper_admonitions", self._convert_admonitions)
|
||||
self.markdown.core.ruler.push("mdhelper_task_lists", self._convert_task_lists)
|
||||
self.markdown.core.ruler.push("mdhelper_source_lines", self._add_source_lines)
|
||||
for name in ("fence", "code_block", "math_block"):
|
||||
original = self.markdown.renderer.rules[name]
|
||||
def mapped(tokens, idx, options, env, render=original):
|
||||
output = render(tokens, idx, options, env)
|
||||
mapping = tokens[idx].map
|
||||
if mapping and env.get("source_map"):
|
||||
output = output.replace("<div", f'<div data-source-line="{mapping[0]}" data-source-end="{mapping[1]}"', 1)
|
||||
return output
|
||||
self.markdown.renderer.rules[name] = mapped
|
||||
|
||||
@staticmethod
|
||||
def _add_source_lines(state: Any) -> None:
|
||||
if not state.env.get("source_map"):
|
||||
return
|
||||
for token in state.tokens:
|
||||
if token.map and token.nesting == 1:
|
||||
token.attrSet("data-source-line", str(token.map[0]))
|
||||
token.attrSet("data-source-end", str(token.map[1]))
|
||||
|
||||
def render_file(
|
||||
self,
|
||||
@@ -104,8 +123,9 @@ class MarkdownRenderer:
|
||||
document_font_size: int | None = None,
|
||||
document_style_css: str = "",
|
||||
math_engine: str = "katex",
|
||||
source_map: bool = False,
|
||||
) -> str:
|
||||
env: dict[str, Any] = {"path": str(markdown_path), "headings": []}
|
||||
env: dict[str, Any] = {"path": str(markdown_path), "headings": [], "source_map": source_map}
|
||||
body = self.markdown.render(source, env)
|
||||
return self._wrap_html(
|
||||
body=body,
|
||||
|
||||
Reference in New Issue
Block a user