Skip to content

Commit

Permalink
Fix regex compatibility for PHP < 7.3 (#3)
Browse files Browse the repository at this point in the history
* Fix regex compatibility for PHP < 7.3
* Bump version
  • Loading branch information
Nathan Parsons authored May 31, 2020
1 parent ac7fe10 commit ec5d7df
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.1.7
## 2020-05-31

1. [](#bugfix)
* Fix regex compatibility issue with PHP < 7.3.

# v0.1.6
## 2020-05-23

Expand Down
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Embed Font Awesome
version: 0.1.6
version: 0.1.7
description: "Embed Font Awesome icons into your HTML output as inline SVGs."
icon: flag
author:
Expand Down
8 changes: 7 additions & 1 deletion embed-fontawesome.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,14 @@ public function onOutputGenerated()
private function embedIcons($content)
{
// Get all matches for icons
if (version_compare($ver = PHP_VERSION, $req = "7.3.0", '<')) {
$iconRegex = '/<i (?<preClass>[a-zA-Z0-9 _="\'-]*)(?<= )class=(?<quot>"|\')(?<classPreFA>[a-zA-Z0-9 :_-]*)(?<=["\' ])(?<weightFA>(?:fa[srlbd]?)|(?:icon)) (?<classMidFA>((?!((fa)|(icon)))[a-zA-Z0-9 _-]*)*)(?<= )(?<iconType>fa|icon)-(?<iconFA>[a-z0-9-]+)(?<classPostFA>[a-zA-Z0-9 :_-]*)\k<quot>(?<postClass>[a-zA-Z0-9 _="\'-]*)><\/i>/';
} else {
$iconRegex = '/<i (?<preClass>[a-zA-Z0-9 _="\'-]*)(?<= )class=(?<quot>"|\')(?<classPreFA>[a-zA-Z0-9 :_-]*)(?<=( |\k<quot>))(?<weightFA>(?:fa[srlbd]?)|(?:icon)) (?<classMidFA>((?!((fa)|(icon)))[a-zA-Z0-9 _-]*)*)(?<= )(?<iconType>fa|icon)-(?<iconFA>[a-z0-9-]+)(?<classPostFA>[a-zA-Z0-9 :_-]*)\k<quot>(?<postClass>[a-zA-Z0-9 _="\'-]*)><\/i>/';
}

if (preg_match_all(
'/<i (?<preClass>[a-zA-Z0-9 _="\'-]*)(?<= )class=(?<quot>"|\')(?<classPreFA>[a-zA-Z0-9 :_-]*)(?<=( |\k<quot>))(?<weightFA>(?:fa[srlbd]?)|(?:icon)) (?<classMidFA>((?!((fa)|(icon)))[a-zA-Z0-9 _-]*)*)(?<= )(?<iconType>fa|icon)-(?<iconFA>[a-z0-9-]+)(?<classPostFA>[a-zA-Z0-9 :_-]*)\k<quot>(?<postClass>[a-zA-Z0-9 _="\'-]*)><\/i>/',
$iconRegex,
$content,
$matchesRaw
)) {
Expand Down

0 comments on commit ec5d7df

Please sign in to comment.