Module:Hatnote group/doc

&#x3c;!-- Please place categories where indicated at the bottom of this page and interwikis at Wikidata (see Wikidata) --&#x3e; Implements hatnote group, for merging multiple hatnotes into a grouped hatnote.

Technical details
The module attempts to find each hatnote-looking &#x3c;code&#x3e;div&#x3c;/code&#x3e; element, and parse them into space-separated &#x3c;code&#x3e;span&#x3c;/code&#x3e; elements wrapped in a larger, generic hatnote.

First, it matches every pattern that "looks like a hatnote" in its input text; this is where most problems are likely to originate as the pattern is fairly sensitive to any difference in the form of a hatnote.

From each of the pattern matches, it constructs a table. Each element ("row") of the table corresponds to one original hatnote, and is a table that contains a string with the rendered inner content of the hatnote, and an inner table containing any "extra" classes associated with that hatnote (e.g. &#x3c;code&#x3e;selfreference&#x3c;/code&#x3e; from a self reference hatnote, or any classes from the &#x3c;code&#x3e;extraclasses&#x3c;/code&#x3e; parameter of hatnote).

It also separately looks for all categories in case they're present outside the hatnote &#x3c;code&#x3e;div&#x3c;/code&#x3e; element, and adds them to a concatenated string of all "loose categories" to make sure they're not accidentally removed by the hatnote grouping process.

Once all rows are available, it looks at the tables of classes. It adds every class from every row into a table of "universal" classes, then filters out the ones that aren't universal by looking at each row's list and eliminating an item if it isn't present in any one row. Then, "universal" classes are removed from each row's classes table, so that they're not duplicated later.

This processing having been done, each row is formatted with a &#x3c;code&#x3e;span&#x3c;/code&#x3e; element that includes the extra classes associated with that row, the &#x3c;code&#x3e;spans&#x3c;/code&#x3e; for each row are joined as a space-separated list, the "loose categories" are tacked on in turn, and then the resulting string is fed into the main hatnote module, with extra classes on the main hatnote being supplied by collating the "universal classes" table into a space-separated list of its keys.

&#x3c;includeonly&#x3e;&#x3c;/includeonly&#x3e;