@@ -10,6 +10,10 @@ class TagRenderer
10
10
private static int $ subsubsecNum = 0 ;
11
11
private static int $ parNum = 0 ;
12
12
13
+ private static ?string $ context = null ;
14
+ private static ?string $ subContext = null ;
15
+ private static ?int $ entityId = null ;
16
+
13
17
private static function getContent ($ tagChildren , $ removeNewLines = true )
14
18
{
15
19
if (is_string ($ tagChildren ))
@@ -104,8 +108,10 @@ private static function getNumByDepth($depth, $override = -1)
104
108
105
109
}
106
110
107
- private static function renderTag ($ depth , $ tagChildren , $ tagOption , $ entity )
111
+ private static function renderTag ($ depth , $ tagChildren , $ tagOption ,
112
+ $ entity , \XF \BbCode \Renderer \AbstractRenderer $ renderer )
108
113
{
114
+ self ::resetCountersIfNeeded ($ entity , $ renderer );
109
115
$ content = self ::getContent ($ tagChildren );
110
116
$ depth = max ($ depth , 0 );
111
117
$ depth = min ($ depth , 4 );
@@ -121,10 +127,10 @@ private static function renderTag($depth, $tagChildren, $tagOption, $entity)
121
127
$ num = '' ;
122
128
if (!empty ($ options ['enumerate ' ]))
123
129
$ num .= self ::getNumByDepth ($ depth , $ options ['overrideNum ' ] ?? -1 );
124
- $ uniqueId = self ::getEntityId ( $ entity ) . '- ' . str_replace ('. ' , '- ' , $ num );
130
+ $ uniqueId = self ::$ entityId . '- ' . str_replace ('. ' , '- ' , $ num );
125
131
$ anchorId = self ::getAnchorId ($ uniqueId , $ tagChildren );
126
132
if (strlen ($ num ) > 0 )
127
- $ num .= ' | ' ;
133
+ $ num .= ' ' ;
128
134
return "< $ tag class= \"$ htmlClass \" id= \"$ anchorId \"> $ num$ content</ $ tag> " ;
129
135
}
130
136
@@ -161,54 +167,44 @@ public static function renderChapterTag($tagChildren, $tagOption, $tag,
161
167
array $ options , \XF \BbCode \Renderer \AbstractRenderer $ renderer )
162
168
{
163
169
return self ::renderTag (0 , $ tagChildren , $ tagOption ,
164
- $ options ['entity ' ]);
170
+ $ options ['entity ' ], $ renderer );
165
171
}
166
172
167
173
public static function renderSectionTag ($ tagChildren , $ tagOption , $ tag ,
168
174
array $ options , \XF \BbCode \Renderer \AbstractRenderer $ renderer )
169
175
{
170
176
return self ::renderTag (1 , $ tagChildren , $ tagOption ,
171
- $ options ['entity ' ]);
177
+ $ options ['entity ' ], $ renderer );
172
178
}
173
179
174
180
public static function renderSubsectionTag ($ tagChildren , $ tagOption ,
175
181
$ tag , array $ options ,
176
182
\XF \BbCode \Renderer \AbstractRenderer $ renderer )
177
183
{
178
184
return self ::renderTag (2 , $ tagChildren , $ tagOption ,
179
- $ options ['entity ' ]);
185
+ $ options ['entity ' ], $ renderer );
180
186
}
181
187
182
188
public static function renderSubsubsectionTag ($ tagChildren , $ tagOption ,
183
189
$ tag , array $ options ,
184
190
\XF \BbCode \Renderer \AbstractRenderer $ renderer )
185
191
{
186
192
return self ::renderTag (3 , $ tagChildren , $ tagOption ,
187
- $ options ['entity ' ]);
193
+ $ options ['entity ' ], $ renderer );
188
194
}
189
195
190
196
public static function renderParagraphTag ($ tagChildren , $ tagOption , $ tag ,
191
197
array $ options , \XF \BbCode \Renderer \AbstractRenderer $ renderer )
192
198
{
193
199
return self ::renderTag (4 , $ tagChildren , $ tagOption ,
194
- $ options ['entity ' ]);
200
+ $ options ['entity ' ], $ renderer );
195
201
}
196
202
197
203
public static function renderTocTag ($ tagChildren , $ tagOption , $ tag ,
198
204
array $ options , \XF \BbCode \Renderer \AbstractRenderer $ renderer )
199
205
{
200
- //$renderer->getTemplater()->includeJs([
201
- // 'src' => 'inforge/posttoc/toc-renderer.js',
202
- // 'addon' => 'Inforge/PostTOC',
203
- // 'min' => true,
204
- // ]);
205
- self ::resetCounters ();
206
- $ hideTitle = !empty ($ tagOption ) &&
207
- (strtolower (trim ($ tagOption )) == 'notitle ' );
208
206
return $ renderer ->getTemplater ()->renderTemplate (
209
- 'public:if_toc_bb_code_tag_toc ' , [
210
- 'showTitle ' => !$ hideTitle ,
211
- ]);
207
+ 'public:if_toc_bb_code_tag_toc ' );
212
208
}
213
209
214
210
private static function resetCounters ($ depth = 0 )
@@ -226,4 +222,30 @@ private static function resetCounters($depth = 0)
226
222
self ::$ parNum = 0 ;
227
223
}
228
224
}
225
+
226
+ private static function resetCountersIfNeeded ($ entity ,
227
+ \XF \BbCode \Renderer \AbstractRenderer $ renderer )
228
+ {
229
+ $ curId = self ::getEntityId ($ entity );
230
+ $ curContext = self ::getCurrentContext ($ renderer );
231
+ $ curSubContext = self ::getCurrentSubContext ($ renderer );
232
+ if (self ::$ entityId !== $ curId
233
+ || self ::$ context !== $ curContext
234
+ || self ::$ subContext !== $ curSubContext ) {
235
+ self ::$ entityId = $ curId ;
236
+ self ::$ context = $ curContext ;
237
+ self ::$ subContext = $ curSubContext ;
238
+ self ::resetCounters ();
239
+ }
240
+ }
241
+
242
+ private static function getCurrentContext (\XF \BbCode \Renderer \AbstractRenderer $ renderer )
243
+ {
244
+ return $ renderer ->getRules ()->getContext ();
245
+ }
246
+
247
+ private static function getCurrentSubContext (\XF \BbCode \Renderer \AbstractRenderer $ renderer )
248
+ {
249
+ return $ renderer ->getRules ()->getSubContext ();
250
+ }
229
251
}
0 commit comments