Skip to content

Commit

Permalink
Improved parsing of emphasis around punctuation
Browse files Browse the repository at this point in the history
  • Loading branch information
colinodell committed Jan 2, 2015
1 parent 1d9dd60 commit f3566b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Inline/Parser/EmphasisParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use League\CommonMark\Delimiter\Delimiter;
use League\CommonMark\InlineParserContext;
use League\CommonMark\Inline\Element\Text;
use League\CommonMark\Util\RegexHelper;

class EmphasisParser extends AbstractInlineParser
{
Expand Down Expand Up @@ -55,8 +56,16 @@ public function parse(ContextInterface $context, InlineParserContext $inlineCont

$charAfter = $cursor->getCharacter() ?: "\n";

$canOpen = $numDelims > 0 && !preg_match('/\s/', $charAfter);
$canClose = $numDelims > 0 && !preg_match('/\s/', $charBefore);
$canOpen = $numDelims > 0 && !preg_match('/\pZ|\s/u', $charAfter) &&
!(preg_match(RegexHelper::REGEX_PUNCTUATION, $charAfter) &&
!preg_match('/\pZ|\s/u', $charBefore) &&
!(preg_match(RegexHelper::REGEX_PUNCTUATION, $charBefore)));

$canClose = $numDelims > 0 && !preg_match('/\pZ|\s/u', $charBefore) &&
!(preg_match(RegexHelper::REGEX_PUNCTUATION, $charBefore) &&
!preg_match('/\pZ|\s/u', $charAfter) &&
!(preg_match(RegexHelper::REGEX_PUNCTUATION, $charAfter)));

if ($character === '_') {
$canOpen = $canOpen && !preg_match('/[a-z0-9]/i', $charBefore);
$canClose = $canClose && !preg_match('/[a-z0-9]/i', $charAfter);
Expand Down
1 change: 1 addition & 0 deletions src/Util/RegexHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class RegexHelper

const REGEX_ESCAPABLE = '[!"#$%&\'()*+,.\/:;<=>?@[\\\\\]^_`{|}~-]';
const REGEX_ENTITY = '/&(?:#x[a-f0-9]{1,8}|#[0-9]{1,8}|[a-z][a-z0-9]{1,31});/i';
const REGEX_PUNCTUATION = '/^[\x{2000}-\x{206F}\x{2E00}-\x{2E7F}\\\\\'!"#\$%&\(\)\*\+,\-\.\\/:;<=>\?@\[\]\^_`\{\|\}~]/u';

protected $regex = array();

Expand Down

0 comments on commit f3566b1

Please sign in to comment.