fabianmichael / kirby-typography Goto Github PK
View Code? Open in Web Editor NEWTypographic enhancements for your Kirby-driven website.
License: GNU General Public License v3.0
Typographic enhancements for your Kirby-driven website.
License: GNU General Public License v3.0
On PHP 5.4 (yeah there are some old servers around) and PHP 5.5 (built-in PHP version in latest OSX, I’m getting a parse error in lib/kirbytypography.php
, line 9.
Apparently PHP prior to 5.6 does not like computing stuff when declaring class properties.
class KirbyTypography extends PHP_Typography {
protected $domainListUrl = 'http://data.iana.org/TLD/tlds-alpha-by-domain.txt';
protected $domainListCacheLifetime = 60 * 24 * 7; // one week
Changing to protected $domainListCacheLifetime = 10080;
seems to fix the issue (tested with PHP 5.5).
By the way, is that property supposed to represent a number of minutes?
Because 60 * 24 * 7 = 10080
is the number of minutes in a week.
If you want seconds, that’s 60 * 60 * 24 * 7 = 604800
.
Declaration of Kirby\Plugins\Typography\Component\Typography::parse($text, $force = false) should be compatible with Kirby\Component\Smartypants::parse($text, $force, Field $field)
Any idea how to fix this ?
Thanks a lot
Not sure that's something you have control over, if the options come from the libraries used.
I was thinking that for typography.quotes.primary
and typography.quotes.secundary
it would be nice to be able to provide custom strings, like:
c::set('typography.quotes.primary', '« foo »');
The foo
string or another marker would act as a way to detect a custom setting and split the opening/closing parts.
Hi Fabian, your adaption is pretty neat! Will there be a way to make further typographical corrections in your next version? like searching for regex patterns or speficic word combinations, then changing the whitespace to a smaller one and wrap the term to prevent line breaking etc?
My current config.php looks like this:
c::set([
'typography.dashes' => 'false', // I already care for that
'typography.hyphenation' => 'false' // disable hyphenation
]);
But it doesn't work. The text still gets hyphenated :(
Hi, it's me again.
"Noooo, not them again."
Sorry. :D
Okay, so this might be a problem upstream in php-Typography.
Provided the following input:
Les « courants de bord ouest » du Pacifique ?
Eh bien : ils sont "fabuleux".
and using the smartypants
function or kirbytext
method on this input, the result is:
Les « courants de bord ouest » du Pacifique ?
Eh bien : ils sont « fabuleux ».
config is:
// config/config.php
c::set([
'smartypants' => true,
'typography' => true,
'typography.style.punctuation.hanging' => false,
'typography.style.quotes.initial' => false,
'typography.hyphenation' => false,
]);
// languages/fr.php
l::set('typography.punctuation.spacing.french', true);
l::set('typography.quotes.primary', 'doubleGuillemetsFrench');
l::set('typography.quotes.secondary', 'doubleCurled');
Ideally, I would like the typography.punctuation.spacing.french
setting to deal with « »
quotes in the same way it deals with ?!:;
, i.e. to transform «\s+
to «
and \s+»
to »
. Since it's a setting for French, there should be no doubt whether »
is a closing or opening quote (it's a closing quote).
Do you think that's a limitation of php-Typography that I should bring up with them?
Add troubleshooting section with fixes for common problems with the plugin. The Troubleshooting section will contain solutions for this.
Ligatures:
https://forum.getkirby.com/t/kirby-typography-plugin/4199/9
Would this plugin be able provide a $field->hyphenate($lang)
method, without major refactoring?
As argued in #6, hyphenation is a design choice. And I'll add that a designer or client may want hyphenation for some texts (e.g. an article's body) but not for others (e.g. a big title).
What might serve this use case:
<article>
<header>
<h1><?php echo $page->title()->smartypants(); ?></h1>
</header>
<div class="article-body">
<?php echo $page->text()->kirbytext()->hyphenate(); ?>
</div>
</article>
This plugin loads a non existing file (also i couldn't find a htaccess with this path in it).
http://127.0.0.1/plugins/typography/widget/api/status
Make the dashboard widget translatable.
I have an issue that I don't seem to be able to resolve with config options only.
I have those two textareas, for example :
He was co-editor of the magazine *Name of magazine* and created *Name of creation*.
and
Editorial manager: Name
Address: 75 Street City
Email: [email protected]
I have two languages. English (default) and french. And I only changed the hyphenation to false
in my config file. My issue :
The first textarea renders as :
He was co-editor of the magazine<em>Name of magazine<em> and created<em>Name of creation</em>.
and the second :
Editorial manager: Name<br>
Address: 75 Street City<br>
Email: <a href="mailto:[email protected]">example@​example.​com</a>
So, the first text is missing its spaces before the <em>
tags.
space.collapse
set to false
With this option, the first text renders as it should :
He was co-editor of the magazine <em>Name of magazine<em> and created <em>Name of creation</em>.
But in the meantime, it introduced some doubleQuote
after each <br>
on the second text :
Editorial manager: Gauthier Roussilhe<br>
<span class="push--doubleQuote"></span>​<span class="pull--doubleQuote">
</span>Address: 75 Street City<br>
<span class="push--doubleQuote"></span>​<span class="pull--doubleQuote">
</span>Email: <a href="mailto:[email protected]">example@​example.​com</a>
What should I do ?
(you can see the code of the entire website here)
Using Kirby-Typography should not be limited to Kirbytext or by utilizing the Smartypants component. In Some cases, you want to use different settings for different fields and/or in different sections of a template (see #7).
Kirby-Typography should provide methods utilizing the plugin directly:
typography($text, $settings = []);
This should always be based a language’s default settings with the possibility to override them using the $settings
parameter. It could also be possible to define presets in the config file, which can then be used in templates by providing a string instead of an array for $settings
.
Hi,
So I spent a few hours the other day trying to get settings for a multilingual site working. Most of the settings I was declaring, in site/config/config.php
or in languages/fr.php
were not working. for instance I couldn't get the
added before double punctuation marks. It just wouldn't work.
Today I realized that this plugin uses a week-long cache, and what I was seeing was perhaps the result from older settings. So I set c::set('typography.debug', true);
and taddaaaa it worked.
I'm suspecting many users would have this issue, if following this scenario:
Different ways to prevent that:
typography.debug
to the value of the debug
config.Can you provide an exemple for "typography.diacritics.custom" ? I want to use it in French recommended Settings but it doesn't work. Also, "typography.punctuation.spacing.french" doesn't seems to add thin spaces inside French quotes (ex. : « foo »).
Thanks!
On simple php webserver i get this
Fatal error: Method Kirbytext::__toString() must not throw an exception, caught Error: Call to undefined function Masterminds\HTML5\Parser\ctype_alpha() in /Users/krisa/dev/sok_bz/website/kirby/helpers.php on line 0
I was thinking that maybe its some extension missing, but that html5 parser seems OK and should work even in php5.3
I tested this in php5.6 and 7 not sure what i am missing.
I understand the personal preference and perhaps the willingness to depart from English/American norms all the time everywhere, but:
doubleCurled
and singleCurled
are closest to the replaced charactersFeel free to close this issue if you disagree. :)
Rationale: while other things like typographically incorrect quotes and fake dashes (--
) can be seen as defects or limitations of the source text that should probably be corrected whenever possible, hyphenation is a design choice that designers should probably opt in. Especially since it's very uncommon on the web.
'typography.hyphenation.headings' => 'false',
Has strictly no effect (words are hypheteted)
Kirby version : 2.3
Language : French
Do you plan to make a K3 version of this great plugin ? :)
Hi,
It would be nice to add a simple composer.json
file to this repo, to make installation with Composer quite easier.
It could look like:
{
"name": "fabianmichael/kirby-typography",
"description": "This is a port of [wp-Typography](https://de.wordpress.org/plugins/wp-typography/) for Kirby CMS. Based on the `PHP_Typography` class, this plugin enhances the typography of you kirby-powered website. Think of it a more advanced alternative to the built-in `SmartyPants` parser.",
"authors": [{"name": "Fabian Michael"}],
"license": "GPL-3.0"
}
The "version"
key is optional, and it’s recommended to omit it to let Composer (and Packagist) retrieve the available versions from git tags. Note that Composer will only see those tags which have a composer.json
file, so if you add a commit with a composer.json
you will need to add a tag.
It could be nice to publish this package on Packagist as well.
If one wants to install this plugin with Composer today, one needs a verbose definition:
{
"minimum-stability": "beta",
"require": {
"fabianmichael/kirby-typography": "^1.0.0"
},
"repositories": [
{
"type": "package",
"package": {
"name": "fabianmichael/kirby-typography",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/fabianmichael/kirby-typography.git",
"reference": "1.0.0-beta1"
}
}
}
]
}
With a composer.json
in this repo, it gets shorter:
{
"minimum-stability": "beta",
"require": {
"fabianmichael/kirby-typography": "^1.0.0"
},
"repositories": [
{ "type": "vcs", "url": "https://github.com/fabianmichael/kirby-typography" }
]
}
And if this package is also published on Packagist, you can just use:
{
"minimum-stability": "beta",
"require": {
"fabianmichael/kirby-typography": "^1.0.0"
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.