@@ -10,6 +10,10 @@ class TagRenderer
1010 private static int $ subsubsecNum = 0 ;
1111 private static int $ parNum = 0 ;
1212
13+ private static ?string $ context = null ;
14+ private static ?string $ subContext = null ;
15+ private static ?int $ entityId = null ;
16+
1317 private static function getContent ($ tagChildren , $ removeNewLines = true )
1418 {
1519 if (is_string ($ tagChildren ))
@@ -104,8 +108,10 @@ private static function getNumByDepth($depth, $override = -1)
104108
105109 }
106110
107- private static function renderTag ($ depth , $ tagChildren , $ tagOption , $ entity )
111+ private static function renderTag ($ depth , $ tagChildren , $ tagOption ,
112+ $ entity , \XF \BbCode \Renderer \AbstractRenderer $ renderer )
108113 {
114+ self ::resetCountersIfNeeded ($ entity , $ renderer );
109115 $ content = self ::getContent ($ tagChildren );
110116 $ depth = max ($ depth , 0 );
111117 $ depth = min ($ depth , 4 );
@@ -121,10 +127,10 @@ private static function renderTag($depth, $tagChildren, $tagOption, $entity)
121127 $ num = '' ;
122128 if (!empty ($ options ['enumerate ' ]))
123129 $ num .= self ::getNumByDepth ($ depth , $ options ['overrideNum ' ] ?? -1 );
124- $ uniqueId = self ::getEntityId ( $ entity ) . '- ' . str_replace ('. ' , '- ' , $ num );
130+ $ uniqueId = self ::$ entityId . '- ' . str_replace ('. ' , '- ' , $ num );
125131 $ anchorId = self ::getAnchorId ($ uniqueId , $ tagChildren );
126132 if (strlen ($ num ) > 0 )
127- $ num .= ' | ' ;
133+ $ num .= ' ' ;
128134 return "< $ tag class= \"$ htmlClass \" id= \"$ anchorId \"> $ num$ content</ $ tag> " ;
129135 }
130136
@@ -161,54 +167,44 @@ public static function renderChapterTag($tagChildren, $tagOption, $tag,
161167 array $ options , \XF \BbCode \Renderer \AbstractRenderer $ renderer )
162168 {
163169 return self ::renderTag (0 , $ tagChildren , $ tagOption ,
164- $ options ['entity ' ]);
170+ $ options ['entity ' ], $ renderer );
165171 }
166172
167173 public static function renderSectionTag ($ tagChildren , $ tagOption , $ tag ,
168174 array $ options , \XF \BbCode \Renderer \AbstractRenderer $ renderer )
169175 {
170176 return self ::renderTag (1 , $ tagChildren , $ tagOption ,
171- $ options ['entity ' ]);
177+ $ options ['entity ' ], $ renderer );
172178 }
173179
174180 public static function renderSubsectionTag ($ tagChildren , $ tagOption ,
175181 $ tag , array $ options ,
176182 \XF \BbCode \Renderer \AbstractRenderer $ renderer )
177183 {
178184 return self ::renderTag (2 , $ tagChildren , $ tagOption ,
179- $ options ['entity ' ]);
185+ $ options ['entity ' ], $ renderer );
180186 }
181187
182188 public static function renderSubsubsectionTag ($ tagChildren , $ tagOption ,
183189 $ tag , array $ options ,
184190 \XF \BbCode \Renderer \AbstractRenderer $ renderer )
185191 {
186192 return self ::renderTag (3 , $ tagChildren , $ tagOption ,
187- $ options ['entity ' ]);
193+ $ options ['entity ' ], $ renderer );
188194 }
189195
190196 public static function renderParagraphTag ($ tagChildren , $ tagOption , $ tag ,
191197 array $ options , \XF \BbCode \Renderer \AbstractRenderer $ renderer )
192198 {
193199 return self ::renderTag (4 , $ tagChildren , $ tagOption ,
194- $ options ['entity ' ]);
200+ $ options ['entity ' ], $ renderer );
195201 }
196202
197203 public static function renderTocTag ($ tagChildren , $ tagOption , $ tag ,
198204 array $ options , \XF \BbCode \Renderer \AbstractRenderer $ renderer )
199205 {
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 ' );
208206 return $ renderer ->getTemplater ()->renderTemplate (
209- 'public:if_toc_bb_code_tag_toc ' , [
210- 'showTitle ' => !$ hideTitle ,
211- ]);
207+ 'public:if_toc_bb_code_tag_toc ' );
212208 }
213209
214210 private static function resetCounters ($ depth = 0 )
@@ -226,4 +222,30 @@ private static function resetCounters($depth = 0)
226222 self ::$ parNum = 0 ;
227223 }
228224 }
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+ }
229251}
0 commit comments