5
5
from bs4 import BeautifulSoup , Comment , Doctype , NavigableString
6
6
from pydantic import BaseModel
7
7
8
- from jsondoc .convert .utils import (
8
+ from jsondoc .convert .placeholder import (
9
9
BreakElementPlaceholderBlock ,
10
10
CaptionPlaceholderBlock ,
11
11
CellPlaceholderBlock ,
12
12
FigurePlaceholderBlock ,
13
+ )
14
+ from jsondoc .convert .utils import (
13
15
append_rich_text_to_block ,
14
16
append_to_parent_block ,
15
17
append_to_rich_text ,
35
37
)
36
38
from jsondoc .models .block .base import BlockBase
37
39
from jsondoc .models .block .types .image import ImageBlock
40
+ from jsondoc .models .block .types .paragraph import ParagraphBlock
38
41
from jsondoc .models .block .types .rich_text .base import RichTextBase
39
42
from jsondoc .models .block .types .rich_text .equation import RichTextEquation
40
43
from jsondoc .models .block .types .rich_text .text import Link , RichTextText
@@ -232,6 +235,30 @@ def override_reconcile_to_figure_placeholder_block(
232
235
return ret
233
236
234
237
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
+
235
262
# Override append functions
236
263
# Maps pairs of (parent_block_type, child_block_type) to a function
237
264
# that appends the child block to the parent block
@@ -242,6 +269,7 @@ def override_reconcile_to_figure_placeholder_block(
242
269
243
270
OVERRIDE_RECONCILE_FUNCTIONS = {
244
271
FigurePlaceholderBlock : override_reconcile_to_figure_placeholder_block ,
272
+ CaptionPlaceholderBlock : override_reconcile_to_caption_placeholder_block ,
245
273
}
246
274
247
275
0 commit comments