Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Installation of [markdown extra extension package to wrap the <ruby> tag]

Started by Muut Archive 10 years ago · 30 replies · 1428 views
10 years ago

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.

10 years ago

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.

\wis 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

10 years ago

taking off the first and last / makes an error too ...

10 years ago

finally, there was something to match with regex:

TXT
^{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:

JS
'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
<ruby><rb>日本語</rb><rt>にほんご</rt></ruby>

TXT


?

getting close to the point...
10 years ago

Progress:
code

JS
            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
<rt>にほんご</rt>


any idea?

10 years ago

Probably not able to deal with 2 statements 'element' so taking only the last one... any idea?

10 years ago

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

TXT
<ruby><rb>日本語</rb><rt>にほんご</rt></ruby>

Code:

JS
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],
      )
    )
  )
);
10 years ago

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'...

10 years ago

@Sommerregen

THANNNNKS AGAINNNNN!!!

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1354 9 years ago
Archive · by Muut Archive, 9 years ago
2 935 9 years ago
Archive · by Muut Archive, 9 years ago
2 4065 9 years ago
Archive · by Muut Archive, 9 years ago
1 2953 9 years ago
Archive · by Muut Archive, 9 years ago
3 1119 9 years ago