Skip to content

Commit f4c6f37

Browse files
committed
Merge branch 'release/3.4.3.0'
2 parents 3f4c69a + 9ddb8e8 commit f4c6f37

5 files changed

Lines changed: 50 additions & 25 deletions

File tree

src/pandoc_numbering/_main.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,20 @@ def _remove_accents(string):
239239
return "".join([c for c in nfkd_form if not unicodedata.combining(c)])
240240

241241
@staticmethod
242-
def _identifier(string):
242+
def identifier(string: str) -> str:
243+
"""
244+
Convert a string to a valid identifier.
245+
246+
Parameters
247+
----------
248+
string
249+
A string to convert.
250+
251+
Returns
252+
-------
253+
str
254+
The corresponding identifier
255+
"""
243256
# replace invalid characters by dash
244257
string = re.sub(
245258
"[^0-9a-zA-Z_-]+", "-", Numbered._remove_accents(string.lower())
@@ -335,7 +348,7 @@ def _compute_description(self):
335348

336349
def _compute_basic_category(self):
337350
if self._match.group("prefix") is None:
338-
self._basic_category = Numbered._identifier(
351+
self._basic_category = Numbered.identifier(
339352
"".join(map(stringify, self._description))
340353
)
341354
else:
@@ -421,13 +434,13 @@ def _compute_alias(self):
421434
+ ":"
422435
+ self._section_alias
423436
+ "."
424-
+ Numbered._identifier(stringify(Span(*self._title)))
437+
+ Numbered.identifier(stringify(Span(*self._title)))
425438
)
426439
else:
427440
self._alias = (
428441
self._basic_category
429442
+ ":"
430-
+ Numbered._identifier(stringify(Span(*self._title)))
443+
+ Numbered.identifier(stringify(Span(*self._title)))
431444
)
432445

433446
def _compute_local_number(self):
@@ -1527,6 +1540,11 @@ def finalize(doc: Doc):
15271540
# pylint: disable=consider-using-f-string
15281541
if doc.format in {"tex", "latex"}:
15291542
latex_category = re.sub("[^a-z]+", "", category)
1543+
text = convert_text(
1544+
Plain(*definition["listing-title"]),
1545+
input_format="panflute",
1546+
output_format="latex",
1547+
)
15301548
latex = (
15311549
r"\newlistof{%s}{%s}{%s}"
15321550
r"\renewcommand{\cft%stitlefont}{\cfttoctitlefont}"
@@ -1535,11 +1553,7 @@ def finalize(doc: Doc):
15351553
% (
15361554
latex_category,
15371555
latex_category,
1538-
convert_text(
1539-
Plain(*definition["listing-title"]),
1540-
input_format="panflute",
1541-
output_format="latex",
1542-
),
1556+
text,
15431557
latex_category,
15441558
latex_category,
15451559
latex_category,
@@ -1548,7 +1562,18 @@ def finalize(doc: Doc):
15481562
doc.metadata["header-includes"].append(
15491563
MetaInlines(RawInline(latex, "tex"))
15501564
)
1551-
listof.append(f"\\listof{latex_category}")
1565+
if definition["listing-identifier"] is False:
1566+
listof.append(f"\\listof{latex_category}")
1567+
elif definition["listing-identifier"] is True:
1568+
listof.append(
1569+
f"\\phantomsection\\label{{{Numbered.identifier(text)}}}"
1570+
f"\\listof{latex_category}"
1571+
)
1572+
else:
1573+
listof.append(
1574+
f"\\phantomsection\\label{{{definition['listing-identifier']}}}"
1575+
f"\\listof{latex_category}"
1576+
)
15521577
else:
15531578
classes = ["pandoc-numbering-listing"] + definition["classes"]
15541579

tests/test__identifier.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/test_identifier.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from unittest import TestCase
2+
3+
from pandoc_numbering import Numbered
4+
5+
6+
class IdentifierTest(TestCase):
7+
def test_identifier(self):
8+
self.assertEqual(Numbered.identifier("0123 Ê à"), "e-a")

tests/test_listings_meta.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def test_listing_latex(self):
178178
`{=tex}
179179
- "`\\usepackage{etoolbox}`{=tex}"
180180
- "`\\newlistof{exercise}{exercise}{List of exercises}\\renewcommand{\\cftexercisetitlefont}{\\cfttoctitlefont}\\setlength{\\cftexercisenumwidth}{\\cftfignumwidth}\\setlength{\\cftexerciseindent}{\\cftfigindent}`{=tex}"
181-
- "`\\ifdef{\\mainmatter}{\\let\\oldmainmatter\\mainmatter\\renewcommand{\\mainmatter}[0]{\\listofexercise\\oldmainmatter}}{}`{=tex}"
181+
- "`\\ifdef{\\mainmatter}{\\let\\oldmainmatter\\mainmatter\\renewcommand{\\mainmatter}[0]{\\phantomsection\\label{list-of-exercises}\\listofexercise\\oldmainmatter}}{}`{=tex}"
182182
pandoc-numbering:
183183
exercise:
184184
general:
@@ -199,9 +199,9 @@ def test_listing_latex(self):
199199
200200
`\newlistof{exercise}{exercise}{List of exercises}\renewcommand{\cftexercisetitlefont}{\cfttoctitlefont}\setlength{\cftexercisenumwidth}{\cftfignumwidth}\setlength{\cftexerciseindent}{\cftfigindent}`{=tex}
201201
202-
`\ifdef{\mainmatter}{\let\oldmainmatter\mainmatter\renewcommand{\mainmatter}[0]{\listofexercise\oldmainmatter}}{}`{=tex}
202+
`\ifdef{\mainmatter}{\let\oldmainmatter\mainmatter\renewcommand{\mainmatter}[0]{\phantomsection\label{list-of-exercises}\listofexercise\oldmainmatter}}{}`{=tex}
203203
204-
`\ifdef{\mainmatter}{}{\listofexercise}`{=tex}
204+
`\ifdef{\mainmatter}{}{\phantomsection\label{list-of-exercises}\listofexercise}`{=tex}
205205
206206
`\phantomsection\addcontentsline{exercise}{exercise}{\protect\numberline {1}{\ignorespaces {Exercise}}}`{=tex}[**Exercise 1**]{#exercise:1 .pandoc-numbering-text .exercise}
207207
@@ -286,7 +286,7 @@ def test_listing_latex_format(self):
286286
`{=tex}
287287
- "`\\usepackage{etoolbox}`{=tex}"
288288
- "`\\newlistof{exercise}{exercise}{List of exercises}\\renewcommand{\\cftexercisetitlefont}{\\cfttoctitlefont}\\setlength{\\cftexercisenumwidth}{\\cftfignumwidth}\\setlength{\\cftexerciseindent}{\\cftfigindent}`{=tex}"
289-
- "`\\ifdef{\\mainmatter}{\\let\\oldmainmatter\\mainmatter\\renewcommand{\\mainmatter}[0]{\\listofexercise\\oldmainmatter}}{}`{=tex}"
289+
- "`\\ifdef{\\mainmatter}{\\let\\oldmainmatter\\mainmatter\\renewcommand{\\mainmatter}[0]{\\phantomsection\\label{list-of-exercises}\\listofexercise\\oldmainmatter}}{}`{=tex}"
290290
pandoc-numbering:
291291
exercise:
292292
general:
@@ -313,9 +313,9 @@ def test_listing_latex_format(self):
313313
314314
`\newlistof{exercise}{exercise}{List of exercises}\renewcommand{\cftexercisetitlefont}{\cfttoctitlefont}\setlength{\cftexercisenumwidth}{\cftfignumwidth}\setlength{\cftexerciseindent}{\cftfigindent}`{=tex}
315315
316-
`\ifdef{\mainmatter}{\let\oldmainmatter\mainmatter\renewcommand{\mainmatter}[0]{\listofexercise\oldmainmatter}}{}`{=tex}
316+
`\ifdef{\mainmatter}{\let\oldmainmatter\mainmatter\renewcommand{\mainmatter}[0]{\phantomsection\label{list-of-exercises}\listofexercise\oldmainmatter}}{}`{=tex}
317317
318-
`\ifdef{\mainmatter}{}{\listofexercise}`{=tex}
318+
`\ifdef{\mainmatter}{}{\phantomsection\label{list-of-exercises}\listofexercise}`{=tex}
319319
320320
`\phantomsection\addcontentsline{exercise}{exercise}{\protect\numberline {1}{\ignorespaces {Exercise}}}`{=tex}[**Exercise 1**]{#exercise:1 .pandoc-numbering-text .exercise}
321321

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)