diff --git a/Michelf/MarkdownExtra.php b/Michelf/MarkdownExtra.php index 123f2f8..9a4be84 100644 --- a/Michelf/MarkdownExtra.php +++ b/Michelf/MarkdownExtra.php @@ -46,6 +46,13 @@ class MarkdownExtra extends \Michelf\Markdown { */ public $fn_backlink_html = '↩︎'; + /** + * Optional aria-label attribute for footnote backlinks. Use '{ref}' and + * '{fn}' to refer to the reference number and footnote number respectively. + * @var string + */ + public $fn_backlink_label = ""; + /** * Class name for table cell alignment (%% replaced left/center/right) * For instance: 'go-%%' becomes 'go-left' or 'go-right' or 'go-center' @@ -1681,7 +1688,6 @@ class MarkdownExtra extends \Michelf\Markdown { $title = $this->fn_backlink_title; $title = $this->encodeAttribute($title); $attr .= " title=\"$title\""; - $attr .= " aria-label=\"$title\""; } $attr .= " role=\"doc-backlink\""; $backlink_text = $this->fn_backlink_html; @@ -1705,9 +1711,13 @@ class MarkdownExtra extends \Michelf\Markdown { $note_id = $this->encodeAttribute($note_id); // Prepare backlink, multiple backlinks if multiple references - $backlink = "$backlink_text"; + $label = !empty($this->fn_backlink_label) ? ' aria-label="'.$this->encodeAttribute(str_replace(array('{ref}', '{fn}'), array('1', $note_id), $this->fn_backlink_label)).'"' : ''; + $backlink = "$backlink_text"; for ($ref_num = 2; $ref_num <= $ref_count; ++$ref_num) { - $backlink .= " $backlink_text"; + if (!empty($this->fn_backlink_label)) { + $label = ' aria-label="'.$this->encodeAttribute(str_replace(array('{ref}', '{fn}'), array($ref_num, $note_id), $this->fn_backlink_label)).'"'; + } + $backlink .= " $backlink_text"; } // Add backlink to last paragraph; create new paragraph if needed. if (preg_match('{

$}', $footnote)) {