Skip to content

Commit

Permalink
FancyPants: added =/= as an alias for the not-equal sign
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Dec 9, 2016
1 parent a9a2f2f commit e2910c4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/Plugins/FancyPants/Synopsis.md
Expand Up @@ -55,8 +55,8 @@ echo $html;
</tr>
<tr>
<td>MathSymbols</td>
<td>a != b. 2" x 4" planks.</td>
<td>a ≠ b. 2″ × 4″ planks.</td>
<td>2" x 4". a != b. apples =/= oranges.</td>
<td>2″ × 4″. a ≠ b. apples ≠ oranges.</td>
</tr>
<tr>
<td>Punctuation</td>
Expand Down
8 changes: 5 additions & 3 deletions src/Plugins/FancyPants/Parser.js
Expand Up @@ -104,18 +104,20 @@ function parseGuillemets()

/**
* Parse the not equal sign
*
* Supports != and =/=
*/
function parseNotEqualSign()
{
if (text.indexOf('!=') < 0)
if (text.indexOf('!=') < 0 && text.indexOf('=/=') < 0)
{
return;
}

var m, regexp = /\b !=(?= \b)/g;
var m, regexp = /\b (?:!|=\/)=(?= \b)/g;
while (m = regexp.exec(text))
{
addTag(+m['index'] + 1, 2, "\u2260");
addTag(+m['index'] + 1, m[0].length - 1, "\u2260");
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/Plugins/FancyPants/Parser.php
Expand Up @@ -151,20 +151,22 @@ protected function parseGuillemets()
/**
* Parse the not equal sign
*
* Supports != and =/=
*
* @return void
*/
protected function parseNotEqualSign()
{
if (strpos($this->text, '!=') === false)
if (strpos($this->text, '!=') === false && strpos($this->text, '=/=') === false)
{
return;
}

$regexp = '/\\b !=(?= \\b)/';
$regexp = '/\\b (?:!|=\\/)=(?= \\b)/';
preg_match_all($regexp, $this->text, $matches, PREG_OFFSET_CAPTURE);
foreach ($matches[0] as $m)
{
$this->addTag($m[1] + 1, 2, "\xE2\x89\xA0");
$this->addTag($m[1] + 1, strlen($m[0]) - 1, "\xE2\x89\xA0");
}
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Plugins/FancyPants/ParserTest.php
Expand Up @@ -199,6 +199,10 @@ function ($configurator)
'apples != oranges',
'<r>apples <FP char="≠">!=</FP> oranges</r>'
],
[
'apples =/= oranges',
'<r>apples <FP char="≠">=/=</FP> oranges</r>'
],
[
'apples != oranges',
'<t>apples != oranges</t>',
Expand Down

0 comments on commit e2910c4

Please sign in to comment.