fix: align nested Word blocks and synchronize CSS and heading navigation
This commit is contained in:
@@ -36,7 +36,7 @@ from PySide6.QtWidgets import (
|
||||
)
|
||||
|
||||
from .markdown_renderer import MarkdownRenderer
|
||||
from .markdown_utils import slugify_heading
|
||||
from .markdown_utils import heading_locations
|
||||
|
||||
|
||||
MAX_SYNTAX_HIGHLIGHT_CHARS = 1_000_000
|
||||
@@ -453,32 +453,8 @@ class MarkdownEditorDialog(QDialog):
|
||||
return True
|
||||
|
||||
def _heading_line_for_slug(self, target_slug: str) -> int | None:
|
||||
seen: dict[str, int] = {}
|
||||
in_fenced_block = False
|
||||
|
||||
for line_number, line in enumerate(self.source_text().splitlines()):
|
||||
stripped = line.strip()
|
||||
if stripped.startswith("```") or stripped.startswith("~~~"):
|
||||
in_fenced_block = not in_fenced_block
|
||||
continue
|
||||
if in_fenced_block:
|
||||
continue
|
||||
|
||||
match = re.match(r"^(#{1,6})\s+(.+?)\s*#*\s*$", stripped)
|
||||
if not match:
|
||||
continue
|
||||
|
||||
slug = slugify_heading(match.group(2).strip())
|
||||
if not slug:
|
||||
continue
|
||||
count = seen.get(slug, 0)
|
||||
seen[slug] = count + 1
|
||||
if count:
|
||||
slug = f"{slug}-{count + 1}"
|
||||
if slug == target_slug:
|
||||
return line_number
|
||||
|
||||
return None
|
||||
return next((line for heading, line in heading_locations(self.source_text(), self.renderer.markdown)
|
||||
if heading.slug == target_slug), None)
|
||||
|
||||
|
||||
def _on_editor_text_changed(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user