tsackton / taelgar

0 stars 0 forks source link

Improve string formatting #20

Closed msackton closed 9 months ago

msackton commented 9 months ago

This change introduces a new mechanism for formatting strings. The general string formatter supports inserting a number of tokens from the page front matter as follows:

<name> - the name of the page

- the primary affiliations of the page, joined by “and” - the organization this is part of. Follows the organization chain. Will not follow location part ofs - the current whereabout of the page, including following the location chain at the current date, or unknown if there is no current whereabout - the home whereabout of the page, including following the location chain at the current date, or unknown if there is no current whereabout - the origin whereabout of the page, including following the location chain at the page creation date or 0001, if there is no page creation date - the last known whereabout of the page, or the current whereabout if there is no last known whereabout, including following the location chain at the last known or current date, or unknown if there is neither a last known or current whereabout - the population from frontmatter, prefaced with pop. if population is a number - the pronoun from frontmatter or calculated from gender - the end date of a page, ie death or destroyed - the start date of a page, ie birth or creation - the start status - the end status - the current date - the date of the last known whereabout or the current date if there is a current whereabout - the age of the page including units (ie years) , , , , , - as per previous header definitions - from header - outputs ka and the ka number, or blank if no ka, except for elves for which it outputs ka unknown Having formatted the string by replacing these tokens, the code trims spaces, trailing commas or colons, as well as trailing ofs ons and ins. the idea is that something like a of will trim to just a if there is no primary. All of these pieces support a format string of the form the format string can contain y - always link n - never link u - first letter uppercase t - title case s - lower case (small) a - add an indefinite article A - add an indefinite article if it is first word