@@ -27,11 +27,11 @@ def is_inside_four_backticks(markdown: str, start_pos: int) -> bool:
2727
2828
2929def find_marimo_code_fences (markdown : str ) -> list [re .Match [str ]]:
30- matches : list [ Any ] = []
31- for match in CODE_FENCE_REGEX . finditer ( markdown ):
32- if not is_inside_four_backticks ( markdown , match . start ()):
33- matches . append ( match )
34- return matches
30+ return [
31+ match
32+ for match in CODE_FENCE_REGEX . finditer ( markdown )
33+ if not is_inside_four_backticks ( markdown , match . start () )
34+ ]
3535
3636
3737def collect_marimo_code (markdown : str ) -> tuple [list [str ], list [re .Match [str ]]]:
@@ -107,11 +107,14 @@ def on_page_markdown(
107107 if page .abs_url is None :
108108 return markdown
109109
110+ code_blocks , matches = collect_marimo_code (markdown )
111+ if not matches :
112+ return markdown
113+
110114 generator = marimo .MarimoIslandGenerator ()
111115 replacements : list [str ] = []
112116 self .replacements [page .abs_url ] = replacements
113117 outputs : list [Any ] = []
114- code_blocks , matches = collect_marimo_code (markdown )
115118
116119 for code in code_blocks :
117120 outputs .append (generator .add_code (code ))
@@ -207,8 +210,8 @@ def on_post_page(self, output: str, /, *, page: Page, config: MkDocsConfig) -> s
207210 # Add the extra header to the output
208211 output = output .replace ("</head>" , f"{ header } \n </head>" )
209212
210- replacesments : list [str ] = self .replacements .get (page .abs_url , [])
211- for idx , replacement in enumerate (replacesments ):
213+ replacements : list [str ] = self .replacements .get (page .abs_url , [])
214+ for idx , replacement in enumerate (replacements ):
212215 output = output .replace (f"<marimo-internal-island idx='{ idx } '/>" , replacement , 1 )
213216 return output
214217
0 commit comments