@@ -2218,67 +2218,68 @@ def remove(self, *, title=None, tags=None, remove_all=False):
2218
2218
]
2219
2219
2220
2220
return remove_idx
2221
+
2221
2222
@fill_doc
2222
2223
def _add_or_replace (self , * , title , section , tags , html_partial , replace = False ):
2223
2224
"""Append HTML content report, or replace it if it already exists.
2224
2225
2225
2226
Parameters
2226
- ----------
2227
- title : str
2228
- The title entry.
2229
- %(section_report)s
2230
- tags : tuple of str
2231
- The tags associated with the added element.
2232
- html_partial : callable
2233
- Callable that renders a HTML string, called as::
2234
- html_partial(id_=...)
2235
- replace : bool
2236
- Whether to replace existing content if the title and section match.
2237
- If an object is replaced, its dom_id is preserved.
2238
- """
2239
- assert callable (html_partial ), type (html_partial )
2240
-
2241
- # Temporarily set HTML and dom_id to dummy values
2242
- new_content = _ContentElement (
2243
- name = title , section = section , dom_id = "" , tags = tags , html = ""
2244
- )
2245
-
2246
- append = True
2247
- if replace :
2248
- matches = [
2249
- ii
2250
- for ii , element in enumerate (self ._content )
2251
- if (element .name , element .section ) == (title , section )
2252
- ]
2253
- if matches :
2254
- dom_id = self ._content [matches [- 1 ]].dom_id
2255
- self ._content [matches [- 1 ]] = new_content
2256
- append = False
2257
- if append :
2258
- dom_id = self ._get_dom_id (section = section , title = title )
2259
- self ._content .append (new_content )
2260
- new_content .dom_id = dom_id
2261
- new_content .html = html_partial (id_ = dom_id )
2262
- assert isinstance (new_content .html , str ), type (new_content .html )
2263
-
2264
- def _add_code (self , * , code , title , language , section , tags , replace ):
2265
- if isinstance (code , Path ):
2266
- code = Path (code ).read_text ()
2267
- html_partial = partial (
2268
- _html_code_element ,
2269
- tags = tags ,
2270
- title = title ,
2271
- code = code ,
2272
- language = language ,
2273
- )
2274
- self ._add_or_replace (
2275
- title = title ,
2276
- section = section ,
2277
- tags = tags ,
2278
- html_partial = html_partial ,
2279
- replace = replace ,
2227
+ ----------
2228
+ title : str
2229
+ The title entry.
2230
+ %(section_report)s
2231
+ tags : tuple of str
2232
+ The tags associated with the added element.
2233
+ html_partial : callable
2234
+ Callable that renders a HTML string, called as::
2235
+ html_partial(id_=...)
2236
+ replace : bool
2237
+ Whether to replace existing content if the title and section match.
2238
+ If an object is replaced, its dom_id is preserved.
2239
+ """
2240
+ assert callable (html_partial ), type (html_partial )
2241
+
2242
+ # Temporarily set HTML and dom_id to dummy values
2243
+ new_content = _ContentElement (
2244
+ name = title , section = section , dom_id = "" , tags = tags , html = ""
2245
+ )
2246
+
2247
+ append = True
2248
+ if replace :
2249
+ matches = [
2250
+ ii
2251
+ for ii , element in enumerate (self ._content )
2252
+ if (element .name , element .section ) == (title , section )
2253
+ ]
2254
+ if matches :
2255
+ dom_id = self ._content [matches [- 1 ]].dom_id
2256
+ self ._content [matches [- 1 ]] = new_content
2257
+ append = False
2258
+ if append :
2259
+ dom_id = self ._get_dom_id (section = section , title = title )
2260
+ self ._content .append (new_content )
2261
+ new_content .dom_id = dom_id
2262
+ new_content .html = html_partial (id_ = dom_id )
2263
+ assert isinstance (new_content .html , str ), type (new_content .html )
2264
+
2265
+ def _add_code (self , * , code , title , language , section , tags , replace ):
2266
+ if isinstance (code , Path ):
2267
+ code = Path (code ).read_text ()
2268
+ html_partial = partial (
2269
+ _html_code_element ,
2270
+ tags = tags ,
2271
+ title = title ,
2272
+ code = code ,
2273
+ language = language ,
2280
2274
)
2281
-
2275
+ self ._add_or_replace (
2276
+ title = title ,
2277
+ section = section ,
2278
+ tags = tags ,
2279
+ html_partial = html_partial ,
2280
+ replace = replace ,
2281
+ )
2282
+
2282
2283
@fill_doc
2283
2284
def add_code (
2284
2285
self ,
0 commit comments