Refactor string formatting across HTML and language, add "blockwrap" metatag #348
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Development:
This pull request brings a few related changes together:
html.Tag
values (which we call "live values") which got passed into functions likelanguage.$
orlanguage.formatConjunctionList
would get stringified at the time of that formatting function call, so that they could be inserted into string surroundings, either from a template specified in a strings file, or dynamically placed by anIntl.ListFormat
formatting function.html.tags
element. (We already did a similar wrapping for marking the output of a formatting function as no longer needing sanitization; we're accomplishing the same thing now, too, but also usinghtml.tags
to be able to bundle multiple live values together.)#iterateOverTemplate
function, which takes a "template", a regular expression that identifies parts of the template that should be replaced, and an insertion function, which processes the match and returns the content to insert at that point. The insertion function can returnundefined
to mark output forming as canceled, in which case the rest of the matches are stlil iterated over, but no final output is returned.{OPTION_NAMES}
in a language file string; insert option values as provided, or, if missing, cancel string forming and mark the option as missing. Strike used options from a list; mark unused options as misplaced.<::insertion_0>
,<::insertion_1>
,<::insertion_2>
etc in a string that was composed by anIntl.ListFormat
formatting function. Replace with the corresponding items in a provided array.#iterateOverTemplate
sanitizes raw string values (using#sanitizeValueForInsertion
, née#sanitizeStringArg
) and conjoins adjacent strings. It also flattens nested tag values that are "content only", i.e. no tag name/attributes nor special (metatag) behavior - i.e,html.tags()
, which are most often embedded as the result of another formatting function call.#iterateOverTemplate
not only is an abstraction of the basic iteration/insertion behavior, but also consolidates supplemental stuff common acrossformatString
and list formatters.formatConjunctionList
) now use a#formatListHelper
function to take care of creating and operating on insertion markers - it's just a convenient wrapper around#iterateOverTemplate
.formatString
has been touched up with fresher reading, mostly thanks to#iterateOverTemplate
.html.metatag
system, includinghtml.metatag('blockwrap')
.blockwrap
is a metatag which, during content stringification, "absorbs" all same-parent siblings following it and puts them together with its own children, under a<span class="blockwrap">
tag.Since blockwrap fundamentally functions outside the normal stringification hierarchy behavior, the language changes are required to ensure the blockwrap itself gets stringified (at which point it can't be detected for special handling by the parent's stringification).
We don't actually use blockwrap anywhere in this PR - changes to content are kept for a follow-up pull request.