| | 123 | |
| | 124 | #503 - The text of a heading is now becoming a link to this heading, allowing an easy way to copy link to clipboard. |
| | 125 | // For this, we take the textNode child of a heading, and if it is not enclosed in <a...></a>, we enclose it in |
| | 126 | // $opening_anchor and $closing_anchor. |
| | 127 | $opening_anchor = '<a class="heading" href="#'.$h_id.'">'; |
| | 128 | $closing_anchor = '</a>'; |
| | 129 | /** |
| | 130 | * Match "<a " when it isn't preceded by "</a>" |
| | 131 | */ |
| | 132 | define('PATTERN_OPEN_A_ALONE', '(?<!</a>|^)<a '); |
| | 133 | /** |
| | 134 | * Match the end of a string when the string doesn't end with </a> |
| | 135 | */ |
| | 136 | define('PATTERN_END_OF_STRING_ALONE', '(?<!</a>)$'); |
| | 137 | /** |
| | 138 | * Match "</a>" when it is not followed by an opening link markup (<a ) |
| | 139 | */ |
| | 140 | define('PATTERN_CLOSE_A_ALONE', '</a>(?!<a |$)'); |
| | 141 | /** |
| | 142 | * Match the start of a string when the string doesn't start with "<a " |
| | 143 | */ |
| | 144 | define('PATTERN_START_OF_STRING_ALONE', '^(?!<a )'); |
| | 145 | $h_heading = preg_replace('@('.PATTERN_OPEN_A_ALONE. '|'.PATTERN_END_OF_STRING_ALONE. ')@', $closing_anchor.'\\0', $h_heading); |
| | 146 | $h_heading = preg_replace('@('.PATTERN_CLOSE_A_ALONE.'|'.PATTERN_START_OF_STRING_ALONE.')@', '\\0'.$opening_anchor, $h_heading); |