docs: def format_as_html(explanation,  # type: Explanation
                     include_styles=True,  # type: bool
                     force_weights=True,  # type: bool
                     show=fields.ALL,
                     preserve_density=None,  # type: Optional[bool]
                     highlight_spaces=None,  # type: Optional[bool]
                     horizontal_layout=True,  # type: bool
                     show_feature_values=False  # type: bool
                     ):
      # type: (...) -> str
      """ Format explanation as html.
      Most styles are inline, but some are included separately in <style> tag,
      you can omit them by passing ``include_styles=False`` and call
      ``format_html_styles`` to render them separately (or just omit them).
      With ``force_weights=False``, weights will not be displayed in a table for
      predictions where it is possible to show feature weights highlighted
      in the document.
      If ``highlight_spaces`` is None (default), spaces will be highlighted in
      feature names only if there are any spaces at the start or at the end of the
      feature. Setting it to True forces space highlighting, and setting it to
      False turns it off.
      If ``horizontal_layout`` is True (default), multiclass classifier
      weights are laid out horizontally.
      If ``show_feature_values`` is True, feature values are shown if present.
      Default is False.
      """
      template = template_env.get_template('explain.html')
      if highlight_spaces is None:
          highlight_spaces = should_highlight_spaces(explanation)
      targets = explanation.targets or []
      if len(targets) == 1:
          horizontal_layout = False
      explaining_prediction = has_any_values_for_weights(explanation)
      show_feature_values = show_feature_values and explaining_prediction
  
      rendered_weighted_spans = render_targets_weighted_spans(
          targets, preserve_density)
      weighted_spans_others = [
          t.weighted_spans.other if t.weighted_spans else None for t in targets]
  
      return template.render(
          include_styles=include_styles,
          force_weights=force_weights,
          target_table_styles=
          'border-collapse: collapse; border: none; margin-top: 0em; table-layout: auto;',
          tr_styles='border: none;',
          # Weight (th and td)
          td1_styles='padding: 0 1em 0 0.5em; text-align: right; border: none;',
          # N more positive/negative
          tdm_styles='padding: 0 0.5em 0 0.5em; text-align: center; border: none; '
                     'white-space: nowrap;',
          # Feature (th and td)
          td2_styles='padding: 0 0.5em 0 0.5em; text-align: left; border: none;',
          # Value (th and td)
          td3_styles='padding: 0 0.5em 0 1em; text-align: right; border: none;',
          horizontal_layout_table_styles=
          'border-collapse: collapse; border: none; margin-bottom: 1.5em;',
          horizontal_layout_td_styles=
          'padding: 0px; border: 1px solid black; vertical-align: top;',
          horizontal_layout_header_styles=
          'padding: 0.5em; border: 1px solid black; text-align: center;',
          show=show,
          expl=explanation,
          hl_spaces=highlight_spaces,
          horizontal_layout=horizontal_layout,
          any_weighted_spans=any(t.weighted_spans for t in targets),
          feat_imp_weight_range=max_or_0(
              abs(fw.weight) for fw in explanation.feature_importances.importances)
          if explanation.feature_importances else 0,
          target_weight_range=max_or_0(
              get_weight_range(t.feature_weights) for t in targets),
          other_weight_range=max_or_0(
              get_weight_range(other)
              for other in weighted_spans_others if other),
          targets_with_weighted_spans=list(
              zip(targets, rendered_weighted_spans, weighted_spans_others)),
          show_feature_values=show_feature_values,
          weights_table_span=3 if show_feature_values else 2,
          explaining_prediction=explaining_prediction,
          weight_help=html_escape(WEIGHT_HELP),
          contribution_help=html_escape(CONTRIBUTION_HELP),
      )