Muut
January 12, 2016, 5:02pm
21
When working with Regex I suggest trying it here: https://regex101.com/
This way you can put your test string in and tweak the regex until it matches as you want it, then paste the resulting code back into PHP. BTW you don’t need the first and last /
characters… those are for PHP only.
Muut
January 12, 2016, 6:31pm
22
Thank you but I can’t get how this to work!
Whatever I try, it’s: ‘no match’…
I can’t find any clue… I am not even sure of what to put and where.
\w
is given as matching any word character [a-zA-Z0-9_]
: does regex \w is able to deal with japanese characters?
Once I made something on regex (be witout being able to have something matching), I test it my php document and I have an error…
I am in a maze here… Please help
Muut
January 12, 2016, 6:39pm
23
taking off the first and last /
makes an error
too …
Muut
January 12, 2016, 7:02pm
24
finally, there was something to match with regex:
^{r}([\S]+){\/r:([\S]+)}
but testing it in grav, is leading to an error
with the handler of Parsedown
and ParsedownExtra
:
Capture6
it seems that this:
'text' => array (
'element' => array(
'name' => 'rb',
'text' => $matches[1]),
'element' => array(
'name' => 'rt',
'text' => $matches[2]),
),
IS NOT valid.
[probably because it should be a string…]
How can it be written differently to get to output:
—html
日本語にほんご
?
getting close to the point...
Muut
January 12, 2016, 7:57pm
25
Progress:
code
if (preg_match('/{r}([\S]+){\/r:([\S]+)}/', $excerpt['text'], $matches))
{
return
array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'rb',
'text' => $matches[1]),
'element' => array(
'name' => 'rt',
'text' => $matches[2]),
);
}
};
}
}
gave the ouptput:
—html
にほんご
any idea?
Muut
January 12, 2016, 8:07pm
26
Probably not able to deal with 2 statements ‘element’ so taking only the last one… any idea?
Muut
January 12, 2016, 9:01pm
28
Hi @tidivoit I’m not used to Markdown parsing, but it seems you are right: only one element is valid and your code is overwriting the first element
entry, too. I’ve reverse engineered how Parsedown (the Markdown Parser) works. The following code (inside the if condition) should return
<ruby><rb>日本語</rb><rt>にほんご</rt></ruby>
Code:
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'ruby',
'handler' => 'elements',
'text' => array(
array(
'name' => 'rb',
'text' => $matches[1],
),
array(
'name' => 'rt',
'text' => $matches[2],
)
)
)
);
Muut
January 12, 2016, 9:20pm
29
it worked beautifully !!!
☆ Thank you very very very much!!!
So, this plugin is ready for release now! GREAT!!!
it’s going to be easier to publish in eastern languages with this ♪ … Good for Grav!!!
Next step is too release it properly following manual on ‘learn.getgrav.org ’…
Muut
January 12, 2016, 9:49pm
30
@Sommerregen
☆ THANNNNKS AGAINNNNN!!! ♪