Skip to content

Commit

Permalink
Merge branch '1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
kzykhys committed Jan 23, 2014
2 parents 8b606b6 + 4c5287d commit 86053df
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
13 changes: 3 additions & 10 deletions src/Ciconia/Ciconia.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
class Ciconia
{

/**
* Version number
*/
const VERSION = '1.1.x-dev';
const VERSION = '1.0.1';

/**
* @var RendererInterface
Expand All @@ -40,8 +37,6 @@ class Ciconia
private $extensions;

/**
* Constructor
*
* @param RendererInterface $renderer
*/
public function __construct(RendererInterface $renderer = null)
Expand All @@ -57,10 +52,8 @@ public function __construct(RendererInterface $renderer = null)
}

/**
*
*
* @param string $text The markdown content
* @param array $options An array of options
* @param string $text
* @param array $options
*
* @return string
*/
Expand Down
25 changes: 20 additions & 5 deletions src/Ciconia/Extension/Core/InlineStyleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Ciconia\Extension\Core;

use Ciconia\Common\Text;
use Ciconia\Event\EmitterAwareInterface;
use Ciconia\Event\EmitterAwareTrait;
use Ciconia\Extension\ExtensionInterface;
use Ciconia\Renderer\RendererAwareInterface;
use Ciconia\Renderer\RendererAwareTrait;
Expand All @@ -16,10 +18,11 @@
*
* @author Kazuyuki Hayashi <hayashi@valnur.net>
*/
class InlineStyleExtension implements ExtensionInterface, RendererAwareInterface
class InlineStyleExtension implements ExtensionInterface, RendererAwareInterface, EmitterAwareInterface
{

use RendererAwareTrait;
use EmitterAwareTrait;

/**
* {@inheritdoc}
Expand All @@ -40,8 +43,14 @@ public function processBold(Text $text)
}

/** @noinspection PhpUnusedParameterInspection */
$text->replace('{ (\*\*|__) (?=\S) (.+?[*_]*) (?<=\S) \1 }sx', function (Text $w, Text $a, Text $target) {
return $this->getRenderer()->renderBoldText($target);
$text->replace('{ ([^\*_\s]?) (\*\*|__) (?=\S) (.+?[*_]*) (?<=\S) \2 ([^\*_\s]?) }sx', function (Text $w, Text $prevChar, Text $a, Text $target, Text $nextChar) {
if (!$prevChar->isEmpty() && !$nextChar->isEmpty() && $target->contains(' ')) {
$this->getEmitter()->emit('escape.special_chars', [$w->replaceString(['*', '_'], ['\\*', '\\_'])]);

return $w;
}

return $prevChar . $this->getRenderer()->renderBoldText($target) . $nextChar;
});
}

Expand All @@ -55,8 +64,14 @@ public function processItalic(Text $text)
}

/** @noinspection PhpUnusedParameterInspection */
$text->replace('{ (\*|_) (?=\S) (.+?) (?<=\S) \1 }sx', function (Text $w, Text $a, Text $target) {
return $this->getRenderer()->renderItalicText($target);
$text->replace('{ ([^\*_\s]?) (\*|_) (?=\S) (.+?) (?<=\S) \2 ([^\*_\s]?) }sx', function (Text $w, Text $prevChar, Text $a, Text $target, Text $nextChar) {
if (!$prevChar->isEmpty() && !$nextChar->isEmpty() && $target->contains(' ')) {
$this->getEmitter()->emit('escape.special_chars', [$w->replaceString(['*', '_'], ['\\*', '\\_'])]);

return $w;
}

return $prevChar . $this->getRenderer()->renderItalicText($target) . $nextChar;
});
}

Expand Down
3 changes: 3 additions & 0 deletions test/Ciconia/Resources/core/em-spaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
under_score and under_score

under__score and under__score
3 changes: 3 additions & 0 deletions test/Ciconia/Resources/core/em-spaces.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>under_score and under_score</p>

<p>under__score and under__score</p>
3 changes: 3 additions & 0 deletions test/Ciconia/Resources/gfm/em-spaces.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
under_score and under_score

under__score and under__score
3 changes: 3 additions & 0 deletions test/Ciconia/Resources/gfm/em-spaces.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>under_score and under_score</p>

<p>under__score and under__score</p>

0 comments on commit 86053df

Please sign in to comment.