function MarkdownExtra_Parser::doExtraAttributes in Markdown 6
6 calls to MarkdownExtra_Parser::doExtraAttributes()
- MarkdownExtra_Parser::_doAnchors_inline_callback in ./
markdown.php - MarkdownExtra_Parser::_doFencedCodeBlocks_callback in ./
markdown.php - MarkdownExtra_Parser::_doHeaders_callback_atx in ./
markdown.php - MarkdownExtra_Parser::_doHeaders_callback_setext in ./
markdown.php - MarkdownExtra_Parser::_doImages_inline_callback in ./
markdown.php
File
- ./
markdown.php, line 1809
Class
Code
function doExtraAttributes($tag_name, $attr) {
#
# 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.
#
if (empty($attr)) {
return "";
}
# Split on components
preg_match_all('/[#.][-_:a-zA-Z0-9]+/', $attr, $matches);
$elements = $matches[0];
# handle classes and ids (only first id taken into account)
$classes = 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);
}
}
}
}
# compose attributes as string
$attr_str = "";
if (!empty($id)) {
$attr_str .= ' id="' . $id . '"';
}
if (!empty($classes)) {
$attr_str .= ' class="' . implode(" ", $classes) . '"';
}
return $attr_str;
}