From e6417f64b74acfa18dd91310994637fbc2c07fc8 Mon Sep 17 00:00:00 2001 From: Evangelos Ribeiro Tzaras Date: Tue, 6 Aug 2024 18:13:33 +0200 Subject: [PATCH] Allow figure dash and en dash as year separator in copyright These are valid characters to denote ranges. --- sphinx/config.py | 4 +++- tests/test_config/test_correct_year.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sphinx/config.py b/sphinx/config.py index bd5941e2cae..f43daccc4bb 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -651,6 +651,8 @@ def _substitute_copyright_year(copyright_line: str, replace_year: str) -> str: * ``YYYY-YYYY,`` * ``YYYY-YYYY `` + The dash in year ranges may also be figure-dash (U+2012) or en-dash (U+2013). + The final year in the string is replaced with ``replace_year``. """ if len(copyright_line) < 4 or not copyright_line[:4].isdigit(): @@ -659,7 +661,7 @@ def _substitute_copyright_year(copyright_line: str, replace_year: str) -> str: if copyright_line[4:5] in {'', ' ', ','}: return replace_year + copyright_line[4:] - if copyright_line[4] != '-': + if copyright_line[4] != '-' and copyright_line[4] != '‒' and copyright_line[4] != '–': return copyright_line if copyright_line[5:9].isdigit() and copyright_line[9:10] in {'', ' ', ','}: diff --git a/tests/test_config/test_correct_year.py b/tests/test_config/test_correct_year.py index 4ef77a6f5ff..343c412235a 100644 --- a/tests/test_config/test_correct_year.py +++ b/tests/test_config/test_correct_year.py @@ -9,6 +9,10 @@ # test with SOURCE_DATE_EPOCH set: copyright year should be updated ('1293840000', '2006-2011'), ('1293839999', '2006-2010'), + # figure dash (U+2012) + ('1293840000', '2006‒2011'), + # en dash (U+2013) + ('1293840000', '2006–2011'), ], )