Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Michelf/MarkdownExtra.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ protected function teardown() {
*/
protected string $id_class_attr_nocatch_re = '\{(?>[ ]*[#.a-z][-_:a-zA-Z0-9=]+){1,}[ ]*\}';

/**
* Expression to use when determining whether to make a tag with an id focusable
* @var string
*/
protected $id_focusable_tags_re = '/h[1-6]/i';

/**
* Parse attributes caught by the $this->id_class_attr_catch_re expression
* and return the HTML-formatted list of attributes.
Expand Down Expand Up @@ -254,6 +260,10 @@ protected function doExtraAttributes($tag_name, $attr, $defaultIdValue = null, $
$attr_str = "";
if (!empty($id)) {
$attr_str .= ' id="'.$this->encodeAttribute($id) .'"';
// make specified tags focusable for assistive technologies anchor targets
if ($this->id_focusable_tags_re && preg_match($this->id_focusable_tags_re, $tag_name)) {
$attr_str .= ' tabindex="-1"';
}
}
if (!empty($classes)) {
$attr_str .= ' class="'. implode(" ", $classes) . '"';
Expand Down