code: 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
              if t.feature_weights is not None
          ),
          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),
      )
  
imports: from __future__ import absolute_import
  from itertools import groupby
  from typing import List, Optional, Tuple
  import numpy
  from jinja2 import Environment, PackageLoader
  from eli5 import _graphviz
  from eli5.base import Explanation, TargetExplanation, FeatureWeights, FeatureWeight
  from eli5.utils import max_or_0
  from .utils import format_signed, format_value, format_weight, has_any_values_for_weights, replace_spaces, should_highlight_spaces
  from .None import fields
  from .features import FormattedFeatureName
  from .trees import tree2text
  from .text_helpers import prepare_weighted_spans, PreparedWeightedSpans
label_desc: Use image node_id 1 for calling a global function with example usage: format_as_html(explanation, include_styles, force_weights, show, preserve_density, highlight_spaces, horizontal_layout, show_feature_values) and returns: template