From 14392e9a73563b0dc4622c0313b6131af725d0ae Mon Sep 17 00:00:00 2001 From: RavSinghChandan Date: Mon, 9 Nov 2026 07:24:20 +0530 Subject: [PATCH] Keep the space before the number in numbering extra captions --- CHANGES.md | 1 + lib/markdown2.py | 2 ++ test/tm-cases/numbering.text | 12 ++++++------ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 10aabd33..25b5a158 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## python-markdown2 2.5.6 (not yet released) +- [pull #770] Fix `numbering` extra dropping the space between the caption text and the number (`Table1` instead of `Table 1`) - [pull #762] Speed up documents with many links by skipping the backslash-escape scan for text without a backslash - [pull #748] Speed up `_unescape_special_chars` by skipping text with no hashes and dropping the full-text comparison per pass (#635) - [pull #749] URL-encode destinations generated by the `link-patterns` extra (#55) diff --git a/lib/markdown2.py b/lib/markdown2.py index d6285404..3f6159ed 100755 --- a/lib/markdown2.py +++ b/lib/markdown2.py @@ -4132,6 +4132,8 @@ def run(self, text: str): continue counter = match.group(1) text_before = match.group(2).strip() + if text_before: + text_before += ' ' ref_id = match.group(3) text_after = match.group(4) number = counters.get(counter, 1) diff --git a/test/tm-cases/numbering.text b/test/tm-cases/numbering.text index 627eef8f..43d5a33b 100644 --- a/test/tm-cases/numbering.text +++ b/test/tm-cases/numbering.text @@ -2,15 +2,15 @@

-
Image 1: Let's Rick Roll You
+[#imagenumbers Image @rickroll: Let's Rick Roll You] -

And we can refer to the rickrolling image as Image 1. There is a second image of something else

+And we can refer to the rickrolling image as Image [@rickroll]. There is a second image of something else

-
Figure 2: I for one welcome our new insect overlords
+[#imagenumbers Figure @kent: I for one welcome our new insect overlords] -

So we can refer to Figure 1 and Figure 2 separately.

+So we can refer to Figure [@rickroll] and Figure [@kent] separately.

Here is a table

@@ -33,8 +33,8 @@ -
Table 1: An example table
+[#tablenumbers Table @exampletable: An example table] -

Which we can refer to as table 1

+Which we can refer to as table [@exampletable]

And so we are done.

\ No newline at end of file