Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle badly nested bullets #116

Merged
merged 3 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e 'git+https://git@github.com/laws-africa/cobalt.git@master#egg=cobalt'
pip install 'git+https://git@github.com/laws-africa/cobalt.git@master#egg=cobalt'
pip install -e '.[test]'
- name: Test with nosetests
run: nosetests
6 changes: 5 additions & 1 deletion bluebell/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,11 @@ def to_dict(self):
kids.append(empty_p())

if self.content.text:
kids.extend(k.to_dict() for k in self.content.siblings)
for kid in self.content.siblings:
if hasattr(kid, 'to_dict'):
kids.append(kid.to_dict())
else:
kids.extend(kid.to_children())

return {
'type': 'element',
Expand Down
64 changes: 64 additions & 0 deletions tests/test_bullet_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,68 @@ def test_non_starred_items(self):
<p eId="ul_1__li_5__p_1">no star 3</p>
</li>
</ul>
""", xml)

def test_bad_bullets_with_hier(self):
tree = self.parse("""
BULLETS

PARA 24.

SUBPARA i.

Bar
""", 'judgment')

self.assertEqual({
'attribs': {'name': 'judgment'},
'children': [
{'name': 'header', 'type': 'element'},
{'children': [{
'children': [{
'children': [{
'children': [{
'children': [{'type': 'text', 'value': 'PARA 24.'}],
'name': 'p',
'type': 'content'
}, {
'children': [{'type': 'text', 'value': 'SUBPARA i.'}],
'name': 'p',
'type': 'content'
}, {
'children': [{'type': 'text', 'value': 'Bar'}],
'name': 'p',
'type': 'content'
}],
'name': 'li',
'type': 'element'
}],
'name': 'ul',
'type': 'block'}
],
'name': 'arguments',
'type': 'element'}
],
'name': 'judgmentBody',
'type': 'element'}],
'name': 'judgment',
'type': 'element'
}, tree.to_dict())

xml = self.tostring(self.to_xml(tree.to_dict()))

self.assertEqual("""<judgment xmlns="http://docs.oasis-open.org/legaldocml/ns/akn/3.0" name="judgment">
<header/>
<judgmentBody>
<arguments>
<ul eId="arguments__ul_1">
<li eId="arguments__ul_1__li_1">
<p eId="arguments__ul_1__li_1__p_1">PARA 24.</p>
<p eId="arguments__ul_1__li_1__p_2">SUBPARA i.</p>
<p eId="arguments__ul_1__li_1__p_3">Bar</p>
</li>
</ul>
</arguments>
</judgmentBody>
</judgment>
""", xml)