Skip to content

Commit

Permalink
Merge branch '3.0.x' into 6564_table_width
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Mar 30, 2020
2 parents 49063aa + faf7280 commit 015def3
Show file tree
Hide file tree
Showing 17 changed files with 7,079 additions and 98 deletions.
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Deprecated
Features added
--------------

* Added ``ObjectDescription.transform_content()``.

Bugs fixed
----------

Expand All @@ -23,6 +25,11 @@ Bugs fixed
* #7368: C++, comma operator in expressions, pack expansion in template
argument lists, and more comprehensive error messages in some cases.
* C, C++, fix crash and wrong duplicate warnings related to anon symbols.
* #6477: Escape first "!" in a cross reference linking no longer possible
* #7219: py domain: The index entry generated by ``py:function`` directive is
different with one from ``index`` directive with "builtin" type
* #7301: capital characters are not allowed for node_id
* #7301: epub: duplicated node_ids are generated
* #6564: html: a width of table was ignored on HTML builder

Testing
Expand Down
23 changes: 12 additions & 11 deletions sphinx/builders/_epub_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ def fix_ids(self, tree: nodes.document) -> None:
Some readers crash because they interpret the part as a
transport protocol specification.
"""
def update_node_id(node: Element) -> None:
"""Update IDs of given *node*."""
new_ids = []
for node_id in node['ids']:
new_id = self.fix_fragment('', node_id)
if new_id not in new_ids:
new_ids.append(new_id)
node['ids'] = new_ids

for reference in tree.traverse(nodes.reference):
if 'refuri' in reference:
m = self.refuri_re.match(reference['refuri'])
Expand All @@ -268,22 +277,14 @@ def fix_ids(self, tree: nodes.document) -> None:
reference['refid'] = self.fix_fragment('', reference['refid'])

for target in tree.traverse(nodes.target):
for i, node_id in enumerate(target['ids']):
if ':' in node_id:
target['ids'][i] = self.fix_fragment('', node_id)
update_node_id(target)

next_node = target.next_node(ascend=True) # type: Node
if isinstance(next_node, nodes.Element):
for i, node_id in enumerate(next_node['ids']):
if ':' in node_id:
next_node['ids'][i] = self.fix_fragment('', node_id)
update_node_id(next_node)

for desc_signature in tree.traverse(addnodes.desc_signature):
ids = desc_signature.attributes['ids']
newids = []
for id in ids:
newids.append(self.fix_fragment('', id))
desc_signature.attributes['ids'] = newids
update_node_id(desc_signature)

def add_visible_links(self, tree: nodes.document, show_urls: str = 'inline') -> None:
"""Add visible link targets for external links"""
Expand Down
10 changes: 10 additions & 0 deletions sphinx/directives/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ def before_content(self) -> None:
"""
pass

def transform_content(self, contentnode: addnodes.desc_content) -> None:
"""
Called after creating the content through nested parsing,
but before the ``object-description-transform`` event is emitted,
and before the info-fields are transformed.
Can be used to manipulate the content.
"""
pass

def after_content(self) -> None:
"""
Called after parsing content. Used to reset information about the
Expand Down Expand Up @@ -198,6 +207,7 @@ def run(self) -> List[Node]:
self.env.temp_data['object'] = self.names[0]
self.before_content()
self.state.nested_parse(self.content, self.content_offset, contentnode)
self.transform_content(contentnode)
self.env.app.emit('object-description-transform',
self.domain, self.objtype, contentnode)
DocFieldTransformer(self).transform_all(contentnode)
Expand Down
21 changes: 16 additions & 5 deletions sphinx/domains/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,12 +551,23 @@ def get_signature_prefix(self, sig: str) -> str:
def needs_arglist(self) -> bool:
return True

def get_index_text(self, modname: str, name_cls: Tuple[str, str]) -> str:
def add_target_and_index(self, name_cls: Tuple[str, str], sig: str,
signode: desc_signature) -> None:
super().add_target_and_index(name_cls, sig, signode)
modname = self.options.get('module', self.env.ref_context.get('py:module'))
node_id = signode['ids'][0]

name, cls = name_cls
if modname:
return _('%s() (in module %s)') % (name, modname)
text = _('%s() (in module %s)') % (name, modname)
self.indexnode['entries'].append(('single', text, node_id, '', None))
else:
return _('%s() (built-in function)') % name
text = '%s; %s()' % (pairindextypes['builtin'], name)
self.indexnode['entries'].append(('pair', text, node_id, '', None))

def get_index_text(self, modname: str, name_cls: Tuple[str, str]) -> str:
# add index in own add_target_and_index() instead.
return None


class PyDecoratorFunction(PyFunction):
Expand Down Expand Up @@ -915,8 +926,8 @@ def run(self) -> List[Node]:
# the platform and synopsis aren't printed; in fact, they are only
# used in the modindex currently
ret.append(target)
indextext = _('%s (module)') % modname
inode = addnodes.index(entries=[('single', indextext, node_id, '', None)])
indextext = '%s; %s' % (pairindextypes['module'], modname)
inode = addnodes.index(entries=[('pair', indextext, node_id, '', None)])
ret.append(inode)
return ret

Expand Down

0 comments on commit 015def3

Please sign in to comment.