Plugin Author
Scott Reilly
(@coffee2code)
WordPress & Plugin Developer
@kanjipad ; Hi,
I can confirm that text immediately bookended by HTML tags do not get hover-texted. It’s a little trickier there to get it working and not have text inside of an HTML tag (such as in attributes) from getting hover-texted. I’m working on it though.
I cannot confirm that text at the end of a sentence does not get hover-texted. At the link you provided, the kanji at the end of a sentence does have hovertext. My tests indicate that this should be working. Is this still a problem for you?
Thread Starter
Leto
(@kanjipad)
Hi,
Thanks for the feedback. The plugin has been really useful on my site, as you can probably see. I had a go at fixing the tag issue but don’t know enough about regex at this point.
Kanji at the end of a sentence are okay if there is punctuation after the kanji. An example of where it fails is in the discussion thread…
http://kanjisketchpad.com/kanji/kanji-keyword-shortcuts-and-hover-text/
In particular, you can see the comment by me that reads ‘ Testing end of line… ‘ Followed by the kanji for eye.
(By the way, I entered that comment with your other plugin. By combining the two, I can type :eye: which becomes 目, which then acquires the hover in most cases apart from the end of line problem.)
It might depend on which invisible character is used at the end of the line.
I am currently using a modified regex expression from when I tried to fiddle with the plugin myself. I can revert to the original, I think, and will try that now to see if it is something I messed up in trying to tackle the tag issue.
Thread Starter
Leto
(@kanjipad)
I’ve changed back to your original regex expression, I think (Hopefully the commented out version was unchanged.)
The current line reads like this:
$regex = “(?!<.*?)([\s\’\”\.\x98\x99\x9c\x9d\xCB\x9C\xE2\x84\xA2\xC5\x93\xEF\xBF\xBD\(\[\{])($old_text)([\s\’\”\x98\x99\x9c\x9d\xCB\x9C\xE2\x84\xA2\xC5\x93\xEF\xBF\xBD\?\!\.\,\-\+\]\)\}])(?![^<>]*?>)”;
With that line in the plugin, I still don’t get a translation of the eye kanji when it is the last character in a line in my forum. Adding a fullstop fixes the issue, so in most cases it will be fine, and I could always add a space and a dummy tag to the html. The problem is that I can’t expect visitors to remember to do that.
Thread Starter
Leto
(@kanjipad)
I looked at the page source for the end-of-line issue in the forum, and it appears that this is a variation of the <tag> problem.
The relevant bit from the link above…
<p>But fails without the fullstop...<br />
目</p>
I can probably fix it by doing a global replace of all “</p>” with ” “</p>”, and perhaps all something similar with break tags, just prior to the regex test.
Thread Starter
Leto
(@kanjipad)
Hi there,
I’ve fixed the issue on my site with the following mod to the plugin. The first line below was already there, the next two I added:
$text = ' ' . $text . ' ';
$text = str_replace( '</p>',' </p>', $text);
$text = str_replace( '\n','\n ', $text);
Similar approaches may be needed for specific issues on individual posts, so I will perform more str-replace calls as needed.
It would still be nice to fix this for other users.