diff options
author | Stefanie Molin <24376333+stefmolin@users.noreply.github.com> | 2023-05-11 17:43:48 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-11 22:43:48 +0100 |
commit | e09d02e440691e842377f0ebea7910d307509a81 (patch) | |
tree | 344e4ebf0226f7d78fdb5d3f517f241bc3947407 | |
parent | 86b07d4a97a225e79150d14e25a768ebc4c087cc (diff) | |
download | sphinx-git-e09d02e440691e842377f0ebea7910d307509a81.tar.gz |
Allow ``copyright`` to contain multiple entries (#10983)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | doc/_themes/sphinx13/layout.html | 2 | ||||
-rw-r--r-- | doc/usage/configuration.rst | 4 | ||||
-rw-r--r-- | sphinx/config.py | 4 | ||||
-rw-r--r-- | sphinx/themes/basic/layout.html | 26 | ||||
-rw-r--r-- | tests/roots/test-copyright-multiline/conf.py | 8 | ||||
-rw-r--r-- | tests/roots/test-copyright-multiline/index.rst | 3 | ||||
-rw-r--r-- | tests/test_config.py | 22 |
8 files changed, 63 insertions, 8 deletions
@@ -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 ---------- diff --git a/doc/_themes/sphinx13/layout.html b/doc/_themes/sphinx13/layout.html index 8010517a6..86a794306 100644 --- a/doc/_themes/sphinx13/layout.html +++ b/doc/_themes/sphinx13/layout.html @@ -54,7 +54,7 @@ {%- block footer %} <div class="footer" role="contentinfo"> - {% trans path=pathto('copyright'), copyright=copyright|e %}© <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 %} diff --git a/doc/usage/configuration.rst b/doc/usage/configuration.rst index 1fc4c674b..133e2099d 100644 --- a/doc/usage/configuration.rst +++ b/doc/usage/configuration.rst @@ -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`. diff --git a/sphinx/config.py b/sphinx/config.py index a4e661934..b8cf1eda2 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -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', []), diff --git a/sphinx/themes/basic/layout.html b/sphinx/themes/basic/layout.html index f3088f79a..79eb02de8 100644 --- a/sphinx/themes/basic/layout.html +++ b/sphinx/themes/basic/layout.html @@ -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 %} + © {{ copyright_prefix }} {{ copyright }}. + {% endtrans %} + {%- if not loop.last %}<br/>{%- endif %} + {% endfor %} + {%- else %} + {% trans trimmed copyright_prefix=copyright_prefix, copyright=copyright|e %} + © {{ 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 %}© <a href="{{ path }}">Copyright</a> {{ copyright }}.{% endtrans %} - {%- else %} - {% trans copyright=copyright|e %}© Copyright {{ copyright }}.{% endtrans %} - {%- endif %} + {{- copyright_block() -}} {%- endif %} {%- if last_updated %} {% trans last_updated=last_updated|e %}Last updated on {{ last_updated }}.{% endtrans %} diff --git a/tests/roots/test-copyright-multiline/conf.py b/tests/roots/test-copyright-multiline/conf.py new file mode 100644 index 000000000..24bd0c529 --- /dev/null +++ b/tests/roots/test-copyright-multiline/conf.py @@ -0,0 +1,8 @@ +copyright = ( + '2006-2009, Alice', + '2010-2013, Bob', + '2014-2017, Charlie', + '2018-2021, David', + '2022-2025, Eve', +) +html_theme = 'basic' diff --git a/tests/roots/test-copyright-multiline/index.rst b/tests/roots/test-copyright-multiline/index.rst new file mode 100644 index 000000000..aa32ae60f --- /dev/null +++ b/tests/roots/test-copyright-multiline/index.rst @@ -0,0 +1,3 @@ +======================== +test-copyright-multiline +======================== diff --git a/tests/test_config.py b/tests/test_config.py index ec5d0948f..f01ea0c32 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -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 ' © Copyright 2006-2009, Alice.<br/>' in content + assert ' © Copyright 2010-2013, Bob.<br/>' in content + assert ' © Copyright 2014-2017, Charlie.<br/>' in content + assert ' © Copyright 2018-2021, David.<br/>' in content + assert ' © Copyright 2022-2025, Eve.' in content + + lines = ( + ' © Copyright 2006-2009, Alice.<br/>\n \n' + ' © Copyright 2010-2013, Bob.<br/>\n \n' + ' © Copyright 2014-2017, Charlie.<br/>\n \n' + ' © Copyright 2018-2021, David.<br/>\n \n' + ' © Copyright 2022-2025, Eve.\n \n' + ) + assert lines in content |