Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1dd152d

Browse files
committed
Added support to handle \versionadded in a reasonable way.
1 parent 170e190 commit 1dd152d

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

Doc/tools/sgmlconv/docfixer.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,10 @@ def rewrite_descriptor(doc, descriptor):
155155
# 2. Create a <signature> from the name attribute and <args>.
156156
# 3. Create additional <signature>s from <*line{,ni}> elements,
157157
# if found.
158-
# 4. Move remaining child nodes to a <description> element.
159-
# 5. Put it back together.
158+
# 4. If a <versionadded> is found, move it to an attribute on the
159+
# descriptor.
160+
# 5. Move remaining child nodes to a <description> element.
161+
# 6. Put it back together.
160162
#
161163
descname = descriptor.tagName
162164
index = 1
@@ -200,24 +202,29 @@ def rewrite_descriptor(doc, descriptor):
200202
signature.appendChild(doc.createTextNode("\n "))
201203
signature.appendChild(args)
202204
signature.appendChild(doc.createTextNode("\n "))
203-
# 3.
205+
# 3, 4.
204206
pos = skip_leading_nodes(children, pos + 1)
205207
while pos < len(children) \
206208
and children[pos].nodeType == xml.dom.core.ELEMENT \
207-
and children[pos].tagName == linename:
208-
# this is really a supplemental signature, create <signature>
209-
sig = methodline_to_signature(doc, children[pos])
210-
newchildren.append(sig)
209+
and children[pos].tagName in (linename, "versionadded"):
210+
if children[pos].tagName == linename:
211+
# this is really a supplemental signature, create <signature>
212+
sig = methodline_to_signature(doc, children[pos])
213+
newchildren.append(sig)
214+
else:
215+
# <versionadded added=...>
216+
descriptor.setAttribute(
217+
"added", children[pos].getAttribute("version"))
211218
pos = skip_leading_nodes(children, pos + 1)
212-
# 4.
219+
# 5.
213220
description = doc.createElement("description")
214221
description.appendChild(doc.createTextNode("\n"))
215222
newchildren.append(description)
216223
move_children(descriptor, description, pos)
217224
last = description.childNodes[-1]
218225
if last.nodeType == xml.dom.core.TEXT:
219226
last.data = string.rstrip(last.data) + "\n "
220-
# 5.
227+
# 6.
221228
# should have nothing but whitespace and signature lines in <descriptor>;
222229
# discard them
223230
while descriptor.childNodes:
@@ -408,6 +415,9 @@ def create_module_info(doc, section):
408415
typenode = doc.createElement("type")
409416
typenode.appendChild(doc.createTextNode(type))
410417
modinfo.appendChild(typenode)
418+
versionadded = extract_first_element(section, "versionadded")
419+
if versionadded:
420+
modinfo.setAttribute("added", versionadded.getAttribute("version"))
411421
title = get_first_element(section, "title")
412422
if title:
413423
children = title.childNodes

0 commit comments

Comments
 (0)