docs: def _process_figure(value, fmt):
      """Processes the figure.  Returns a dict containing figure properties."""
  
      # pylint: disable=global-statement
      global Nreferences             # Global references counter
      global has_unnumbered_figures  # Flags unnumbered figures were found
      global cursec                  # Current section
  
      # Parse the image
      attrs, caption = value[0]['c'][:2]
  
      # Initialize the return value
      fig = {'is_unnumbered': False,
             'is_unreferenceable': False,
             'is_tagged': False,
             'attrs': attrs}
  
      # Bail out if the label does not conform
      if not LABEL_PATTERN.match(attrs[0]):
          has_unnumbered_figures = True
          fig['is_unnumbered'] = True
          fig['is_unreferenceable'] = True
          return fig
  
      # Process unreferenceable figures
      if attrs[0] == 'fig:': # Make up a unique description
          attrs[0] = attrs[0] + str(uuid.uuid4())
          fig['is_unreferenceable'] = True
          unreferenceable.append(attrs[0])
  
      # For html, hard-code in the section numbers as tags
      kvs = PandocAttributes(attrs, 'pandoc').kvs
      if numbersections and fmt in ['html', 'html5'] and 'tag' not in kvs:
          if kvs['secno'] != cursec:
              cursec = kvs['secno']
              Nreferences = 1
          kvs['tag'] = cursec + '.' + str(Nreferences)
          Nreferences += 1
  
      # Save to the global references tracker
      fig['is_tagged'] = 'tag' in kvs
      if fig['is_tagged']:
          # Remove any surrounding quotes
          if kvs['tag'][0] == '"' and kvs['tag'][-1] == '"':
              kvs['tag'] = kvs['tag'].strip('"')
          elif kvs['tag'][0] == "'" and kvs['tag'][-1] == "'":
              kvs['tag'] = kvs['tag'].strip("'")
          references[attrs[0]] = kvs['tag']
      else:
          Nreferences += 1
          references[attrs[0]] = Nreferences
  
      # Adjust caption depending on the output format
      if fmt in ['latex', 'beamer']:  # Append a \label if this is referenceable
          if not fig['is_unreferenceable']:
              value[0]['c'][1] += [RawInline('tex', r'\label{%s}'%attrs[0])]
      else:  # Hard-code in the caption name and number/tag
          if isinstance(references[attrs[0]], int):  # Numbered reference
              value[0]['c'][1] = [RawInline('html', r'<span>'),
                                  Str(captionname), Space(),
                                  Str('%d:'%references[attrs[0]]),
                                  RawInline('html', r'</span>')] \
                  if fmt in ['html', 'html5'] else \
                  [Str(captionname), Space(), Str('%d:'%references[attrs[0]])]
              value[0]['c'][1] += [Space()] + list(caption)
          else:  # Tagged reference
              assert isinstance(references[attrs[0]], STRTYPES)
              text = references[attrs[0]]
              if text.startswith('$') and text.endswith('$'):  # Math
                  math = text.replace(' ', r'\ ')[1:-1]
                  els = [Math({"t":"InlineMath", "c":[]}, math), Str(':')]
              else:  # Text
                  els = [Str(text+':')]
              value[0]['c'][1] = \
                  [RawInline('html', r'<span>'), Str(captionname), Space()] + \
                  els + [RawInline('html', r'</span>')] \
                  if fmt in ['html', 'html5'] else \
                  [Str(captionname), Space()] + els
              value[0]['c'][1] += [Space()] + list(caption)
  
      return fig