Skip to content

Add an option 'G' to use German quotes #13

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

Open
wants to merge 2 commits into
base: lib
Choose a base branch
from

Conversation

flesser
Copy link

@flesser flesser commented Jan 31, 2016

The configuration option 'G' can be set to use „German“ quotes instead of "English" quotes.

@michelf
Copy link
Owner

michelf commented Jan 31, 2016

You probably didn't notice that if you worked from the SmartyPantsTypographer class most of that work was already done. In that class those variable already exist:

# Smart quote characters:
# Opening and closing smart double-quotes.
public $smart_doublequote_open  = '“';
public $smart_doublequote_close = '”';
public $smart_singlequote_open  = '‘';
public $smart_singlequote_close = '’'; # Also apostrophe.

I admit the current way things are setup with the _SmartyPantsTypographer_TmpImpl class in the middle makes things confusing. That's in need for a reorganization.

I think your 'G' option is a good idea. But:

  1. it probably belongs in SmartyPantsTypographer (or rather _SmartyPantsTypographer_TmpImpl), not the base SmartyPants class.
  2. I worry a bit about having to support too many quotation styles.

@flesser
Copy link
Author

flesser commented Feb 1, 2016

In that class those variable already exist
Yes, I found them while doing my replacements and assigned new values to them when parsing the 'G' option in L646.

Actually, I am quite confused why the file contains two full implementations of the same functionality. Many functions (like educateQuotes()) are implemented two times in both classes using pretty much the same code. Does it have a reason i missed? It's is not really helpful to understand and extend the code.

  1. I worry a bit about having to support too many quotation styles.

Well, you're right. That list is ... extensive.
Maybe the better way would be to either provide a documented configuration API to set arbitrary strings to override the default quotes, or to make SmartyPants to accept an ISO country code and have a lookup table for the according quotes.

In my case, I'm using SmartyPants as part of Grav CMS, serving a website in German language.
However, Grav's SmartyPants plugin seems to use the SmartyPants class and not the SmartyPantsTypographer:

    $page->setRawContent(\Michelf\SmartyPants::defaultTransform(
        $page->getRawContent(),
        $config->get('options')
    ));

So in order to get my German quotes, I edited the above class in SmartyPants.php
Maybe I'll try to edit the plugin instead to use SmartyPantsTypographer and have some configuration options to set the public $smart_doublequote_open variables before transforming.

@michelf
Copy link
Owner

michelf commented Feb 1, 2016

The reason the two classes exist is that I wanted to preserve the original PHP SmartyPants as it was (similar to John Gruber's SmartyPants) and put everything new in a separate class. The Typographer version replaces many spaces with non-breaking spaces by default, and I didn't want to force that behaviour on existing users of SmartyPants.

Similarly, the _SmartyPantsTypographer_TmpImpl probably has no reason to exist anymore. The idea was to facilitate merges using git while I maintained the older version (which is still the one available on my website) together with this new "lib" version. But I doubt very much I'll do any more work on the older version, so it's pointless now. And confusing.

When it comes to configuring the quotes, I agree it'd make a bit more sense to put the configuration variables inside of the SmartyPants class to avoid duplicated code. That is almost what your pull request is doing, so feel free to update it in that direction if you want.

And also, if you want to remove the _SmartyPantsTypographer_TmpImpl class and move its content to the SmartyPantsTypograher class, feel free to do so too (but as a separate pull request ideally). Otherwise I'll do it myself eventually.

I'm not sure what would be the best way to get the quote configuration within Grav. But doing something like this would seem to make much sense:

$parser = new \Michelf\SmartyPants($config->get('options'));
$parser->smart_doublequote_open = ""; // get quote config from somewhere
$parser->smart_doublequote_close = ""; // get quote config from somewhere
$page->setRawContent($parser->transform($page->getRawContent()));

Copy link

@jnncks jnncks left a comment

Choose a reason for hiding this comment

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

As much as I'd appreciate support of German quotes out of the box, there are a few flaws with the characters you're using. The closing quote characters are not the correct ones, take a look at Wikipedia: https://en.wikipedia.org/wiki/Quotation_mark#German

Also, the apostrophe is unfortunately a separate character (basically a raised comma): https://de.wikipedia.org/wiki/Apostroph

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.

3 participants