@@ -1455,6 +1455,53 @@ def add_images_to_section(self, fnames, captions, scale=None,
14551455 self .add_images (images = fnames , titles = captions , captions = comments ,
14561456 tags = tags )
14571457
1458+ @fill_doc
1459+ def add_htmls (self , htmls , titles , * , tags = ('custom-html' ,)):
1460+ """Add HTML content to the report.
1461+
1462+ Parameters
1463+ ----------
1464+ htmls : str | collection of str
1465+ The HTML content to add.
1466+ titles : str | collection of str
1467+ Title(s) corresponding to ``htmls``.
1468+ %(report_tags)s
1469+ """
1470+ if isinstance (htmls , str ):
1471+ htmls = (htmls ,)
1472+ else :
1473+ htmls = tuple (htmls )
1474+
1475+ if isinstance (titles , str ):
1476+ titles = (titles ,)
1477+ else :
1478+ titles = tuple (titles )
1479+
1480+ if len (htmls ) != len (titles ):
1481+ raise ValueError (
1482+ f'Number of htmls ({ len (htmls )} ) must equal number of '
1483+ f'titles ({ len (titles )} )'
1484+ )
1485+
1486+ tags = tuple (tags )
1487+ for tag in tags :
1488+ if tag not in self .tags :
1489+ self .tags .append (tag )
1490+
1491+ for html , title in zip (htmls , titles ):
1492+ dom_id = self ._get_id ()
1493+ html_element = _html_element (
1494+ id = dom_id , html = html , title = title , tags = tags ,
1495+ div_klass = 'custom-html'
1496+ )
1497+ self ._add_or_replace (
1498+ dom_id = dom_id ,
1499+ toc_entry_name = title ,
1500+ tags = tags ,
1501+ html = html_element
1502+ )
1503+
1504+ # @deprecated(extra='Use `Report.add_htmls` instead')
14581505 def add_htmls_to_section (self , htmls , captions , section = 'custom' ,
14591506 replace = False ):
14601507 """Append htmls to the report.
@@ -1476,27 +1523,10 @@ def add_htmls_to_section(self, htmls, captions, section='custom',
14761523 -----
14771524 .. versionadded:: 0.9.0
14781525 """
1479- if section not in self .tags :
1480- self .tags .append (section )
1481- self ._sectionvars [section ] = section
1526+ # htmls, captions, _ = self._validate_input(htmls, captions, section)
14821527
1483- htmls , captions , _ = self ._validate_input (htmls , captions , section )
1484- for html , caption in zip (htmls , captions ):
1485- caption = 'custom plot' if caption == '' else caption
1486- sectionvar = self ._sectionvars [section ]
1487- global_id = self ._get_id ()
1488- div_klass = self ._sectionvars [section ]
1489-
1490- self ._add_or_replace (
1491- content_id = f'{ caption } -#-{ sectionvar } -#-custom' ,
1492- sectionlabel = sectionvar ,
1493- dom_id = global_id ,
1494- html = html_template .substitute (
1495- div_klass = div_klass , id = global_id ,
1496- caption = caption , html = html
1497- ),
1498- replace = replace
1499- )
1528+ tags = _clean_tags (section )
1529+ self .add_htmls (htmls = htmls , titles = captions , tags = tags )
15001530
15011531 # @deprecated(extra='Use `Report.add_bem` instead')
15021532 @verbose
0 commit comments