code: def html_visit_pdvega_plot(self, node):
      # Execute the setup code, saving the global & local state
  
      namespace = {}
      if node["setupcode"]:
          exec(node["setupcode"], namespace)
  
      # Execute the plot code in this context, evaluating the last line
      try:
          output = exec_then_eval(node["code"], namespace)
      except Exception as e:
          warnings.warn(
              "pdvega-plot: {0}:{1} Code Execution failed:"
              "{2}: {3}".format(
                  node["rst_source"],
                  node["rst_lineno"],
                  e.__class__.__name__,
                  str(e),
              )
          )
          raise nodes.SkipNode
  
      if isinstance(output, Axes):
          # Last line should be a Vega-Lite chart; get the spec:
          spec = output.spec
  
          # Create the vega-lite spec to embed
          # embed_spec = json.dumps({'mode': 'vega-lite',
          #                          'actions': node['links'],
          #                          'spec': spec})
  
          # Previously we did this, but after github migrated to https only
          # it started causing issues for some http clients such as localhost.
          # embed_spec = embed_spec.replace('http://', '//')
          # embed_spec = embed_spec.replace('https://', '//')
  
          # Write embed_spec to a *.vl.json file
          dest_dir = os.path.join(self.builder.outdir, node["relpath"])
          if not os.path.exists(dest_dir):
              os.makedirs(dest_dir)
          filename = "{0}.vl.json".format(node["div_id"])
          # TODO: let this url be configured
          url = "{0}{1}.vl.json".format(
              node["url_root"], node["div_id"]
          )
          dest_path = os.path.join(dest_dir, filename)
          with open(dest_path, "w") as f:
              json.dump(spec, f)
  
          # Pass relevant info into the template and append to the output
          html = VGL_TEMPLATE.render(div_id=node["div_id"], url=url)
          self.body.append(html)
      else:
          warnings.warn(
              "pdvega-plot: {0}:{1} Malformed block. Last line of "
              "code block should define a valid pdvega object."
              "".format(node["rst_source"], node["rst_lineno"])
          )
      raise nodes.SkipNode
  
imports: import os
  import json
  import warnings
  import jinja2
  from docutils import nodes
  from docutils.parsers.rst import Directive
  from docutils.parsers.rst.directives import flag, unchanged
  from sphinx.locale import _
  from pdvega import Axes
  from .utils import exec_then_eval
label_desc: Use image node_id 3 for calling a global function with example usage: html_visit_pdvega_plot(node) without return types