The current way of marking up highlighted keywords in the search snippet is to use <strong> element, however I would like to use <mark> (HTML5).

In D8 there is a lot of talk about shifting to HMTL5, while I am for this, I think we need to better support markup choices per se, so if you want to use HMTL4, XHTML or HTML5 you can, therefore we need to stop doing hard coded markup such as...

  $text = preg_replace('/' . $boundary . '(' . implode('|', $keys) . ')' . $boundary . '/iu', '<strong>\0</strong>', $text);

... and make all markup themeable, i.e. this should use theme_mark or similar.

Comments

jhodgdon’s picture

Sounds like a good idea for Drupal 8, thanks for the suggestion!

Jacine’s picture

Issue tags: +Front end

Agreed. This should run through theme_mark() which should be updated to use the <mark> element.

Jacine’s picture

Issue tags: -Front end

Created an issue for theme_mark(): #1311372: Use <mark> element for 'mark' theme hook.

andypost’s picture

Also related #493270: search_excerpt() doesn't work well with stemming
i think we need both preprocess and theme for excerpt

Jacine’s picture

Title: search_excerpt is not themeable » search_excerpt is not themeable and should use <mark> to highlight search results
Component: search.module » markup

Changing the component to markup. Hopefully it will get more visibility there.

JvE’s picture

theme_mark is not applicable here. It "Returns HTML for a marker for new or updated content.", it does not take input other than the type of mark (new/read/updated).

I'm thinking the whole search_excerpt() function should be a theme function.
With text, keywords, length (currently fixed at 256) and dots (leading, dividing and trailing) as possible inputs.

Otherwise maybe add a theme function:

/**
 * Returns HTML for a piece of text with keywords highlighted.
 * @param $variables
 *   An associative array containing:
 *   - text: Text containing keywords to highlight.
 *   - keys: An array of words to highlight.
 *   - boundary: A pattern that specifies word boundaries.
 */
function theme_search_highlight($variables) {
  $pattern = '/' . $variables['boundary'] . '(' . implode('|', $variables['keys']) . ')' . $variables['boundary'] . '/iu';
  return preg_replace($pattern, '\0', $variables['text']);
}
markcarver’s picture

mgifford’s picture

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.