Skip to content

Commit

Permalink
Merge branch 'release-0.5.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenjackson01 committed May 1, 2017
2 parents 78afb1d + 33dfe3d commit 6ac4003
Show file tree
Hide file tree
Showing 42 changed files with 861 additions and 36 deletions.
1 change: 0 additions & 1 deletion .pyup.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
update: all
branch: develop
schedule: "every day"
label_prs: update
7 changes: 7 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
#######################################

0.5.2
=======================================

Fixes:

- Verto container tags, are now supported in markdown lists.

0.5.1
=======================================

Expand Down
2 changes: 2 additions & 0 deletions docs/source/processors/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ The following pages cover processors that do not require explicit use when autho

beautify
jinja
orderedlist
remove
scratch-compatibility
style
unorderedlist
41 changes: 41 additions & 0 deletions docs/source/processors/orderedlist.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.. _orderedlist:

Ordered List (OListProcessor)
#######################################

**Processor name:** ``olist``

This processor overwrites functionality provided by the Python `Markdown <https://pypi.python.org/pypi/Markdown>`_ package allowing for the use of container tags such as :doc:`panel` and :doc:`boxed-text` tags within an ordered list while also providing the same features of the sane lists extension.

Indentation is important when creating ordered lists and is expected to be by default ``4`` spaces for inner content and ``2`` spaces after the number. Authors should follow the following example where indentation spaces are replaced with the ```` character.

.. code-block:: none
1.••Text here.
••••More text here.
2.••Text here.
••••1.••List within a list.
••••••••More text here.
Sane Lists
*******************************

The Sane Lists extension alters the markdown lists such that types are not allowed to mix. This extension is implemented in Verto by default and therefore does not need to be added as an extension. This means the following markdown:

.. code-block:: none
1. Ordered list item.
* Not a separate item.
produces the output:

.. code-block:: html

<ol>
<li>
Ordered list item.
* Not a separate item.
</li>
</ol>
22 changes: 22 additions & 0 deletions docs/source/processors/unorderedlist.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.. _unorderedlist:

Unordered List (UListProcessor)
#######################################

**Processor name:** ``ulist``

This processor overwrites functionality provided by the Python `Markdown <https://pypi.python.org/pypi/Markdown>`_ package allowing for the use of container tags such as :doc:`panel` and :doc:`boxed-text` tags within an unordered list while also providing the same features of the sane lists extension.

Indentation is important when creating unordered lists and is expected to be ``4`` spaces by default for inner content and ``3`` spaces after the bullet. Authors should follow the following example where indentation spaces are replaced with the ```` character.

.. code-block:: none
*•••Text here.
••••More text here.
*•••Text here.
••••*•••List within a list.
••••••••More text here.
See :doc:`orderedlist` for details on Sane Lists.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ markdown==2.6.8
beautifulsoup4==4.5.3
Jinja2==2.9.6
python-slugify==1.2.3
setuptools==35.0.0
setuptools==35.0.2

# Required dependencies for building documentation
sphinx==1.5.5
Expand Down
6 changes: 5 additions & 1 deletion verto/VertoExtension.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

from verto.utils.UniqueSlugify import UniqueSlugify
from verto.utils.HeadingNode import HeadingNode
from verto.utils.overrides import is_block_level, BLOCK_LEVEL_ELEMENTS
from verto.utils.overrides import BLOCK_LEVEL_ELEMENTS, is_block_level
from verto.utils.overrides import OListProcessor
from verto.utils.overrides import UListProcessor

from collections import defaultdict, OrderedDict
from os import listdir
Expand Down Expand Up @@ -101,6 +103,8 @@ def update_processors(processors, markdown_processors):

# Compatibility modules
md.postprocessors['raw_html'].isblocklevel = lambda html: is_block_level(html, BLOCK_LEVEL_ELEMENTS)
md.parser.blockprocessors['olist'] = OListProcessor(md.parser)
md.parser.blockprocessors['ulist'] = UListProcessor(md.parser)

if ('fenced_code_block' in self.compatibility
and 'scratch' in self.processors):
Expand Down
2 changes: 1 addition & 1 deletion verto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# flake8: noqa
from .Verto import Verto

__version__ = '0.5.1'
__version__ = '0.5.2'
10 changes: 8 additions & 2 deletions verto/processors/StylePreprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def __init__(self, ext, *args, **kwargs):
self.block_strings = ext.processor_info[self.processor]['strings']['block']
self.inline_strings = ext.processor_info[self.processor]['strings']['inline']

self.LIST_RE = re.compile('^[ ]*(\d+\.|[*+-])[ ]+(.*)')

def run(self, lines):
'''
Validates lines and raising StyleErrors when rules are not upheld.
Expand All @@ -47,8 +49,12 @@ def run(self, lines):

start_index, end_index = block_match.span()
rest = line[:start_index] + line[end_index+1:]
for char in rest:
if not char.isspace():

if (self.LIST_RE.match(line[:start_index])
and not all(map(lambda char: char.isspace(), line[end_index+1:]))):
raise StyleError(line_nums, error_lines, 'Content after block in list.')
elif (not self.LIST_RE.match(line[:start_index])
and not all(map(lambda char: char.isspace(), rest))):
raise StyleError(line_nums, error_lines, 'Blocks must be the only thing on the line.')

return lines
119 changes: 119 additions & 0 deletions verto/tests/MarkdownOverrideTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import markdown
from verto.tests.BaseTest import BaseTest
from verto.VertoExtension import VertoExtension

class MarkdownOverrideTest(BaseTest):
'''Tests that the overrides for built-in markdown packages
continue to work as normal markdown.
'''

def __init__(self, *args, **kwargs):
'''Setup asset file directory.
'''
super().__init__(*args, **kwargs)
self.test_type = "markdown-override"

def read_test_file(self, filename):
'''Returns a string for a given file.
Args:
filename: The filename of the file found in the asset
directory.
Returns:
A string of the given file.
'''
return super().read_test_file(self.test_type, filename, True)

def setUp(self):
'''Runs before each testcase, creates a verto extensions
and a markdown instance for running tests.
'''
self.verto_extension = VertoExtension([], {})

def test_unordered_list_asterisk_tight(self):
'''Check that tight unordered list with asterisks produces expected output.
'''
test_string = self.read_test_file('unordered_list_asterisk_tight.md')
converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension])
expected_string = self.read_test_file('unordered_list_asterisk_tight_expected.html')
self.assertEqual(expected_string, converted_test_string)

def test_unordered_list_asterisk_loose(self):
'''Check that loose unordered list with asterisks produces expected output.
'''
test_string = self.read_test_file('unordered_list_asterisk_loose.md')
converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension])
expected_string = self.read_test_file('unordered_list_asterisk_loose_expected.html')
self.assertEqual(expected_string, converted_test_string)

def test_unordered_list_tight_nested(self):
'''Check that tight unordered list with asterisks produces expected output.
'''
test_string = self.read_test_file('unordered_list_tight_nested.md')
converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension])
expected_string = self.read_test_file('unordered_list_tight_nested_expected.html')
self.assertEqual(expected_string, converted_test_string)

def test_unordered_list_loose_nested(self):
'''Check that loose unordered list with asterisks produces expected output.
'''
test_string = self.read_test_file('unordered_list_loose_nested.md')
converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension])
expected_string = self.read_test_file('unordered_list_loose_nested_expected.html')
self.assertEqual(expected_string, converted_test_string)

def test_unordered_list_mixed_nested(self):
'''Check that loose unordered list with asterisks produces expected output.
'''
test_string = self.read_test_file('unordered_list_mixed_nested.md')
converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension])
expected_string = self.read_test_file('unordered_list_mixed_nested_expected.html')
self.assertEqual(expected_string, converted_test_string)

def test_ordered_list_tight(self):
'''Check that tight ordered list with numbers produces expected output.
'''
test_string = self.read_test_file('ordered_list_tight.md')
converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension])
expected_string = self.read_test_file('ordered_list_tight_expected.html')
self.assertEqual(expected_string, converted_test_string)

def test_ordered_list_loose(self):
'''Check that loose ordered list with numbers produces expected output.
'''
test_string = self.read_test_file('ordered_list_loose.md')
converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension])
expected_string = self.read_test_file('ordered_list_loose_expected.html')
self.assertEqual(expected_string, converted_test_string)

def test_ordered_list_multiple_paragraphs(self):
'''Check that an ordered list with multiple paragraphs produces expected output.
'''
test_string = self.read_test_file('ordered_list_multiple_paragraphs.md')
converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension])
expected_string = self.read_test_file('ordered_list_multiple_paragraphs_expected.html')
self.assertEqual(expected_string, converted_test_string)

def test_ordered_list_tight_nested(self):
'''Check that nested tight ordered list with numbers produces expected output.
'''
test_string = self.read_test_file('ordered_list_tight_nested.md')
converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension])
expected_string = self.read_test_file('ordered_list_tight_nested_expected.html')
self.assertEqual(expected_string, converted_test_string)

def test_sane_list(self):
'''Check that nested tight ordered list with numbers produces expected output.
'''
test_string = self.read_test_file('sane_list.md')
converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension])
expected_string = self.read_test_file('sane_list_expected.html')
self.assertEqual(expected_string, converted_test_string)

def test_sane_list_python_markdown(self):
'''Check that nested tight ordered list with numbers produces expected output.
'''
test_string = self.read_test_file('sane_list_python_markdown.md')
converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension])
expected_string = self.read_test_file('sane_list_python_markdown_expected.html')
self.assertEqual(expected_string, converted_test_string)
24 changes: 24 additions & 0 deletions verto/tests/PanelTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,30 @@ def test_contains_inner_image(self):
expected_string = self.read_test_file(self.processor_name, 'contains_inner_image_expected.html', strip=True)
self.assertEqual(expected_string, converted_test_string)

def test_panel_in_numbered_list(self):
'''Tests that panels and containers work within numbered lists.
'''
test_string = self.read_test_file(self.processor_name, 'panel_in_numbered_list.md')
blocks = self.to_blocks(test_string)

self.assertListEqual([False, False, False, True, False, True, False], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string))

converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension])
expected_string = self.read_test_file(self.processor_name, 'panel_in_numbered_list_expected.html', strip=True)
self.assertEqual(expected_string, converted_test_string)

def test_panel_only_in_numbered_list(self):
'''Tests that panels and containers work within numbered lists.
'''
test_string = self.read_test_file(self.processor_name, 'panel_only_in_numbered_list.md')
blocks = self.to_blocks(test_string)

self.assertListEqual([False, False, False, False, True, False], [self.block_processor.test(blocks, block) for block in blocks], msg='"{}"'.format(test_string))

converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension])
expected_string = self.read_test_file(self.processor_name, 'panel_only_in_numbered_list_expected.html', strip=True)
self.assertEqual(expected_string, converted_test_string)

#~
# Doc Tests
#~
Expand Down
13 changes: 13 additions & 0 deletions verto/tests/StyleTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,16 @@ def test_doc_example_block_valid(self):
'''
test_string = self.read_test_file(self.processor_name, 'doc_example_block_valid.md')
converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension])

def test_doc_example_block_valid_in_list(self):
'''A valid example of using container tags.
'''
test_string = self.read_test_file(self.processor_name, 'doc_example_block_valid_in_list.md')
converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension])

def test_doc_example_block_error_in_list(self):
'''A valid example of using container tags.
'''
test_string = self.read_test_file(self.processor_name, 'doc_example_block_error_in_list.md')
with self.assertRaises(StyleError):
converted_test_string = markdown.markdown(test_string, extensions=[self.verto_extension])
7 changes: 7 additions & 0 deletions verto/tests/assets/markdown-override/ordered_list_loose.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Numbered loose:

1. Lipsum

2. Lorem

3. Ipsem
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<p>
Numbered loose:
</p>
<ol>
<li>
<p>
Lipsum
</p>
</li>
<li>
<p>
Lorem
</p>
</li>
<li>
<p>
Ipsem
</p>
</li>
</ol>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
1. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed luctus augue non nisi commodo volutpat.
Aliquam erat volutpat. Class aptent.

2. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Aenean et ligula gravida, tempor massa et, pulvinar tortor.

3. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus vestibulum sollicitudin purus nec auctor.

Sed sed tortor tempus, ullamcorper lorem in, elementum nisl. Phasellus non nibh ligula.

Phasellus vestibulum turpis vel tortor semper egestas. Cras eu maximus lorem.

Curabitur ultrices egestas libero, ut dictum enim porta in. Pellentesque habitant morbi.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<ol>
<li>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed luctus augue non nisi commodo volutpat.
Aliquam erat volutpat. Class aptent.
</p>
</li>
<li>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<p>
Aenean et ligula gravida, tempor massa et, pulvinar tortor.
</p>
</li>
<li>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus vestibulum sollicitudin purus nec auctor.
</p>
<p>
Sed sed tortor tempus, ullamcorper lorem in, elementum nisl. Phasellus non nibh ligula.
</p>
<p>
Phasellus vestibulum turpis vel tortor semper egestas. Cras eu maximus lorem.
</p>
<p>
Curabitur ultrices egestas libero, ut dictum enim porta in. Pellentesque habitant morbi.
</p>
</li>
</ol>
Loading

0 comments on commit 6ac4003

Please sign in to comment.