55from bs4 import BeautifulSoup , Comment , Doctype , NavigableString
66from pydantic import BaseModel
77
8- from jsondoc .convert .utils import (
8+ from jsondoc .convert .placeholder import (
99 BreakElementPlaceholderBlock ,
1010 CaptionPlaceholderBlock ,
1111 CellPlaceholderBlock ,
1212 FigurePlaceholderBlock ,
13+ )
14+ from jsondoc .convert .utils import (
1315 append_rich_text_to_block ,
1416 append_to_parent_block ,
1517 append_to_rich_text ,
3537)
3638from jsondoc .models .block .base import BlockBase
3739from jsondoc .models .block .types .image import ImageBlock
40+ from jsondoc .models .block .types .paragraph import ParagraphBlock
3841from jsondoc .models .block .types .rich_text .base import RichTextBase
3942from jsondoc .models .block .types .rich_text .equation import RichTextEquation
4043from jsondoc .models .block .types .rich_text .text import Link , RichTextText
@@ -232,6 +235,30 @@ def override_reconcile_to_figure_placeholder_block(
232235 return ret
233236
234237
238+ def override_reconcile_to_caption_placeholder_block (
239+ parent : CaptionPlaceholderBlock , children : List [CHILDREN_TYPE ]
240+ ):
241+ """
242+ Given a caption placeholder block and a list of children,
243+ this function will get the rich text from the children
244+ and set it as the rich text of the caption placeholder block
245+ Finally, it will return the caption placeholder block
246+ """
247+ final_rich_text = []
248+ for child in children :
249+ if isinstance (child , RichTextBase ):
250+ final_rich_text .append (child )
251+ elif isinstance (child , BlockBase ):
252+ final_rich_text .extend (get_rich_text_from_block (child ))
253+ else :
254+ pass
255+ # raise ValueError(f"Unsupported type: {type(child)}")
256+
257+ parent .rich_text = final_rich_text
258+
259+ return [parent ]
260+
261+
235262# Override append functions
236263# Maps pairs of (parent_block_type, child_block_type) to a function
237264# that appends the child block to the parent block
@@ -242,6 +269,7 @@ def override_reconcile_to_figure_placeholder_block(
242269
243270OVERRIDE_RECONCILE_FUNCTIONS = {
244271 FigurePlaceholderBlock : override_reconcile_to_figure_placeholder_block ,
272+ CaptionPlaceholderBlock : override_reconcile_to_caption_placeholder_block ,
245273}
246274
247275
0 commit comments