Module:Hatnote group/doc

MyWikiBiz, Author Your Legacy — Friday April 19, 2024
Jump to navigationJump to search

This is the documentation page for Module:Hatnote group

Implements {{hatnote group}}, for merging multiple hatnotes into a grouped hatnote.

Technical details

The module attempts to find each hatnote-looking div element, and parse them into space-separated span 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. selfreference from a {{self reference}} hatnote, or any classes from the extraclasses parameter of {{hatnote}}).

It also separately looks for all categories in case they're present outside the hatnote div 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 span element that includes the extra classes associated with that row, the spans 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.