Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.5: HeadingPermalinkProcessor::getChildText() strips out AbstractStringContainer from link #615

Closed
Ambient-Impact opened this issue May 2, 2021 · 5 comments
Assignees
Labels
bug Something isn't working right fixed Fix has been implemented

Comments

@Ambient-Impact
Copy link

Ambient-Impact commented May 2, 2021

Description
I know that HeadingPermalinkProcessor::getChildText() is going to be removed in 2.0, but I'm stuck with 1.5 for the foreseeable future. I assumed any class that extends AbstractStringContainer would have its text contents included in the permalink, but it seems that instanceof Text and instanceof Code are hard coded. Is there a reason for this, or can it be expanded to instanceof AbstractStringContainer?

Example
I'm helping bring 8fold/commonmark-abbreviations closer in line with CommonMark core (see 8fold/commonmark-abbreviations#8), and when an Abbreviation is present in the heading text, even with the pull request to extend AbstractStringContainer, the text content is completely ignored by the heading permalink.

@Ambient-Impact Ambient-Impact added the enhancement New functionality or behavior label May 2, 2021
@Ambient-Impact
Copy link
Author

Upon poking around, it seems like this issue can be worked around with a custom text normalizer:

class YourNormalizer implements TextNormalizerInterface {

  /**
   * {@inheritdoc}
   */
  public function normalize(string $text, $context = null): string {
    if (
      \is_object($context) &&
      \method_exists($context, 'getStringContent') &&
      !empty($context->getStringContent())
    ) {
      $text = $context->getStringContent();
    }

    // Rest of normalizer processing goes here.

  }

}

@colinodell
Copy link
Member

I assumed any class that extends AbstractStringContainer would have its text contents included in the permalink, but it seems that instanceof Text and instanceof Code are hard coded. Is there a reason for this, or can it be expanded to instanceof AbstractStringContainer?

I honestly can't recall why the other node types were excluded.

Given that 2.0 allows other types including AbstractStringContainer, I don't see any obvious reasons why we can't allow this in 1.x too.

Would you be okay if we changed this behavior in 1.6.1? Or do you really need this in 1.5?

@Ambient-Impact
Copy link
Author

Given the workaround I posted, it's no rush and fine in 1.6.1. Thanks! 🤓

@colinodell
Copy link
Member

Fixed via a70a586 and released in 1.6.1.

Thanks for reporting this!

@colinodell colinodell added the fixed Fix has been implemented label May 8, 2021
@Ambient-Impact
Copy link
Author

Awesome, thanks!

Excited wiggling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right fixed Fix has been implemented
Projects
None yet
Development

No branches or pull requests

2 participants