@@ -38,19 +38,47 @@ def setUp(self):
38
38
[
39
39
{
40
40
"type" : "paragraph" ,
41
- "value" : f'<p>This is a paragraph with a footnote. <footnote id="{ uuid } ">1</footnote></p>' ,
41
+ "value" : (
42
+ f'<p>This is a paragraph with a footnote. <footnote id="{ uuid } ">[{ uuid [:6 ]} ]</footnote></p>'
43
+ ),
42
44
},
43
45
]
44
46
),
45
47
)
46
48
home_page .add_child (instance = self .test_page_with_footnote )
47
49
self .test_page_with_footnote .save_revision ().publish ()
48
- self . footnote = Footnote .objects .create (
50
+ Footnote .objects .create (
49
51
page = self .test_page_with_footnote ,
50
52
uuid = uuid ,
51
53
text = "This is a footnote" ,
52
54
)
53
55
56
+ self .test_page_with_multiple_references_to_the_same_footnote = TestPageStreamField (
57
+ title = "Test Page With Multiple References to the Same Footnote" ,
58
+ slug = "test-page-with-multiple-references-to-the-same-footnote" ,
59
+ body = json .dumps (
60
+ [
61
+ {
62
+ "type" : "paragraph" ,
63
+ "value" : (
64
+ f'<p>This is a paragraph with a footnote. <footnote id="{ uuid } ">[{ uuid [:6 ]} ]</footnote></p>'
65
+ f"<p>This is another paragraph with a reference to the same footnote. "
66
+ f'<footnote id="{ uuid } ">[{ uuid [:6 ]} ]</footnote></p>'
67
+ ),
68
+ },
69
+ ]
70
+ ),
71
+ )
72
+ home_page .add_child (
73
+ instance = self .test_page_with_multiple_references_to_the_same_footnote
74
+ )
75
+ self .test_page_with_multiple_references_to_the_same_footnote .save_revision ().publish ()
76
+ Footnote .objects .create (
77
+ page = self .test_page_with_multiple_references_to_the_same_footnote ,
78
+ uuid = uuid ,
79
+ text = "This is a footnote" ,
80
+ )
81
+
54
82
def test_block_with_no_features (self ):
55
83
block = RichTextBlockWithFootnotes ()
56
84
self .assertIsInstance (block , blocks .RichTextBlock )
@@ -103,13 +131,36 @@ def test_block_replace_footnote_render_basic(self):
103
131
value = rtb .get_prep_value (self .test_page_with_footnote .body [0 ].value )
104
132
context = self .test_page_with_footnote .get_context (self .client .get ("/" ))
105
133
out = rtb .render_basic (value , context = context )
106
- result = '<p>This is a paragraph with a footnote. <a href="#footnote-1" id="footnote-source-1"><sup>[1]</sup></a></p>'
134
+ result = (
135
+ '<p>This is a paragraph with a footnote. <a href="#footnote-1" id="footnote-source-1-0"><sup>[1]</sup></a>'
136
+ "</p>"
137
+ )
107
138
self .assertEqual (out , result )
108
139
109
140
def test_block_replace_footnote_render (self ):
110
141
rtb = self .test_page_with_footnote .body .stream_block .child_blocks ["paragraph" ]
111
142
value = rtb .get_prep_value (self .test_page_with_footnote .body [0 ].value )
112
143
context = self .test_page_with_footnote .get_context (self .client .get ("/" ))
113
144
out = rtb .render (value , context = context )
114
- result = '<p>This is a paragraph with a footnote. <a href="#footnote-1" id="footnote-source-1"><sup>[1]</sup></a></p>'
145
+ result = (
146
+ '<p>This is a paragraph with a footnote. <a href="#footnote-1" id="footnote-source-1-0"><sup>[1]</sup></a>'
147
+ "</p>"
148
+ )
149
+ self .assertEqual (out , result )
150
+
151
+ def test_block_replace_footnote_with_multiple_references_render (self ):
152
+ body = self .test_page_with_multiple_references_to_the_same_footnote .body
153
+ rtb = body .stream_block .child_blocks ["paragraph" ]
154
+ value = rtb .get_prep_value (body [0 ].value )
155
+ context = (
156
+ self .test_page_with_multiple_references_to_the_same_footnote .get_context (
157
+ self .client .get ("/" )
158
+ )
159
+ )
160
+ out = rtb .render (value , context = context )
161
+ result = (
162
+ '<p>This is a paragraph with a footnote. <a href="#footnote-1" id="footnote-source-1-0"><sup>[1]</sup></a>'
163
+ '</p><p>This is another paragraph with a reference to the same footnote. <a href="#footnote-1" '
164
+ 'id="footnote-source-1-1"><sup>[1]</sup></a></p>'
165
+ )
115
166
self .assertEqual (out , result )
0 commit comments