From 35dedee0a14104430bb1b7ecef0f807d4b12f4b9 Mon Sep 17 00:00:00 2001 From: orzih Date: Sat, 3 Jul 2021 10:46:02 +0900 Subject: [PATCH] Fixed a bug with number-only page titles. #67 --- mkdocs_with_pdf/generator.py | 2 +- mkdocs_with_pdf/utils/section.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/mkdocs_with_pdf/generator.py b/mkdocs_with_pdf/generator.py index d2da177c..c9a331bf 100644 --- a/mkdocs_with_pdf/generator.py +++ b/mkdocs_with_pdf/generator.py @@ -222,7 +222,7 @@ def shift_heading(elem, page): page_path = self._page_path_for_id(page) h1 = soup.new_tag('h1', id=f'{page_path}') - h1.append(page.title) + h1.append(str(page.title)) elem.insert(0, h1) return elem diff --git a/mkdocs_with_pdf/utils/section.py b/mkdocs_with_pdf/utils/section.py index 97e13471..64cbe859 100644 --- a/mkdocs_with_pdf/utils/section.py +++ b/mkdocs_with_pdf/utils/section.py @@ -23,7 +23,8 @@ def _section_slug(section) -> str: if slug: return slug - title = section.title if len(section.title) else str(uuid4) + title = str(section.title).strip() + title = title if title else str(uuid4) slug = b32encode(title.encode('utf-8')).rstrip(b'=').decode() setattr(section, 'pdf_slug', slug)