mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 13:40:27 +02:00
Fixed markdown TOC generation
This commit is contained in:
+3
-1
@@ -1,5 +1,7 @@
|
||||
# 1.1.9
|
||||
# 1.1.9 (pre-release)
|
||||
- Fixed the issue where spaces were deleted before punctuation marks while generating subtitles.
|
||||
- Fixed markdown TOC generation breaks when "Replace single newlines" is enabled.
|
||||
- Improvements in code and documentation.
|
||||
|
||||
# 1.1.8
|
||||
- Added `.md` (Markdown) file extension support by @brianxiadong in PR #75
|
||||
|
||||
+10
-5
@@ -231,20 +231,24 @@ class HandlerDialog(QDialog):
|
||||
if not self.markdown_text:
|
||||
return
|
||||
|
||||
text = clean_text(self.markdown_text)
|
||||
text = textwrap.dedent(text)
|
||||
# Generate TOC from the original (dedented) markdown BEFORE cleaning,
|
||||
# so header ids/anchors are preserved for reliable position detection.
|
||||
original_text = textwrap.dedent(self.markdown_text)
|
||||
md = markdown.Markdown(extensions=['toc', 'fenced_code'])
|
||||
html = md.convert(text)
|
||||
html = md.convert(original_text)
|
||||
self.markdown_toc = md.toc_tokens
|
||||
|
||||
# Use cleaned text for stored content/length calculations
|
||||
cleaned_full_text = clean_text(original_text)
|
||||
|
||||
soup = BeautifulSoup(html, 'html.parser')
|
||||
self.content_texts = {}
|
||||
self.content_lengths = {}
|
||||
|
||||
if not self.markdown_toc:
|
||||
chapter_id = "markdown_content"
|
||||
self.content_texts[chapter_id] = text
|
||||
self.content_lengths[chapter_id] = calculate_text_length(text)
|
||||
self.content_texts[chapter_id] = cleaned_full_text
|
||||
self.content_lengths[chapter_id] = calculate_text_length(cleaned_full_text)
|
||||
return
|
||||
|
||||
all_headers = []
|
||||
@@ -279,6 +283,7 @@ class HandlerDialog(QDialog):
|
||||
header_tag = section_soup.find(attrs={'id': header_id})
|
||||
if header_tag:
|
||||
header_tag.decompose()
|
||||
# Clean section text for storage/lengths
|
||||
section_text = clean_text(section_soup.get_text()).strip()
|
||||
chapter_id = header_id
|
||||
if section_text:
|
||||
|
||||
Reference in New Issue
Block a user