Skip to content

Commit 1a201bc

Browse files
authored
feat: Allow exporting a specific page to md. (#63)
* Allow exporting a specific page to md. Signed-off-by: Yasyf Mohamedali <[email protected]> * Pass page_no to `iterate_items` recursive calls. Signed-off-by: Yasyf Mohamedali <[email protected]> * Address code review. Signed-off-by: Yasyf Mohamedali <[email protected]> --------- Signed-off-by: Yasyf Mohamedali <[email protected]>
1 parent 50bbe29 commit 1a201bc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

docling_core/types/doc/document.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,10 @@ def iterate_items(
12551255
# If the child is a NodeItem, recursively traverse it
12561256
if not isinstance(child, PictureItem) or traverse_pictures:
12571257
yield from self.iterate_items(
1258-
child, _level=_level + 1, with_groups=with_groups
1258+
child,
1259+
_level=_level + 1,
1260+
with_groups=with_groups,
1261+
page_no=page_no,
12591262
)
12601263

12611264
def print_element_tree(self):
@@ -1281,6 +1284,7 @@ def export_to_markdown( # noqa: C901
12811284
image_mode: ImageRefMode = ImageRefMode.PLACEHOLDER,
12821285
indent: int = 4,
12831286
text_width: int = -1,
1287+
page_no: Optional[int] = None,
12841288
) -> str:
12851289
r"""Serialize to Markdown.
12861290
@@ -1317,7 +1321,7 @@ def export_to_markdown( # noqa: C901
13171321
in_list = False # Track if we're currently processing list items
13181322

13191323
for ix, (item, level) in enumerate(
1320-
self.iterate_items(self.body, with_groups=True)
1324+
self.iterate_items(self.body, with_groups=True, page_no=page_no)
13211325
):
13221326
# If we've moved to a lower level, we're exiting one or more groups
13231327
if level < previous_level:

0 commit comments

Comments
 (0)