[Home]WikiPatches/SeparateCounters

UseModWiki | WikiPatches | RecentChanges | Preferences

Arbitrary Named Counters

Often I've wanted to keep separate running counters going for a page that aren't necessarily adjacent in text, nor an ordered list. Turns out it's easy to implement. Add a %Counters global and then add

    s/([^#])#(\w+)#/$1 . ++$Counters{$2}/ge;
to CommonMarkup. I did this just after the <tt> expression. This will match things like #foo# #foo# #bar# #foo# #bar# in the text, emitting 1 2 1 3 2. -- SunirShah
I'll vote for this
Minor tweak with zero-padding:
 s/([^#])#(\w+)#/$1 .((($Counters{$2}) < 9)?"0":""). ++$Counters{$2}/ge;
--JuanmaMP

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited August 26, 2009 7:28 pm by JuanmaMP (diff)
Search: