Skip to content

Commit

Permalink
Add option to have different styles for consecutive lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sylry committed May 17, 2018
1 parent 3af14d8 commit 6d6bd5d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Converter/ListItemConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,16 @@ public function convert(ElementInterface $element)

if ($list_type === 'ul') {
$list_item_style = $this->config->getOption('list_item_style', '-');
return $prefix . $list_item_style . ' ' . $value . "\n";
$list_item_style_alternate = $this->config->getOption('list_item_style_alternate');
if (!isset($this->list_item_style)) {
$this->list_item_style = $list_item_style_alternate ? $list_item_style_alternate : $list_item_style;
}

if ($list_item_style_alternate && $level == 0 && $element->getSiblingPosition() === 1) {
$this->list_item_style = $this->list_item_style == $list_item_style ? $list_item_style_alternate : $list_item_style;
}

return $prefix . $this->list_item_style . ' ' . $value . "\n";
}

if ($list_type === 'ol' && $start = $element->getParent()->getAttribute('start')) {
Expand Down
1 change: 1 addition & 0 deletions tests/HtmlConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function test_lists()
$this->html_gives_markdown('<ol><li> Item A</li><li> Item B</li></ol>', "1. Item A\n2. Item B");
$this->html_gives_markdown('<ol><li> <h3> Item A</h3><p>Description</p></li><li> Item B</li></ol>', "1. ### Item A\n \n Description\n2. Item B");
$this->html_gives_markdown('<ol start="120"><li>Item A</li><li>Item B</li></ol>', "120. Item A\n121. Item B");
$this->html_gives_markdown('<ul><li>first item of first list</li><li>second item of first list</li></ul><ul><li>first item of second list</li></ul>', "- first item of first list\n- second item of first list\n\n* first item of second list", array('list_item_style_alternate' => '*'));
}

public function test_nested_lists()
Expand Down

0 comments on commit 6d6bd5d

Please sign in to comment.