Skip to content

Commit

Permalink
Merge branch 'list-bullets'
Browse files Browse the repository at this point in the history
* list-bullets:
  - Fix CHANGELOG.md - Add messages for 2.5.0
  Add tests for list_bullets
  Add 'Customizable list bullets in TOC' section on README.
  Add 'default_list_bullets' #41
  • Loading branch information
naokazuterada committed Sep 20, 2017
2 parents 3443ab5 + 5172634 commit 00e4d0e
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 1 deletion.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Changes in MarkdownTOC
===========================

## 2.5.0

- Add `Customizable list bullets` feature

## 2.4.1

- Fix problem that user's settings doesn't work. Ref: #100
- Fix problem that characters inside codeblock is also escaped. Ref: #64
Contribution by Mathieu PATUREL ( @math2001 ). Ref: #101

## 2.4.0

- Support MarkdownPreview's anchoring

## 2.3.2

- Fix the way of import dependencies
Expand Down
6 changes: 5 additions & 1 deletion MarkdownTOC.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,14 @@ def replace_strings_in_id(_str):
toc = ''
_ids = []
level_counters = [0]
list_bullets = attrs['list_bullets']


for item in items:
_id = None
_indent = item[0] - 1
_text = item[1]
_list_bullet = list_bullets[_indent%len(list_bullets)]
_text = pattern_tag.sub('', _text) # remove html tags
_text = _text.rstrip() # remove end space

Expand Down Expand Up @@ -280,7 +283,7 @@ def replace_strings_in_id(_str):
_id += '-' + str(n-1)

if attrs['style'] == 'unordered':
list_prefix = '- '
list_prefix = _list_bullet+' '
elif attrs['style'] == 'ordered':
list_prefix = '1. '

