PHP code example of noi / parsedown-rubytext

1. Go to this page and download the library: Download noi/parsedown-rubytext library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

noi / parsedown-rubytext example snippets


$pd = new \Noi\ParsedownRubyText(); // or new \Noi\ParsedownExtraRubyText();
echo $pd->text('[日本語]^(にほんご)');

// Output:
<p><ruby>日本語<rp>(</rp><rt>にほんご</rt><rp>)</rp></ruby></p>

class YourParsedown extends Parsedown /* or ParsedownExtra or etc. */ {
    // 1. ルビ用エクステンションのtraitをuse
    use \Noi\Parsedown\RubyTextTrait;
    use \Noi\Parsedown\RubyTextDefinitionTrait;

    // 2. registerメソッドをコンストラクタかどこかで実行
    public function __construct()
    {
        parent::__construct(); // 必要に応じて

        $this->registerRubyTextExtension();
        $this->registerRubyTextDefinitionExtension();
    }
}

$pd = new YourParsedown();
echo $pd->text('[日本語]^(にほんご)');

// Output:
<p><ruby>日本語<rp>(</rp><rt>にほんご</rt><rp>)</rp></ruby></p>