diff --git a/src/markup/engine/__tests__/remarkup/ordered-list-with-numbers.txt b/src/markup/engine/__tests__/remarkup/ordered-list-with-numbers.txt --- a/src/markup/engine/__tests__/remarkup/ordered-list-with-numbers.txt +++ b/src/markup/engine/__tests__/remarkup/ordered-list-with-numbers.txt @@ -10,6 +10,10 @@ 1. asd 234) asd +10. ten +11. eleven +12. twelve + 1/ This explicitly should not be formatted as a list. ~~~~~~~~~~
    @@ -24,13 +28,21 @@
  1. asdf
-

234) asd

+
    +
  1. asd
  2. +
  1. asd
  2. asd
+
    +
  1. ten
  2. +
  3. eleven
  4. +
  5. twelve
  6. +
+

1/ This explicitly should not be formatted as a list.

~~~~~~~~~~ 1. aasdx @@ -40,9 +52,13 @@ 1. asdf 2. asdf -234) asd +234. asd 1. asd 2. asd +10. ten +11. eleven +12. twelve + 1/ This explicitly should not be formatted as a list. diff --git a/src/markup/engine/remarkup/blockrule/PhutilRemarkupListBlockRule.php b/src/markup/engine/remarkup/blockrule/PhutilRemarkupListBlockRule.php --- a/src/markup/engine/remarkup/blockrule/PhutilRemarkupListBlockRule.php +++ b/src/markup/engine/remarkup/blockrule/PhutilRemarkupListBlockRule.php @@ -81,7 +81,7 @@ * the stack. */ const MAXIMUM_LIST_NESTING_DEPTH = 12; - const START_BLOCK_PATTERN = '@^\s*(?:[-*#]+|1[.)]|\[.?\])\s+@'; + const START_BLOCK_PATTERN = '@^\s*(?:[-*#]+|([1-9][0-9]*)[.)]|\[.?\])\s+@'; const CONT_BLOCK_PATTERN = '@^\s*(?:[-*#]+|[0-9]+[.)]|\[.?\])\s+@'; const STRIP_BLOCK_PATTERN = '@^\s*(?:[-*#]+|[0-9]+[.)])\s*@'; @@ -151,9 +151,14 @@ // ); $item = array(); + $starts_at = null; $regex = self::START_BLOCK_PATTERN; foreach ($lines as $line) { - if (preg_match($regex, $line)) { + $match = null; + if (preg_match($regex, $line, $match)) { + if (!$starts_at && !empty($match[1])) { + $starts_at = $match[1]; + } $regex = self::CONT_BLOCK_PATTERN; if ($item) { $items[] = $item; @@ -165,6 +170,9 @@ if ($item) { $items[] = $item; } + if (!$starts_at) { + $starts_at = 1; + } // Process each item to normalize the text, remove line wrapping, and @@ -314,7 +322,7 @@ // Finally, we have enough information to render the tree. - $out = $this->renderTree($tree, 0, $has_marks); + $out = $this->renderTree($tree, 0, $has_marks, $starts_at); if ($this->getEngine()->isTextMode()) { $out = implode('', $out); @@ -416,7 +424,12 @@ /** * See additional notes in @{method:markupText}. */ - private function renderTree(array $tree, $level, $has_marks) { + private function renderTree( + array $tree, + $level, + $has_marks, + $starts_at = 1) { + $style = idx(head($tree), 'style'); $out = array(); @@ -431,20 +444,27 @@ break; } + $start_attr = null; + if (ctype_digit($starts_at) && $starts_at > 1) { + $start_attr = hsprintf(' start="%d"', $starts_at); + } + if ($has_marks) { $out[] = hsprintf( - '<%s class="remarkup-list remarkup-list-with-checkmarks">', - $tag); + '<%s class="remarkup-list remarkup-list-with-checkmarks"%s>', + $tag, + $start_attr); } else { $out[] = hsprintf( - '<%s class="remarkup-list">', - $tag); + '<%s class="remarkup-list"%s>', + $tag, + $start_attr); } $out[] = "\n"; } - $number = 1; + $number = $starts_at; foreach ($tree as $item) { if ($this->getEngine()->isTextMode()) { if ($item['text'] === null) {