Allow `copyright` to contain multiple entries (#10983)

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
Stefanie Molin
2023-05-11 17:43:48 -04:00
committed by GitHub
parent 86b07d4a97
commit e09d02e440
8 changed files with 63 additions and 8 deletions

View File

@@ -33,6 +33,8 @@ Features added
This behaviour may also be controlled by options on object description
directives, for example :rst:dir:`py:function:single-line-parameter-list`.
Patch by Thomas Louf, Adam Turner, and Jean-François Burnol.
* #10983: Support for multiline copyright statements in the footer block.
Patch by Stefanie Molin
Bugs fixed
----------

View File

@@ -54,7 +54,7 @@
{%- block footer %}
<div class="footer" role="contentinfo">
{% trans path=pathto('copyright'), copyright=copyright|e %}&#169; <a href="{{ path }}">Copyright</a> {{ copyright }}.{% endtrans %}
{{ copyright_block() }}
{% trans sphinx_version=sphinx_version|e %}Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> {{ sphinx_version }}.{% endtrans %}
</div>
{%- endblock %}

View File

@@ -73,6 +73,10 @@ Project information
A copyright statement in the style ``'2008, Author Name'``.
.. versionchanged:: 7.1
The value may now be a sequence of copyright statements in the above form,
which will be displayed each to their own line.
.. confval:: project_copyright
An alias of :confval:`copyright`.

View File

@@ -89,8 +89,8 @@ class Config:
# general options
'project': ('Python', 'env', []),
'author': ('unknown', 'env', []),
'project_copyright': ('', 'html', [str]),
'copyright': (lambda c: c.project_copyright, 'html', [str]),
'project_copyright': ('', 'html', [str, tuple, list]),
'copyright': (lambda c: c.project_copyright, 'html', [str, tuple, list]),
'version': ('', 'env', []),
'release': ('', 'env', []),
'today': ('', 'env', []),

View File

@@ -183,14 +183,30 @@
{%- block relbar2 %}{{ relbar() }}{% endblock %}
{%- macro copyright_block() %}
{%- if hasdoc('copyright') %}
{%- set copyright_prefix = '<a href="' + pathto('copyright') + '">' + _('Copyright') + '</a>' -%}
{%- else %}
{%- set copyright_prefix = _('Copyright') %}
{%- endif %}
{%- if copyright is iterable and copyright is not string %}
{% for copyright_line in copyright %}
{% trans trimmed copyright_prefix=copyright_prefix, copyright=copyright_line|e %}
&#169; {{ copyright_prefix }} {{ copyright }}.
{% endtrans %}
{%- if not loop.last %}<br/>{%- endif %}
{% endfor %}
{%- else %}
{% trans trimmed copyright_prefix=copyright_prefix, copyright=copyright|e %}
&#169; {{ copyright_prefix }} {{ copyright }}.
{% endtrans %}
{%- endif %}
{%- endmacro %}
{%- block footer %}
<div class="footer" role="contentinfo">
{%- if show_copyright %}
{%- if hasdoc('copyright') %}
{% trans path=pathto('copyright'), copyright=copyright|e %}&#169; <a href="{{ path }}">Copyright</a> {{ copyright }}.{% endtrans %}
{%- else %}
{% trans copyright=copyright|e %}&#169; Copyright {{ copyright }}.{% endtrans %}
{%- endif %}
{{- copyright_block() -}}
{%- endif %}
{%- if last_updated %}
{% trans last_updated=last_updated|e %}Last updated on {{ last_updated }}.{% endtrans %}

View File

@@ -0,0 +1,8 @@
copyright = (
'2006-2009, Alice',
'2010-2013, Bob',
'2014-2017, Charlie',
'2018-2021, David',
'2022-2025, Eve',
)
html_theme = 'basic'

View File

@@ -0,0 +1,3 @@
========================
test-copyright-multiline
========================

View File

@@ -442,3 +442,25 @@ def test_conf_py_nitpick_ignore_list(tempdir):
# Then the default nitpick_ignore[_regex] is an empty list
assert cfg.nitpick_ignore == []
assert cfg.nitpick_ignore_regex == []
@pytest.mark.sphinx(testroot='copyright-multiline')
def test_multi_line_copyright(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'index.html').read_text(encoding='utf-8')
assert ' &#169; Copyright 2006-2009, Alice.<br/>' in content
assert ' &#169; Copyright 2010-2013, Bob.<br/>' in content
assert ' &#169; Copyright 2014-2017, Charlie.<br/>' in content
assert ' &#169; Copyright 2018-2021, David.<br/>' in content
assert ' &#169; Copyright 2022-2025, Eve.' in content
lines = (
' &#169; Copyright 2006-2009, Alice.<br/>\n \n'
' &#169; Copyright 2010-2013, Bob.<br/>\n \n'
' &#169; Copyright 2014-2017, Charlie.<br/>\n \n'
' &#169; Copyright 2018-2021, David.<br/>\n \n'
' &#169; Copyright 2022-2025, Eve.\n \n'
)
assert lines in content