From 2772b034c622e469684da29c7f36c51b8b6be7b0 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Tue, 27 Sep 2016 00:53:51 +0100 Subject: [PATCH 01/17] Update Parsedown.php (I think this should work) Allow parsedown to specify list start attribute (see: https://github.com/erusev/parsedown/issues/100#issuecomment-249729602) --- Parsedown.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index 646af86..f0efdc5 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -502,10 +502,10 @@ class Parsedown protected function blockList($Line) { - list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]+[.]'); - + list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '([*+-])') : array('ol', '([0-9]+)[.]'); if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches)) { + if($name === 'ol' && $matches[2] !== '1') $name. = ' start="' . $matches[2] . '"'; $Block = array( 'indent' => $Line['indent'], 'pattern' => $pattern, @@ -514,17 +514,14 @@ class Parsedown 'handler' => 'elements', ), ); - $Block['li'] = array( 'name' => 'li', 'handler' => 'li', 'text' => array( - $matches[2], + $matches[3], ), ); - $Block['element']['text'] []= & $Block['li']; - return $Block; } } @@ -1419,7 +1416,7 @@ class Parsedown $markup .= $Element['text']; } - $markup .= ''; + $markup .= ''; } else { From 1c58e9d8d5f90ab61d6cbb18d2c128a210576c60 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Tue, 27 Sep 2016 00:57:57 +0100 Subject: [PATCH 02/17] oops oops --- Parsedown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parsedown.php b/Parsedown.php index f0efdc5..c65b296 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -505,7 +505,7 @@ class Parsedown list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '([*+-])') : array('ol', '([0-9]+)[.]'); if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches)) { - if($name === 'ol' && $matches[2] !== '1') $name. = ' start="' . $matches[2] . '"'; + if($name === 'ol' && $matches[2] !== '1') $name .= ' start="' . $matches[2] . '"'; $Block = array( 'indent' => $Line['indent'], 'pattern' => $pattern, From cceefafd55b7c5574b0ffb7d9c23a067b801b51b Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Tue, 27 Sep 2016 01:16:00 +0100 Subject: [PATCH 03/17] test Attempting to determine which function change is causing test jobs to fail (in unexpected ways) --- Parsedown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parsedown.php b/Parsedown.php index c65b296..ac3ef81 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -1416,7 +1416,7 @@ class Parsedown $markup .= $Element['text']; } - $markup .= ''; + $markup .= ''; } else { From 2cee8d8a2d44e4a5f8584f949f0f6af08c5d3636 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Tue, 27 Sep 2016 01:23:22 +0100 Subject: [PATCH 04/17] Update Parsedown.php Looks like I might need to return the pattern which was used previously Reverting last change as build still failed This build will still fail, but I'm hoping it will only fair where the list start value has been inserted --- Parsedown.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index ac3ef81..5767fd6 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -508,7 +508,7 @@ class Parsedown if($name === 'ol' && $matches[2] !== '1') $name .= ' start="' . $matches[2] . '"'; $Block = array( 'indent' => $Line['indent'], - 'pattern' => $pattern, + 'pattern' => preg_replace('/\(|\)/', '', $pattern), 'element' => array( 'name' => $name, 'handler' => 'elements', @@ -1416,7 +1416,7 @@ class Parsedown $markup .= $Element['text']; } - $markup .= ''; + $markup .= ''; } else { From 38f4027d5e786aa2bbbc16ee56547552136007d2 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Tue, 27 Sep 2016 02:15:09 +0100 Subject: [PATCH 05/17] Update Parsedown.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Okay, so maybe I should have looked 20 lines or so above where I made the edit in the element function – looks like it already supports adding attributes ;p Have amended the change to blocklist to use the already existing functionality, and have reverted the change that I made to the element function. --- Parsedown.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index 5767fd6..c8eb663 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -505,7 +505,6 @@ class Parsedown list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '([*+-])') : array('ol', '([0-9]+)[.]'); if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches)) { - if($name === 'ol' && $matches[2] !== '1') $name .= ' start="' . $matches[2] . '"'; $Block = array( 'indent' => $Line['indent'], 'pattern' => preg_replace('/\(|\)/', '', $pattern), @@ -514,6 +513,7 @@ class Parsedown 'handler' => 'elements', ), ); + if($name === 'ol' && $matches[2] !== '1') $Block['element']['attributes'] = array('start' => $matches[2]); $Block['li'] = array( 'name' => 'li', 'handler' => 'li', @@ -1416,7 +1416,7 @@ class Parsedown $markup .= $Element['text']; } - $markup .= ''; + $markup .= ''; } else { From f17aa0438a7cd5242f67bfa309c2e2459bdbcee5 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Tue, 27 Sep 2016 02:15:35 +0100 Subject: [PATCH 06/17] Update Parsedown.php --- Parsedown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parsedown.php b/Parsedown.php index c8eb663..94515db 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -1416,7 +1416,7 @@ class Parsedown $markup .= $Element['text']; } - $markup .= ''; + $markup .= ''; } else { From c145a758486e4aa95827c02952175e5c32bfac79 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Tue, 4 Oct 2016 15:44:50 +0100 Subject: [PATCH 07/17] update test for new feature --- test/data/ordered_list.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/data/ordered_list.html b/test/data/ordered_list.html index b6c5216..2ca7914 100644 --- a/test/data/ordered_list.html +++ b/test/data/ordered_list.html @@ -8,6 +8,6 @@
  • two
  • large numbers:

    -
      +
      1. one
      2. -
      \ No newline at end of file +
    From 846274996a97a91fe22859e08cc338c6358b539d Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Tue, 4 Oct 2016 17:28:43 +0100 Subject: [PATCH 08/17] Update ordered_list.html From ac857809abb40d4938f093c28589f9092fd3b20e Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Tue, 4 Oct 2016 17:41:57 +0100 Subject: [PATCH 09/17] update test for new feature --- test/data/ordered_list.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/data/ordered_list.html b/test/data/ordered_list.html index 2ca7914..b6c5216 100644 --- a/test/data/ordered_list.html +++ b/test/data/ordered_list.html @@ -8,6 +8,6 @@
  • two
  • large numbers:

    -
      +
      1. one
      2. -
      +
    \ No newline at end of file From 932bafe0f0f7d9707a91bf7d7e185f5be450a190 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Tue, 4 Oct 2016 17:43:37 +0100 Subject: [PATCH 10/17] update test for new feature --- test/data/ordered_list.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/data/ordered_list.html b/test/data/ordered_list.html index b6c5216..c4a69db 100644 --- a/test/data/ordered_list.html +++ b/test/data/ordered_list.html @@ -8,6 +8,6 @@
  • two
  • large numbers:

    -
      +
      1. one
      \ No newline at end of file From 1fa8fae301e33a79d7345e7c6db526228a322d05 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Wed, 5 Oct 2016 10:03:21 +0100 Subject: [PATCH 11/17] Allow parsedown to specify list start attribute Readability improvements --- Parsedown.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index 94515db..a8e8e95 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -502,23 +502,30 @@ class Parsedown protected function blockList($Line) { - list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '([*+-])') : array('ol', '([0-9]+)[.]'); + list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]+[.]'); if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches)) { $Block = array( 'indent' => $Line['indent'], - 'pattern' => preg_replace('/\(|\)/', '', $pattern), + 'pattern' => $pattern, 'element' => array( 'name' => $name, 'handler' => 'elements', ), ); - if($name === 'ol' && $matches[2] !== '1') $Block['element']['attributes'] = array('start' => $matches[2]); + if($name === 'ol') + { + $list_num = explode ('.', $matches[0], 1)[0]; + if($list_num !== '1') + { + $Block['element']['attributes'] = array('start' => $list_num); + } + } $Block['li'] = array( 'name' => 'li', 'handler' => 'li', 'text' => array( - $matches[3], + $matches[2], ), ); $Block['element']['text'] []= & $Block['li']; From ed41fcf3d6714cef3c183386d1d111f54a9948fe Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Wed, 5 Oct 2016 10:06:40 +0100 Subject: [PATCH 12/17] Allow parsedown to specify list start attribute oops --- Parsedown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parsedown.php b/Parsedown.php index a8e8e95..a9fa5ae 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -515,7 +515,7 @@ class Parsedown ); if($name === 'ol') { - $list_num = explode ('.', $matches[0], 1)[0]; + $list_num = explode ('.', $matches[0], 2)[0]; if($list_num !== '1') { $Block['element']['attributes'] = array('start' => $list_num); From f0b7b61c16c1abe25756518c764d6e84e9914b12 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Wed, 5 Oct 2016 11:36:27 +0100 Subject: [PATCH 13/17] Allow parsedown to specify list start attribute Should fix compatibility for PHP 5.3 --- Parsedown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parsedown.php b/Parsedown.php index a9fa5ae..9693428 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -515,7 +515,7 @@ class Parsedown ); if($name === 'ol') { - $list_num = explode ('.', $matches[0], 2)[0]; + $list_num = preg_replace ('/^([0-9]+)[.].*+$/', '$1', $matches[0]); if($list_num !== '1') { $Block['element']['attributes'] = array('start' => $list_num); From e3cd271f1603134c31359043677fbc8c7dc8d1e5 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Wed, 5 Oct 2016 15:44:34 +0100 Subject: [PATCH 14/17] Allow parsedown to specify list start attribute Performance: Swap preg_replace for stristr to obtain list start --- Parsedown.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Parsedown.php b/Parsedown.php index 9693428..03b729b 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -515,7 +515,7 @@ class Parsedown ); if($name === 'ol') { - $list_num = preg_replace ('/^([0-9]+)[.].*+$/', '$1', $matches[0]); + $list_num = stristr($matches[0], ".", true); if($list_num !== '1') { $Block['element']['attributes'] = array('start' => $list_num); From a37797ef347a3777c284dc2e8f8058482b370c09 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Wed, 5 Oct 2016 18:15:47 +0100 Subject: [PATCH 15/17] Allow parsedown to specify list start attribute Syntax preferences to match surrounding code --- Parsedown.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index 03b729b..3a5f0d2 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -503,6 +503,7 @@ class Parsedown protected function blockList($Line) { list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]+[.]'); + if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches)) { $Block = array( @@ -513,14 +514,16 @@ class Parsedown 'handler' => 'elements', ), ); + if($name === 'ol') { - $list_num = stristr($matches[0], ".", true); - if($list_num !== '1') + $listStart = stristr($matches[0], ".", true); + if($listStart !== '1') { - $Block['element']['attributes'] = array('start' => $list_num); + $Block['element']['attributes'] = array('start' => $listStart); } } + $Block['li'] = array( 'name' => 'li', 'handler' => 'li', @@ -528,7 +531,9 @@ class Parsedown $matches[2], ), ); + $Block['element']['text'] []= & $Block['li']; + return $Block; } } From 3978e33fd0eb964f9faa8ce9862b8518492a7a54 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Wed, 5 Oct 2016 18:17:12 +0100 Subject: [PATCH 16/17] Allow parsedown to specify list start attribute Remove github added tabs on blank lines --- Parsedown.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Parsedown.php b/Parsedown.php index 3a5f0d2..cf78d7a 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -503,7 +503,7 @@ class Parsedown protected function blockList($Line) { list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]+[.]'); - + if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches)) { $Block = array( @@ -514,7 +514,7 @@ class Parsedown 'handler' => 'elements', ), ); - + if($name === 'ol') { $listStart = stristr($matches[0], ".", true); @@ -523,7 +523,7 @@ class Parsedown $Block['element']['attributes'] = array('start' => $listStart); } } - + $Block['li'] = array( 'name' => 'li', 'handler' => 'li', @@ -531,9 +531,9 @@ class Parsedown $matches[2], ), ); - + $Block['element']['text'] []= & $Block['li']; - + return $Block; } } From 5c22531e4dc535077e6dce163fbfc5389feddeab Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Wed, 5 Oct 2016 18:27:54 +0100 Subject: [PATCH 17/17] Allow parsedown to specify list start attribute Syntax preferences --- Parsedown.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Parsedown.php b/Parsedown.php index cf78d7a..4737eee 100644 --- a/Parsedown.php +++ b/Parsedown.php @@ -517,7 +517,8 @@ class Parsedown if($name === 'ol') { - $listStart = stristr($matches[0], ".", true); + $listStart = stristr($matches[0], '.', true); + if($listStart !== '1') { $Block['element']['attributes'] = array('start' => $listStart);