From 060b9e559aeff455b52427d7c518334fe7891e11 Mon Sep 17 00:00:00 2001 From: Sunny Walker Date: Fri, 5 Jan 2024 13:31:46 -1000 Subject: [PATCH] make specific tags focusable for AT link targets should be focusable for best assistive technologies support by adding tabindex="-1" (which also keeps them out of the tab indexing). --- Michelf/MarkdownExtra.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Michelf/MarkdownExtra.php b/Michelf/MarkdownExtra.php index 9ac41e7a..afff60bb 100644 --- a/Michelf/MarkdownExtra.php +++ b/Michelf/MarkdownExtra.php @@ -228,6 +228,12 @@ protected function teardown() { */ protected $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. @@ -274,6 +280,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) . '"';