You are here

function MarkdownExtra_Parser::_appendFootnotes_callback in Markdown 5

Same name and namespace in other branches
  1. 6 markdown.php \MarkdownExtra_Parser::_appendFootnotes_callback()

File

./markdown.php, line 2710

Class

MarkdownExtra_Parser

Code

function _appendFootnotes_callback($matches) {
  $node_id = $this->fn_id_prefix . $matches[1];

  # Create footnote marker only if it has a corresponding footnote *and*

  # the footnote hasn't been used by another marker.
  if (isset($this->footnotes[$node_id])) {

    # Transfert footnote content to the ordered list.
    $this->footnotes_ordered[$node_id] = $this->footnotes[$node_id];
    unset($this->footnotes[$node_id]);
    $num = $this->footnote_counter++;
    $attr = " rel=\"footnote\"";
    if ($this->fn_link_class != "") {
      $class = $this->fn_link_class;
      $class = $this
        ->encodeAttribute($class);
      $attr .= " class=\"{$class}\"";
    }
    if ($this->fn_link_title != "") {
      $title = $this->fn_link_title;
      $title = $this
        ->encodeAttribute($title);
      $attr .= " title=\"{$title}\"";
    }
    $attr = str_replace("%%", $num, $attr);
    $node_id = $this
      ->encodeAttribute($node_id);
    return "<sup id=\"fnref:{$node_id}\">" . "<a href=\"#fn:{$node_id}\"{$attr}>{$num}</a>" . "</sup>";
  }
  return "[^" . $matches[1] . "]";
}