Clone a paragraph in a slide. Args: slide (SlidePage): The slide containing the paragraph. div_id (int): The ID of the division containing the paragraph. paragraph_id (int): The ID of the paragraph to clone. Raises: IndexError: If the paragraph is not f
(slide: SlidePage, div_id: int, paragraph_id: int)
| 308 | |
| 309 | |
| 310 | def clone_paragraph(slide: SlidePage, div_id: int, paragraph_id: int): |
| 311 | """ |
| 312 | Clone a paragraph in a slide. |
| 313 | |
| 314 | Args: |
| 315 | slide (SlidePage): The slide containing the paragraph. |
| 316 | div_id (int): The ID of the division containing the paragraph. |
| 317 | paragraph_id (int): The ID of the paragraph to clone. |
| 318 | |
| 319 | Raises: |
| 320 | IndexError: If the paragraph is not found. |
| 321 | |
| 322 | Mention: the cloned paragraph will have a paragraph_id one greater than the current maximum in the parent element. |
| 323 | """ |
| 324 | shape = element_index(slide, div_id) |
| 325 | assert ( |
| 326 | shape.text_frame.is_textframe |
| 327 | ), "The element does not have a text frame, please check the element id and type of element." |
| 328 | max_idx = max([para.idx for para in shape.text_frame.paragraphs]) |
| 329 | for para in shape.text_frame.paragraphs: |
| 330 | if para.idx != paragraph_id: |
| 331 | continue |
| 332 | shape.text_frame.paragraphs.append(deepcopy(para)) |
| 333 | shape.text_frame.paragraphs[-1].idx = max_idx + 1 |
| 334 | shape.text_frame.paragraphs[-1].real_idx = len(shape.text_frame.paragraphs) - 1 |
| 335 | shape._closures["clone"].append( |
| 336 | Closure( |
| 337 | partial(clone_para, para.real_idx), |
| 338 | para.real_idx, |
| 339 | ) |
| 340 | ) |
| 341 | return |
| 342 | raise IndexError( |
| 343 | f"Cannot find the paragraph {paragraph_id} of the element {div_id}, may refer to a non-existed paragraph." |
| 344 | ) |
| 345 | |
| 346 | |
| 347 | class API_TYPES(Enum): |
nothing calls this directly
no test coverage detected