From 92b1e74b78f268a3b812e2194adee9b6a801c718 Mon Sep 17 00:00:00 2001 From: Kazuyuki Hayashi Date: Thu, 5 Dec 2013 00:33:42 +0900 Subject: [PATCH 1/3] v1.0.1 --- README.md | 2 +- src/Ciconia/Ciconia.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3f50b0b..095dffd 100644 --- a/README.md +++ b/README.md @@ -301,7 +301,7 @@ Kazuyuki Hayashi (@kzykhys) [milestones]: https://github.com/kzykhys/Ciconia/issues/milestones -[phar]: https://github.com/kzykhys/Ciconia/releases/download/v1.0.0/ciconia.phar +[phar]: https://github.com/kzykhys/Ciconia/releases/download/v1.0.1/ciconia.phar [contributors]: https://github.com/kzykhys/Ciconia/graphs/contributors [textapi]: https://github.com/kzykhys/Text#api diff --git a/src/Ciconia/Ciconia.php b/src/Ciconia/Ciconia.php index 5634fa2..71a12ca 100644 --- a/src/Ciconia/Ciconia.php +++ b/src/Ciconia/Ciconia.php @@ -24,7 +24,7 @@ class Ciconia { - const VERSION = '1.0.0'; + const VERSION = '1.0.1'; /** * @var RendererInterface From 7067efd959118851068dc7a79afa2b6087b9e73c Mon Sep 17 00:00:00 2001 From: Kazuyuki Hayashi Date: Tue, 10 Dec 2013 17:29:40 +0900 Subject: [PATCH 2/3] Merge branch 'master' of https://github.com/joelcuevas/Ciconia into joelcuevas-master Conflicts: README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 095dffd..aaad992 100644 --- a/README.md +++ b/README.md @@ -292,7 +292,7 @@ The MIT License Contributing ------------ -Feel free to folk this repository and send a pull request. ([A list of contributors][contributors]) +Feel free to fork this repository and send a pull request. ([A list of contributors][contributors]) Author ------ From 4c5287db9be1312fde8b67a49e79b6640980ad05 Mon Sep 17 00:00:00 2001 From: Kazuyuki Hayashi Date: Thu, 23 Jan 2014 16:37:31 +0900 Subject: [PATCH 3/3] Fixes #28 Wrong underscore parsing --- .../Extension/Core/InlineStyleExtension.php | 25 +++++++++++++++---- test/Ciconia/Resources/core/em-spaces.md | 3 +++ test/Ciconia/Resources/core/em-spaces.out | 3 +++ test/Ciconia/Resources/gfm/em-spaces.md | 3 +++ test/Ciconia/Resources/gfm/em-spaces.out | 3 +++ 5 files changed, 32 insertions(+), 5 deletions(-) create mode 100755 test/Ciconia/Resources/core/em-spaces.md create mode 100755 test/Ciconia/Resources/core/em-spaces.out create mode 100644 test/Ciconia/Resources/gfm/em-spaces.md create mode 100644 test/Ciconia/Resources/gfm/em-spaces.out diff --git a/src/Ciconia/Extension/Core/InlineStyleExtension.php b/src/Ciconia/Extension/Core/InlineStyleExtension.php index f2bed81..b3880f5 100644 --- a/src/Ciconia/Extension/Core/InlineStyleExtension.php +++ b/src/Ciconia/Extension/Core/InlineStyleExtension.php @@ -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; @@ -16,10 +18,11 @@ * * @author Kazuyuki Hayashi */ -class InlineStyleExtension implements ExtensionInterface, RendererAwareInterface +class InlineStyleExtension implements ExtensionInterface, RendererAwareInterface, EmitterAwareInterface { use RendererAwareTrait; + use EmitterAwareTrait; /** * {@inheritdoc} @@ -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; }); } @@ -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; }); } diff --git a/test/Ciconia/Resources/core/em-spaces.md b/test/Ciconia/Resources/core/em-spaces.md new file mode 100755 index 0000000..051f373 --- /dev/null +++ b/test/Ciconia/Resources/core/em-spaces.md @@ -0,0 +1,3 @@ +under_score and under_score + +under__score and under__score \ No newline at end of file diff --git a/test/Ciconia/Resources/core/em-spaces.out b/test/Ciconia/Resources/core/em-spaces.out new file mode 100755 index 0000000..653e7d1 --- /dev/null +++ b/test/Ciconia/Resources/core/em-spaces.out @@ -0,0 +1,3 @@ +

under_score and under_score

+ +

under__score and under__score

\ No newline at end of file diff --git a/test/Ciconia/Resources/gfm/em-spaces.md b/test/Ciconia/Resources/gfm/em-spaces.md new file mode 100644 index 0000000..051f373 --- /dev/null +++ b/test/Ciconia/Resources/gfm/em-spaces.md @@ -0,0 +1,3 @@ +under_score and under_score + +under__score and under__score \ No newline at end of file diff --git a/test/Ciconia/Resources/gfm/em-spaces.out b/test/Ciconia/Resources/gfm/em-spaces.out new file mode 100644 index 0000000..653e7d1 --- /dev/null +++ b/test/Ciconia/Resources/gfm/em-spaces.out @@ -0,0 +1,3 @@ +

under_score and under_score

+ +

under__score and under__score

\ No newline at end of file