Hallo!
Das Plugin wp-typogrify bietet die Funktion, Großbuchstaben in Abkürzungen wie SPD, ÖVP, etc. mit der Klasse "caps" zu umschließen. Soweit so gut. Problem ist nur, dass wp-typogrify Umlaute dabei völlig ignoriert. Ich habe mit RegEx keinerlei Erfahrungen und war bislang unfähig durch Experimentieren herauszufinden, wo man was ändern muss, damit auch großgeschriebene Umlaute im wahrsten Sinne des Wortes miteingeschlossen werden. Vielleicht kann mir hier jemand helfen!
Hier der - meiner Meinung nach - entscheidende Code des Plugins:
function caps( $text )
{
// Tokenize; see smartypants.php
$tokens = _TokenizeHTML($text);
$result = array();
$in_skipped_tag = false;
$cap_finder = "/(
(\b[A-Z\d]* # Group 2: Any amount of caps and digits
[A-Z]\d*[A-Z] # A cap string must at least include two caps (but they can have digits between them)
[A-Z\d]*\b) # Any amount of caps and digits
| (\b[A-Z]+\.\s? # OR: Group 3: Some caps, followed by a '.' and an optional space
(?:[A-Z]+\.\s?)+) # Followed by the same thing at least once more
(?:\s|\b|$))/x";
$tags_to_skip_regex = "/<(\/)?(?:pre|code|kbd|script|math)[^>]*>/i";
foreach ($tokens as $token)
{
if ( $token[0] == "tag" )
{
// Don't mess with tags.
$result[] = $token[1];
$close_match = preg_match($tags_to_skip_regex, $token[1]);
if ( $close_match )
{
$in_skipped_tag = true;
}
else
{
$in_skipped_tag = false;
}
}
else
{
if ( $in_skipped_tag )
{
$result[] = $token[1];
}
else
{
$result[] = preg_replace_callback($cap_finder, _cap_wrapper, $token[1]);
}
}
}
return join("", $result);
}
Alles anzeigen
Das Plugin enthält auch die smartypants-Datei und ruft dort die Funktion Tokenize auf, die ich hier auch herkopiert habe (vielleicht braucht man die ja).
if (!function_exists('_TokenizeHTML')) :
function _TokenizeHTML($str) {
# Parameter: String containing HTML markup.
# Returns: An array of the tokens comprising the input
# string. Each token is either a tag (possibly with nested,
# tags contained therein, such as <a href="<MTFoo>">, or a
# run of text between tags. Each element of the array is a
# two-element array; the first is either 'tag' or 'text';
# the second is the actual value.
#
#
# Regular expression derived from the _tokenize() subroutine in
# Brad Choate's MTRegex plugin.
# <http://www.bradchoate.com/past/mtregex.php>
#
$index = 0;
$tokens = array();
$match = '(?s:<!(?:--.*?--\s*)+>)|'. # comment
'(?s:<\?.*?\?>)|'. # processing instruction
# regular tags
'(?:<[/!$]?[-a-zA-Z0-9:]+\b(?>[^"\'>]+|"[^"]*"|\'[^\']*\')*>)';
$parts = preg_split("{($match)}", $str, -1, PREG_SPLIT_DELIM_CAPTURE);
foreach ($parts as $part) {
if (++$index % 2 && $part != '')
$tokens[] = array('text', $part);
else
$tokens[] = array('tag', $part);
}
return $tokens;
}
endif;
Alles anzeigen
Direktlink zum wp-typogrify-Plugin.
Nun meine Frage: Wo muss ich was ändern, damit auch großgeschriebene Umlaute (ÄÖÜ) berücksichtigt werden?
Besten Dank,
Michael