Expand Down Expand Up @@ -331,6 +334,7 @@ def get_settings(self):
"bracket": self.get_setting('default_bracket'),
"depth": self.get_setting('default_depth'),
"indent": self.get_setting('default_indent'),
"list_bullets": self.get_setting('default_list_bullets'),
"lowercase_only_ascii": self.get_setting('default_lowercase_only_ascii'),
"style": self.get_setting('default_style'),
"uri_encoding": self.get_setting('default_uri_encoding'),
Expand Down
1 change: 1 addition & 0 deletions MarkdownTOC.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"default_bracket": "square",
"default_depth": 2,
"default_indent": "\t",
"default_list_bullets": "-",
"default_lowercase_only_ascii": true,
"default_style": "unordered",
"default_uri_encoding": true,
Expand Down
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Sublime Text 3 plugin for generating a Table of Contents (TOC) in a Markdown doc
- [Markdown Preview compatible](#markdown-preview-compatible)
- [Control of depth listed in TOC](#control-of-depth-listed-in-toc)
- [Ordered or unordered style for TOC elements](#ordered-or-unordered-style-for-toc-elements)
- [Customizable list bullets in TOC](#customizable-list-bullets-in-toc)
- [Specify custom indentation prefix](#specify-custom-indentation-prefix)
- [Usage](#usage)
- [Tips](#tips)
Expand Down Expand Up @@ -77,6 +78,7 @@ The **MarkdownTOC** plugin is rich on features and customization, useful for bot
- Manipulation of auto link ids
- Control of depth listed in TOC
- Ordered or unordered style for TOC elements
- Customizable list bullets in TOC
- Specify custom indentation prefix

### Insertion of TOC based on headings in Markdown document
Expand Down Expand Up @@ -556,6 +558,41 @@ Please note that the default for the [attribute](#attributes) is: `unordered`.

You can set your default style in your [configuration](#configuration) with the key `default_style`.

### Customizable list bullets in TOC

You can define the list items used for the TOC for each level. The first item is for the first level, the second for the second and so on until the last one of the list and then it starts over from the beginning.

```markdown
<!-- MarkdownTOC list_bullets="-+*" depth="0" -->

- foo
+ bar
* baz
- foo
+ bar
* baz

<!-- /MarkdownTOC -->
```

You can set default list bullets in your [configuration](#configuration) with the key `default_list_bullets`.

The example above could also be described as:

```json
{
"default_list_bullets": "-+*"
}
```

And the value could also be _array_.

```json
{
"default_list_bullets": ["-","+","*"]
}
```

### Specify custom indentation prefix

The indentation prefix is a specification of the string used to indent the TOC elements.
Expand Down Expand Up @@ -659,6 +696,7 @@ The following attributes can be used to control the generation of the TOC.
| `bracket` | `square`or`round` | `'square'` | `default_bracket` |
| `depth` | integer (`0` means _no limit_) | `2` | `default_depth` |
| `indent` | string | `'\t'` | `default_indent` |
| `list_bullets` | string | `-` | `default_list_bullets` |
| `lowercase_only_ascii` | `true`or`false` | `true` | `default_lowercase_only_ascii` |
| `style` | `ordered` or `unordered` | `'unordered'` | `default_style` |
| `uri_encoding` | `true`or`false` | `true` | `default_uri_encoding` |
Expand Down Expand Up @@ -704,6 +742,7 @@ Example: `MarkdownTOC.sublime-settings`
"default_bracket": "square",
"default_depth": 2,
"default_indent": "\t",
"default_list_bullets": "-",
"default_lowercase_only_ascii": true,
"default_style": "unordered",
"default_uri_encoding": true,
Expand Down
7 changes: 7 additions & 0 deletions messages/2.5.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MarkdownTOC - 2.5.0

CHANGES

- Add `Customizable list bullets` feature

Ref: #41
63 changes: 63 additions & 0 deletions tests/test_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,66 @@ def test_markdown_preview_no_heading_markdown(self):
def test_markdown_preview_no_heading_github(self):
toc_txt = self.commonSetup(self.markdown_preview_no_heading_text.format('markdown_preview=github'))
self.assert_NotIn('^- ', toc_txt)

# list bullets
list_bullets_text = \
"""
<!-- MarkdownTOC depth=0 {0} -->
<!-- /MarkdownTOC -->
# Heading1
## Heading2
## Heading2-2
### Heading3
### Heading3-2
#### Heading4
#### Heading4-2
##### Heading5
###### Heading6
"""
def test_list_bullets_default(self):
toc_txt = self.commonSetup(self.list_bullets_text.format(''))
self.assert_In('- Heading1', toc_txt)
self.assert_In('- Heading2', toc_txt)
self.assert_In('- Heading2-2', toc_txt)
self.assert_In('- Heading3', toc_txt)
self.assert_In('- Heading3-2', toc_txt)
self.assert_In('- Heading4', toc_txt)
self.assert_In('- Heading4-2', toc_txt)
self.assert_In('- Heading5', toc_txt)
self.assert_In('- Heading6', toc_txt)
def test_list_bullets_2values(self):
toc_txt = self.commonSetup(self.list_bullets_text.format('list_bullets="+-"'))
self.assert_In('+ Heading1', toc_txt)
self.assert_In('- Heading2', toc_txt)
self.assert_In('- Heading2-2', toc_txt)
self.assert_In('+ Heading3', toc_txt)
self.assert_In('+ Heading3-2', toc_txt)
self.assert_In('- Heading4', toc_txt)
self.assert_In('- Heading4-2', toc_txt)
self.assert_In('+ Heading5', toc_txt)
self.assert_In('- Heading6', toc_txt)
def test_list_bullets_3values(self):
toc_txt = self.commonSetup(self.list_bullets_text.format('list_bullets="-+*"'))
self.assert_In('- Heading1', toc_txt)
self.assert_In('+ Heading2', toc_txt)
self.assert_In('+ Heading2-2', toc_txt)
self.assert_In('* Heading3', toc_txt)
self.assert_In('* Heading3-2', toc_txt)
self.assert_In('- Heading4', toc_txt)
self.assert_In('- Heading4-2', toc_txt)
self.assert_In('+ Heading5', toc_txt)
self.assert_In('* Heading6', toc_txt)
def test_list_bullets_4values(self):
toc_txt = self.commonSetup(self.list_bullets_text.format('list_bullets="-+-*"'))
self.assert_In('- Heading1', toc_txt)
self.assert_In('+ Heading2', toc_txt)
self.assert_In('+ Heading2-2', toc_txt)
self.assert_In('- Heading3', toc_txt)
self.assert_In('- Heading3-2', toc_txt)
self.assert_In('* Heading4', toc_txt)
self.assert_In('* Heading4-2', toc_txt)
self.assert_In('- Heading5', toc_txt)
self.assert_In('+ Heading6', toc_txt)

0 comments on commit 00e4d0e

Please sign in to comment.