From ade918d5fe75bf98b8d36b6c15057c641a145e4a Mon Sep 17 00:00:00 2001
From: Hisateru Tanaka
Date: Wed, 28 Sep 2016 21:42:45 +0900
Subject: [PATCH] Fix paragraph breaking condition
Quote, HR and HTML are independent blocks even if not placed empty lines before them.
---
GithubMarkdown.php | 3 ++-
Markdown.php | 12 ++++++++++--
tests/github-data/dense-block-markers.html | 7 +++++++
tests/github-data/dense-block-markers.md | 11 ++++++++++-
tests/markdown-data/dense-block-markers.html | 7 +++++++
tests/markdown-data/dense-block-markers.md | 11 ++++++++++-
tests/markdown-data/images.html | 4 ++--
7 files changed, 48 insertions(+), 7 deletions(-)
diff --git a/GithubMarkdown.php b/GithubMarkdown.php
index 23c9d1a..bc9e73d 100644
--- a/GithubMarkdown.php
+++ b/GithubMarkdown.php
@@ -71,7 +71,8 @@ protected function consumeParagraph($lines, $current)
$this->identifyFencedCode($line, $lines, $i) ||
$this->identifyUl($line, $lines, $i) ||
$this->identifyOl($line, $lines, $i) ||
- $this->identifyHr($line, $lines, $i)
+ $this->identifyHr($line, $lines, $i) ||
+ $this->identifyHtml($line, $lines, $i)
)
|| $this->identifyHeadline($line, $lines, $i))
{
diff --git a/Markdown.php b/Markdown.php
index 32c9b0f..a369ea0 100644
--- a/Markdown.php
+++ b/Markdown.php
@@ -92,9 +92,17 @@ protected function consumeParagraph($lines, $current)
break;
}
- if ($line === '' || ltrim($line) === '' || $this->identifyHeadline($line, $lines, $i)) {
+ if (
+ $line === '' ||
+ ltrim($line) === '' ||
+ !ctype_alpha($line[0]) && (
+ $this->identifyQuote($line, $lines, $i) ||
+ $this->identifyHr($line, $lines, $i) ||
+ $this->identifyHtml($line, $lines, $i)
+ )
+ || $this->identifyHeadline($line, $lines, $i)) {
break;
- } elseif ($line[0] === "\t" || $line[0] === " " && strncmp($line, ' ', 4) === 0) {
+ } elseif ($this->identifyCode($line, $lines, $i)) {
// possible beginning of a code block
// but check for continued inline HTML
// e.g.
changelog 2
+paragraph
+quote
+
+paragraph
+
+paragraph
+html block
diff --git a/tests/github-data/dense-block-markers.md b/tests/github-data/dense-block-markers.md
index ea365b8..db09cf8 100644
--- a/tests/github-data/dense-block-markers.md
+++ b/tests/github-data/dense-block-markers.md
@@ -53,4 +53,13 @@ headline2
----
## changelog 2
-* 17-Feb-2013 re-design
\ No newline at end of file
+* 17-Feb-2013 re-design
+
+paragraph
+> quote
+
+paragraph
+- - -
+
+paragraph
+html block
diff --git a/tests/markdown-data/dense-block-markers.html b/tests/markdown-data/dense-block-markers.html
index 964949c..14cbcae 100644
--- a/tests/markdown-data/dense-block-markers.html
+++ b/tests/markdown-data/dense-block-markers.html
@@ -48,3 +48,10 @@ changelog 2
+paragraph
+quote
+
+paragraph
+
+paragraph
+html block
diff --git a/tests/markdown-data/dense-block-markers.md b/tests/markdown-data/dense-block-markers.md
index ea365b8..db09cf8 100644
--- a/tests/markdown-data/dense-block-markers.md
+++ b/tests/markdown-data/dense-block-markers.md
@@ -53,4 +53,13 @@ headline2
----
## changelog 2
-* 17-Feb-2013 re-design
\ No newline at end of file
+* 17-Feb-2013 re-design
+
+paragraph
+> quote
+
+paragraph
+- - -
+
+paragraph
+html block
diff --git a/tests/markdown-data/images.html b/tests/markdown-data/images.html
index e7c7679..96eb56f 100644
--- a/tests/markdown-data/images.html
+++ b/tests/markdown-data/images.html
@@ -2,9 +2,9 @@

Here is an image tag:
.
Images inside of links:
-
+
-
+

This is not an image: ![[ :-)
This is not an image: ![[ :-)]]