Skip to content

Commit

Permalink
Add documentation to hashtag regex
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymcp committed Oct 25, 2018
1 parent d814746 commit e1052e2
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions classes/class-wpcom-liveblog-entry-extend-feature-hashtags.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,31 @@ public function load() {
// the generated hashtag class.
$this->class_prefix = apply_filters( 'liveblog_hashtag_class', $this->class_prefix );

// Set a better regex for hashtags to allow for hex values in content.
$this->set_regex( '~(?:(?<!\S)|>?)(?:(?<!&|&amp;))((?:' . implode( '|', $this->get_prefixes() ) . ')([0-9_\-\p{L}]*))~um' );
$prefixes = implode( '|', $this->get_prefixes() );

// Set a better regex for hashtags to allow for hex values in content -- see https://regex101.com/r/CLWsCo/
// phpcs:disable Squiz.Strings.ConcatenationSpacing.PaddingFound -- ignore indentation
$this->set_regex(
'~'
. '(?:'
. '(?<!\S)' // any visible character
. '|'
. '>?' // possible right angle bracket(s)
. ')'
. '(?:'
. '(?<!'
. '&' // literal ampersand
. '|'
. '&amp;' // encoded ampersand
. ')'
. ')'
. '('
. "(?:{$prefixes})" // hashtag prefixes
. '([0-9_\-\p{L}]*)' // 1: numerals, underscores, dashes, and any letter in any language
. ')'
. '~um'
);
// phpcs:enable

// This is the regex used to revert the
// generated hashtag html back to the
Expand Down

0 comments on commit e1052e2

Please sign in to comment.