Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ css = "table, th, td {border: 1px solid black;}"
pdf.add_section(Section(text), user_css=css)
```

The `sections` property of the `MarkdownPdf` class contains a list of added sections in the order in which they were added.

```python
assert len(pdf.sections) > 1
```

Set the properties of the pdf document.

```python
Expand Down
7 changes: 7 additions & 0 deletions README_ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ from markdown_pdf import Section

section = Section("# Title\n", toc=False)
assert section.page_count == 0

pdf.add_section(section)
assert section.page_count == 1
```
Expand Down Expand Up @@ -95,6 +96,12 @@ css = "table, th, td {border: 1px solid black;}"
pdf.add_section(Section(text), user_css=css)
```

Свойство `sections` кдасса `MarkdownPdf` содержит список секций в том порядке, в котором их добавляли.

```python
assert len(pdf.sections) > 1
```

Устанавливаем свойства pdf документа.

```python
Expand Down
2 changes: 2 additions & 0 deletions history.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
+ Section.page_count contains number of pdf pages that has been generated for section after add_section call.

+ The `sections` property of the `MarkdownPdf` class contains a list of added sections in the order in which they were added.

12.02.2026 ver.1.12
-------------------

Expand Down
4 changes: 3 additions & 1 deletion markdown_pdf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ def __init__(
self.m_d = (MarkdownIt(mode).enable('table')) # Enable support for tables

self.optimize = optimize

self.out_file = io.BytesIO()
self.writer = fitz.DocumentWriter(self.out_file)
self.page_num = 0
self.hrefs = []
self.sections = []

@staticmethod
def _recorder(elpos):
Expand Down Expand Up @@ -128,6 +128,8 @@ def add_section(self, section: Section, user_css: typing.Optional[str] = None) -
story.draw(device)
self.writer.end_page()

self.sections.append(section)

return html

def _make_doc(self):
Expand Down
2 changes: 2 additions & 0 deletions tests/test/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ def test_hrefs(self):
sect = Section(open(self.fixture("hrefs.md"), "rt", encoding='utf-8').read())
assert sect.page_count == 0
pdf = MarkdownPdf()
assert not pdf.sections
pdf.add_section(sect)
assert sect.page_count == 1
assert len(pdf.sections) == 1

pdf.save(self.build("hrefs.pdf"))

Expand Down
7 changes: 6 additions & 1 deletion tests/test/test_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ def test_en(self):
from markdown_pdf import Section, MarkdownPdf

pdf = MarkdownPdf(toc_level=2, optimize=True)
pdf.add_section(Section("# Title\n", toc=False))
section = Section("# Title\n", toc=False)
assert section.page_count == 0
pdf.add_section(section)
assert section.page_count == 1

text = """# Section with links

Expand Down Expand Up @@ -43,6 +46,8 @@ def test_en(self):

pdf.save(self.build("readme.pdf"))

assert len(pdf.sections) == 5

def test_user_case_1(self):
"""Test user case from discussion."""
from markdown_pdf import Section, MarkdownPdf
Expand Down