protected function MarkdownExtra::doExtraAttributes in Markdown 7
* Parse attributes caught by the $this->id_class_attr_catch_re expression * and return the HTML-formatted list of attributes. * * Currently supported attributes are .class and #id. * * In addition, this method also supports supplying a default Id value, * which will be used to populate the id attribute in case it was not * overridden. *
Parameters
string $tag_name: * @param string $attr * @param mixed $defaultIdValue * @param array $classes * @return string
6 calls to MarkdownExtra::doExtraAttributes()
- MarkdownExtra::_doAnchors_inline_callback in includes/
MarkdownExtra.php - * Callback for inline anchors *
- MarkdownExtra::_doFencedCodeBlocks_callback in includes/
MarkdownExtra.php - * Callback to process fenced code blocks *
- MarkdownExtra::_doHeaders_callback_atx in includes/
MarkdownExtra.php - * Callback for atx headers *
- MarkdownExtra::_doHeaders_callback_setext in includes/
MarkdownExtra.php - * Callback for setext headers *
- MarkdownExtra::_doImages_inline_callback in includes/
MarkdownExtra.php - * Callback for inline images *
File
- includes/
MarkdownExtra.php, line 198
Class
- MarkdownExtra
- Markdown Extra Parser Class
Namespace
MichelfCode
protected function doExtraAttributes($tag_name, $attr, $defaultIdValue = null, $classes = array()) {
if (empty($attr) && !$defaultIdValue && empty($classes)) {
return "";
}
// Split on components
preg_match_all('/[#.a-z][-_:a-zA-Z0-9=]+/', $attr, $matches);
$elements = $matches[0];
// Handle classes and IDs (only first ID taken into account)
$attributes = array();
$id = false;
foreach ($elements as $element) {
if ($element[0] == '.') {
$classes[] = substr($element, 1);
}
else {
if ($element[0] == '#') {
if ($id === false) {
$id = substr($element, 1);
}
}
else {
if (strpos($element, '=') > 0) {
$parts = explode('=', $element, 2);
$attributes[] = $parts[0] . '="' . $parts[1] . '"';
}
}
}
}
if (!$id) {
$id = $defaultIdValue;
}
// Compose attributes as string
$attr_str = "";
if (!empty($id)) {
$attr_str .= ' id="' . $this
->encodeAttribute($id) . '"';
}
if (!empty($classes)) {
$attr_str .= ' class="' . implode(" ", $classes) . '"';
}
if (!$this->no_markup && !empty($attributes)) {
$attr_str .= ' ' . implode(" ", $attributes);
}
return $attr_str;
}