You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In some cases we want these to be "pluggable" so that users can customize the output to fit their needs; in others we want to use a standardized approach to comply with the spec. But in both cases I think we can use a common interface for normalizing text.
I'd therefore to unify these under a single interface:
<?phpnamespaceLeague\CommonMark\Normalizer;
/** * Creates a normalized version of the given input text */interface TextNormalizerInterface
{
/** * @param string $text The text to normalize * @param mixed $context Additional context about the text being normalized (optional) */publicfunctionnormalize(string$text, $context = null): string;
}
$context can be used to provide additional information about the text being normalized. For example, when normalizing heading content within the HeadingPermalinkProcessor, we can pass along the Heading node as the $context in case somebody wants to check the heading level when generating a slug. In other cases this may be null.
We'll provide two implementations out-of-the-box:
A TextNormalizer based on Reference::normalizeReference which performs the normalization prescribed by the spec
A SlugNormalizer which works similarly, but converts text to underscore and uses - separators instead of spaces
Existing code will be updated to use these and we'll set relevant deprecation notices where needed.
Furthermore, we'll rename the new heading_permalink/slug_generator option to heading_permalink/slug_normalizer.
The FootnoteExtension will also be modified to use this new normalizer approach, though further research will be needed to determine if we should leverage the spec's reference normalization approach and/or allow customization.
The text was updated successfully, but these errors were encountered:
The footnote extension classes rely on the Reference implementation, which normalizes strings a certain way, so let's avoid allowing customization for now. We can always revisit this later.
(Pulling #484 (comment) into a separate thread)
There are a few places within this library where text is manipulated into a "normalized" version:
In some cases we want these to be "pluggable" so that users can customize the output to fit their needs; in others we want to use a standardized approach to comply with the spec. But in both cases I think we can use a common interface for normalizing text.
I'd therefore to unify these under a single interface:
$context
can be used to provide additional information about the text being normalized. For example, when normalizing heading content within theHeadingPermalinkProcessor
, we can pass along theHeading
node as the$context
in case somebody wants to check the heading level when generating a slug. In other cases this may benull
.We'll provide two implementations out-of-the-box:
TextNormalizer
based onReference::normalizeReference
which performs the normalization prescribed by the specSlugNormalizer
which works similarly, but converts text to underscore and uses-
separators instead of spacesExisting code will be updated to use these and we'll set relevant deprecation notices where needed.
Furthermore, we'll rename the new
heading_permalink/slug_generator
option toheading_permalink/slug_normalizer
.The
FootnoteExtension
will also be modified to use this new normalizer approach, though further research will be needed to determine if we should leverage the spec's reference normalization approach and/or allow customization.The text was updated successfully, but these errors were encountered: