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

Choose filters to apply #1

Merged
merged 3 commits into from
Dec 26, 2024
Merged

Conversation

davidlesieur
Copy link

Following up on getpelican/pelican#3436, here's a take at making the typogrify() function more flexible by allowing one to select which filters to apply.

Some remarks about the proposed changes:

  • To keep the new keyword arguments to applyfilters() and typogrify() short while avoiding name clashes with their corresponding filter functions, they are accessed through kwargs.pop(). That makes the function signatures less self-explanatory, but I am mentioning the keyword arguments in the docstrings.
  • I have moved a doctest from applyfilters() to typogrify(), because it was specifically testing typogrify().
  • I have added doctests for the new options.
  • I have noticed that widont ignores the ignore_tags list, and then discovered that this issue had already been reported in Move widont filter to applyfilters function mintchaos/typogrify#30. I have added a comment and a test about this behavior. I understand that widont only applies to a hardcoded list of tags, but it probably makes the API less predictable to one who wouldn't fully read the documentation or code. However, this would perhaps be better addressed separately from this PR.

@davidlesieur
Copy link
Author

davidlesieur commented Dec 24, 2024

Regarding the widont issue, just noticed the related PR mintchaos#31. It moves the call to widont() to applyfilters(), subjecting it to the list of ignored tags. If you'd like, I could integrate that change here.

@justinmayer justinmayer changed the title Choose filters to apply. Choose filters to apply Dec 24, 2024
@justinmayer
Copy link
Owner

By all means — integrating that change here seems like a sensible approach. Thank you for suggesting that and for jumping on these changes! 😁

@davidlesieur
Copy link
Author

Moved the widont filter to applyfilters(). However, this breaks a test in Pelican, which expects widont to ignore the ignore_tags.

Part of the Pelican tests output:

FAILED pelican/tests/test_readers.py::RstReaderTest::test_typogrify_ignore_tags - AssertionError: '<p>T[34 chars]ff to &quot;typogrify&quot;...</p>\n<p>Now wit[68 chars]p>\n' != '<p>T[34 chars]ff to&nbsp;&quot;typogrify&quot;...</p>\n<p>No[73 chars]p>\n'

Results (2.78s):
     268 passed
       1 failed
         - pelican/tests/test_readers.py:412 RstReaderTest.test_typogrify_ignore_tags
      27 skipped

@justinmayer
Copy link
Owner

If the following relevant comment is to be believed, the widont filter should be able to handle tags and thus not need to ignore them:

# apply widont at the end, as its already smart about tags. Hopefully.

That being the case, perhaps the Pelican test should be updated to no longer require widont to ignore the ignore_tags? What do you think?

@davidlesieur
Copy link
Author

Yes, I think the Pelican test should be changed. My understanding of the comment on widont being "smart" is that it ever only applies to tags h1-h6, p, li, dd, dt, a, em, strong, span, b, i. By moving widont to applyfilters(), we make it more consistent with other filters in that it will now ignore any of those tags if they are specified in ignore_tags. This idea was also in mintchaos#30, which gave the example of someone not wanting widont on h1 tags.

@justinmayer justinmayer changed the base branch from modernize to main December 25, 2024 15:35
Copy link
Owner

@justinmayer justinmayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for these enhancements, David! 🏅

@justinmayer
Copy link
Owner

@davidlesieur: Would you be willing to submit a pull request to Pelican to modify the aforementioned test? That way, as soon as I publish the next Typogrify release, we can merge that Pelican PR and ensure tests continue to pass. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants