Skip to content

Commit 4a5201b

Browse files
authored
Merge pull request #51 from amedama41/fix_docutils_tree
Fix generating non well-formed docutils document tree
2 parents 7e02cb4 + a7fa816 commit 4a5201b

2 files changed

Lines changed: 44 additions & 30 deletions

File tree

sphinx_git/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,20 @@ def _build_markup(self, commits):
176176
detailed_message = None
177177

178178
item = nodes.list_item()
179+
par = nodes.paragraph()
179180
# choose detailed message style by detailed-message-strong option
180181
if self.options.get('detailed-message-strong', True):
181-
item += nodes.strong(text=message)
182+
par += nodes.strong(text=message)
182183
else:
183-
item += nodes.inline(text=message)
184+
par += nodes.inline(text=message)
184185

185186
if not self.options.get('hide_author'):
186-
item += [nodes.inline(text=" by "),
187-
nodes.emphasis(text=six.text_type(commit.author))]
187+
par += [nodes.inline(text=" by "),
188+
nodes.emphasis(text=six.text_type(commit.author))]
188189
if not self.options.get('hide_date'):
189-
item += [nodes.inline(text=" at "),
190-
nodes.emphasis(text=str(date_str))]
190+
par += [nodes.inline(text=" at "),
191+
nodes.emphasis(text=str(date_str))]
192+
item.append(par)
191193
if detailed_message and not self.options.get('hide_details'):
192194
detailed_message = detailed_message.strip()
193195
if self.options.get('detailed-message-pre', False):

tests/test_git_changelog.py

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ def test_single_commit_message_and_user_display(self):
6969
list_markup = BeautifulSoup(str(nodes[0]), features='xml')
7070
item = list_markup.bullet_list.list_item
7171
children = list(item.childGenerator())
72-
assert_equal(5, len(children))
73-
assert_equal('my root commit', children[0].text)
74-
assert_equal('Test User', children[2].text)
72+
assert_equal(1, len(children))
73+
par_children = list(item.paragraph.childGenerator())
74+
assert_equal(5, len(par_children))
75+
assert_equal('my root commit', par_children[0].text)
76+
assert_equal('Test User', par_children[2].text)
7577

7678
def test_single_commit_message_and_user_display_with_non_ascii_chars(self):
7779
self._set_username('þéßþ Úßéë')
@@ -80,17 +82,19 @@ def test_single_commit_message_and_user_display_with_non_ascii_chars(self):
8082
list_markup = BeautifulSoup(six.text_type(nodes[0]), features='xml')
8183
item = list_markup.bullet_list.list_item
8284
children = list(item.childGenerator())
83-
assert_equal(5, len(children))
84-
assert_equal('my root commit', children[0].text)
85-
assert_equal(u'þéßþ Úßéë', children[2].text)
85+
assert_equal(1, len(children))
86+
par_children = list(item.paragraph.childGenerator())
87+
assert_equal(5, len(par_children))
88+
assert_equal('my root commit', par_children[0].text)
89+
assert_equal(u'þéßþ Úßéë', par_children[2].text)
8690

8791
def test_single_commit_time_display(self):
8892
before = datetime.now().replace(microsecond=0)
8993
self.repo.index.commit('my root commit')
9094
nodes = self.changelog.run()
9195
after = datetime.now()
9296
list_markup = BeautifulSoup(str(nodes[0]), features='xml')
93-
item = list_markup.bullet_list.list_item
97+
item = list_markup.bullet_list.list_item.paragraph
9498
children = list(item.childGenerator())
9599
timestamp = datetime.strptime(children[4].text, '%Y-%m-%d %H:%M:%S')
96100
assert_less_equal(before, timestamp)
@@ -104,11 +108,13 @@ def test_single_commit_default_detail_setting(self):
104108
list_markup = BeautifulSoup(str(nodes[0]), features='xml')
105109
item = list_markup.bullet_list.list_item
106110
children = list(item.childGenerator())
107-
assert_equal(6, len(children))
108-
assert_equal('my root commit', children[0].text)
109-
assert_equal('Test User', children[2].text)
111+
assert_equal(2, len(children))
112+
par_children = list(item.paragraph.childGenerator())
113+
assert_equal(5, len(par_children))
114+
assert_equal('my root commit', par_children[0].text)
115+
assert_equal('Test User', par_children[2].text)
110116
assert_equal(
111-
str(children[5]),
117+
str(children[1]),
112118
'<paragraph>additional information\nmore info</paragraph>'
113119
)
114120

@@ -121,9 +127,9 @@ def test_single_commit_preformmated_detail_lines(self):
121127
list_markup = BeautifulSoup(str(nodes[0]), features='xml')
122128
item = list_markup.bullet_list.list_item
123129
children = list(item.childGenerator())
124-
assert_equal(6, len(children))
130+
assert_equal(2, len(children))
125131
assert_equal(
126-
str(children[5]),
132+
str(children[1]),
127133
'<literal_block xml:space="preserve">additional information\n'
128134
'more info</literal_block>'
129135
)
@@ -238,9 +244,11 @@ def test_single_commit_hide_details(self):
238244
list_markup = BeautifulSoup(str(nodes[0]), features='xml')
239245
item = list_markup.bullet_list.list_item
240246
children = list(item.childGenerator())
241-
assert_equal(5, len(children))
242-
assert_equal('Another commit', children[0].text)
243-
assert_equal('Test User', children[2].text)
247+
assert_equal(1, len(children))
248+
par_children = list(item.paragraph.childGenerator())
249+
assert_equal(5, len(par_children))
250+
assert_equal('Another commit', par_children[0].text)
251+
assert_equal('Test User', par_children[2].text)
244252

245253
def test_single_commit_message_hide_author(self):
246254
self.repo.index.commit('Yet another commit')
@@ -250,10 +258,12 @@ def test_single_commit_message_hide_author(self):
250258
item = list_markup.bullet_list.list_item
251259
children = list(item.childGenerator())
252260
print(children)
253-
assert_equal(3, len(children))
254-
assert_equal('Yet another commit', children[0].text)
255-
assert_not_in(' by Test User', children[1].text)
256-
assert_in(' at ', children[1].text)
261+
assert_equal(1, len(children))
262+
par_children = list(item.paragraph.childGenerator())
263+
assert_equal(3, len(par_children))
264+
assert_equal('Yet another commit', par_children[0].text)
265+
assert_not_in(' by Test User', par_children[1].text)
266+
assert_in(' at ', par_children[1].text)
257267

258268
def test_single_commit_message_hide_date(self):
259269
self.repo.index.commit('Yet yet another commit')
@@ -263,10 +273,12 @@ def test_single_commit_message_hide_date(self):
263273
item = list_markup.bullet_list.list_item
264274
children = list(item.childGenerator())
265275
print(children)
266-
assert_equal(3, len(children))
267-
assert_equal('Yet yet another commit', children[0].text)
268-
assert_not_in(' at ', children[1].text)
269-
assert_in(' by ', children[1].text)
276+
assert_equal(1, len(children))
277+
par_children = list(item.paragraph.childGenerator())
278+
assert_equal(3, len(par_children))
279+
assert_equal('Yet yet another commit', par_children[0].text)
280+
assert_not_in(' at ', par_children[1].text)
281+
assert_in(' by ', par_children[1].text)
270282

271283

272284
class TestWithOtherRepository(TestWithRepository):

0 commit comments

Comments
 (0)