Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The regular expression is /<h([1-6])>(.*?)<\/h[1-6]>/
. This is extremely specific to heading tags that use a lower case "h" and have no attributes. Furthermore, the substitution callback has no way to deal with existing attributes even if the regex could deal with it.
There are two paths forward:
- Improve this Regex and the substitution callback.
- Use DOM manipulation.
Regex Improvement
Case insensitive, ungreedily match on anything within the first heading tag as long as there's at least one space after the number.
DOM Manipulation
Check out drupal_xml_parser_create() and format_xml_elements() as potential starting position.
Comments
Comment #1
Grayside CreditAttribution: Grayside commentedhttp://drupalcode.org/sandbox/grayside/1876908.git/commit/8cb92e1
#1877306: Not friendly to mobile or keyboard-only navigation moved all the necessary HTML additions to new tags nested inside the header element itself. As a result, some tweaking to the regular expression is a light-weight and sufficient-for-now solution.
Comment #2
Grayside CreditAttribution: Grayside commentedhttp://drupalcode.org/sandbox/grayside/1876908.git/commit/0e39619
Small tweak.
Comment #3.0
(not verified) CreditAttribution: commentedAdd notes about next steps for fix.