nystudio107 / craft-typogrify

Typogrify prettifies your web typography by preventing ugly quotes and 'widows' and more

Home Page:https://nystudio107.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use mundschenk-at/php-typography

mundschenk-at opened this issue · comments

Might I suggest using mundschenk-at/php-typography? There have been quite a lot of improvements since I took over development from KINGDESK.

I saw that; but it also looked like a number of API changes as well.

I do plan to look into refactoring and using your library, as I want something that is maintained! :)

Two things that have changed: The class name for the main class and that the settings are a separate entity and not part of the PHP_Typography class anymore (i.e. you need an additional parameter). So yes, it's not a drop-in replacement, but the necessary adaptions should be fairly limited.

Yeah the reason why I didn't tackle it immediately was that I created my own settings model (with validators):

https://github.com/nystudio107/craft3-typogrify/blob/master/src/models/Settings.php

And I wasn't sure how much work it was going to be to use your new fork with its own settings model with my settings model layered on top.

I suspect we created them for similar reasons, so it shouldn't be too bad, but when faced with the unknown, I err on the side of caution.

I'm going to give it a whirl today.

@mundschenk-at is there any chance we can get an actual version field in the composer.json so I don't have to do dev-master@dev?

Ah never mind, I see you're doing it with tags instead of a version number in the composer.json

Switched over in version 1.0.2:

https://github.com/nystudio107/craft3-typogrify/releases/tag/1.0.2

Two minor problems I encountered:

  • The parser was returning nothing because the HTML being passed in was invalid, and thus the DOM parser gave up. I do see that it logs errors, and that there's an error handler callback, though, which I'll look at supporting in a later release

  • the set_smart_quotes_secondary() method no longer accepts '' as a valid/default parameter the way the old library did.

All fixed up, thanks for the push to move to your library, and thank you for maintaining it!

You can enable lenient error handling by using set_ignore_parser_errors( true ). The resulting HTML will be a "best guess" by the parser, so there might be side effects. The handler callback is only needed if you want a more finegrained control over parser errors.

I just had a look at the set_smart_quotes_* functions and you are right, originally they also accepted the empty string. I don't remember when this changed, but it was probably when I first refactored the (redundant) code in those functions in 2015. Nowadays, the preferred way is to use the constants from PHP_Typography\Settings\Quote_Style.

Great, thanks for your reply, I'll make some adjustments. Much appreciate you maintaining this wonderful library!