@@ -12,14 +12,51 @@ public static function render(BlockInterface ...$blocks): string
1212 {
1313 $ markdown = "" ;
1414 foreach ($ blocks as $ block ) {
15- $ markdown = $ markdown . self ::renderBlock ($ block ) . "\n" ;
15+ $ markdown = $ markdown . self ::renderBlock ($ block, 0 ) . "\n" ;
1616 }
1717
1818 return $ markdown ;
1919 }
2020
21- public static function renderBlock (BlockInterface $ block , int $ depth = 0 ): string
21+ /**
22+ * Render blocks with custom renderers.
23+ *
24+ * @param array<value-of<BlockType>, BlockRendererInterface> $overrides
25+ * @param BlockInterface ...$blocks
26+ *
27+ * @return string
28+ */
29+ public static function renderWithOverrides (
30+ array $ overrides ,
31+ BlockInterface ...$ blocks ,
32+ ): string {
33+ $ markdown = "" ;
34+ foreach ($ blocks as $ block ) {
35+ $ markdown = $ markdown . self ::renderBlock ($ block , 0 , $ overrides ) . "\n" ;
36+ }
37+
38+ return $ markdown ;
39+ }
40+
41+ /**
42+ * Undocumented function
43+ *
44+ * @param BlockInterface $block
45+ * @param int $depth
46+ * @param array<value-of<BlockType>, BlockRendererInterface> $overrides
47+ *
48+ * @return string
49+ */
50+ public static function renderBlock (
51+ BlockInterface $ block ,
52+ int $ depth = 0 ,
53+ array $ overrides = []): string
2254 {
55+ if (array_key_exists ($ block ->metadata ()->type ->value , $ overrides )) {
56+ $ renderer = $ overrides [$ block ->metadata ()->type ->value ];
57+ return $ renderer ::render ($ block , $ depth );
58+ }
59+
2360 return match ($ block ->metadata ()->type ) {
2461 BlockType::Bookmark => Markdown \BookmarkRenderer::render ($ block , $ depth ),
2562 BlockType::Breadcrumb => Markdown \BreadcrumbRenderer::render ($ block , $ depth ),
0 commit comments