diff --git a/Michelf/MarkdownExtra.php b/Michelf/MarkdownExtra.php index f814cde..ea571c3 100644 --- a/Michelf/MarkdownExtra.php +++ b/Michelf/MarkdownExtra.php @@ -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. @@ -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) . '"';