You are here

function Markdown_Parser::_doImages_reference_callback in Markdown 5

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

File

./markdown.php, line 832

Class

Markdown_Parser

Code

function _doImages_reference_callback($matches) {
  $whole_match = $matches[1];
  $alt_text = $matches[2];
  $link_id = strtolower($matches[3]);
  if ($link_id == "") {
    $link_id = strtolower($alt_text);

    # for shortcut links like ![this][].
  }
  $alt_text = $this
    ->encodeAttribute($alt_text);
  if (isset($this->urls[$link_id])) {
    $url = $this
      ->encodeAttribute($this->urls[$link_id]);
    $result = "<img src=\"{$url}\" alt=\"{$alt_text}\"";
    if (isset($this->titles[$link_id])) {
      $title = $this->titles[$link_id];
      $title = $this
        ->encodeAttribute($title);
      $result .= " title=\"{$title}\"";
    }
    $result .= $this->empty_element_suffix;
    $result = $this
      ->hashPart($result);
  }
  else {

    # If there's no such link ID, leave intact:
    $result = $whole_match;
  }
  return $result;
}