Hi ♪ I am kindly asking help: this is what it is about.
I working on a site in japanese language
and
would like to extendMakdown Extrawith thisextension
(or here) (link shows a page with some japanese, but please, don’t be afraid: it’s just another package that can be installed with composer…)
I would like to install that package so that it works into the site,
but have no idea how to do that properly?
As you can see these lines are instantiating either Parsedown or ParsedownExtra. However, you would need to add the composer package, do a composer update, then modify these lines to load the Ruby Extended version of Parsedown.
Also we are already extending Parsedown and ParsedownExtra with a Grav trait that adds the extended abilities for images and links. That would no longer work.
Thank you for answering.
I wonder if you got what I am trying to say.
Please forgive me if I am wrong,
Here Ruby DO NOT STAND for the programming language Ruby but for the html tag [that allow displaying of pronunciation mainly used in Eastern languages (Chinese, Korean, Japanese…).]
so, Isn’t there some confusion there?
Therefore, the component that I would like to see implemented IS NOT replacing Parsedown Extra by antoher version programmed in the programming language Ruby.
I am not so experienced that I can get exactly how the extension interact with Parsedown Extra, BUT In the japanese, the explanations given by progammer, give two ways to implement the extension, one at level of a simple Parsedown class, the other by creating a new original trait.
So it should be possible to implement that as an evidence, with very little work.
Practically, what this extension does is to wrap:
[some text]^(some pronunciation)
like for example:
[日本語]^(にほんご)
into
the following html output:
—html
日本語(にほんご)
it is very very very useful (short) for dealing with those languages!
It is fundamental also mainly because, unlikely as in the latin alphabet, it is not possible to _read (pronunce) a word that you never saw before_.
So, in informational texts that one share with its audience thrue Grav, you definetely want to have that, as you are presentating things to people that do not know yet what you are willing to present to them and therefore you need to have them be able to pronunce your text.
Actually I have to set `html` code each time for each term directly in Mardown Text, which is particularly painful.
the <ruby> tag has been introduce in html 5 considering that essential need also in terms of number of people (chinese, japanese, korean language speaking audience) (not a detail!) for such a feature.
As it is not so complex to do, isn't there a real interest to introduce that new feature in Grav too?
Grav definitely need that feature because it's of its time and our times is Pacific orientated!
Hope wishes come true, at least, that you can get what I am trying to say!
☆ thank you... ♪
in addition to previous post, please find a translation of documentation made by japanese programmer of extension to wrap tag as a simple ParsedownExtra class. original documentation in japanese
Here the translated text:
use Noi\ParsedownRubyText / Noi\ParsedownExtraRubyText
These classes are the classes implemented for ParsedownとParsedownExtra to use the extension.
It’s possible to add to the already existing classes the classes defining the notation and the >ruby> notation when used as a reference.
Using this method, it’s the same as for a Parsedown class.
$pd = new \Noi\ParsedownRubyText(); // or new \Noi\ParsedownExtraRubyText();
echo $pd->text('[日本語]^(にほんご)');
// Output:
<p><ruby>日本語<rp>(</rp><rt>にほんご</rt><rp>)</rp></ruby></p>
Hope this demonstrates that implementation is simple to achieve ☆
If for some reason you would not be interested in implementating this as a new feature for Grav’s core, is it possible to achieve this making a dedicated plugin?
What would be the method to follow?
Sorry that I could not convince of the value of this feature for Grav too.
True this is new.
The tag in html5 is new.
The library in reference is 4 months old.
There are plans also to implement other aspects of ruby in future browsers also.
This will probably be added in a near future in ParsedownExtra, but in the mean time… it would be an avantage for Grav… because Grav is a NEW thing!
If I try to implement that with my poor skills:
1-
add the composer package, do a composer update, then modify these lines to load the Ruby Extended version of Parsedown
2-
I write a new Grav trait for that adds the extended abilities for ParsedownExtraRubyText.
How should I do not to touch the images and links so that they continue to work regularly and have that ParsedownExtraRubyText work?
I mean they are not touching the same things?
Another option, is probably to write a new plugin on the model of markdown-color, that would react on a redaction like for {c:red}some text{/c} with probably an inversion of order like {c}some text{/c:some pronunciation} to respect the sentence order.
I would change the output to something like:
—html
日本語にほんご
Personnally I prefer first solution as it is able to evolve more, but I don't feel that I can manage to do that with my actual technical level.
Even the second solution is hard for me...
I deal with a language, japanese that, as for chinese and korean, definitely need this for a matter of confort: to write code html word per word is TOO HARD!!!
Not having anything is out of question... And having that type of redaction 日本語(にほんご)is NOT sufficiently professional for a DECENT web site.
Having nothing is suicide as people can not even pronunce what you're trying to communicate...
Always thanks in advance for your support in making Grav the NEW thing!!! ♪
A plugin would be the preferred solution. It ensures it is independently developed, and can be updated and bug fixed without having to release the core. The best bet is to try that route first.
It also means you are adding functionality without breaking or changing anything in the core.
☆ I’ll try that… if success, this will be my first plugin!!!
The markdown color plugin seems possible with my technical level…
See you there…
Always thanks again ♪
<?php
namespace Grav\Plugin;
use \Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event;
//COMMENT: THE NEW PLUGIN'S NAME IS 'RUBYTEXT':
class RubytextPlugin extends Plugin
{
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'onMarkdownInitialized' => ['onMarkdownInitialized', 0],
];
}
public function onMarkdownInitialized()
{
$markdown = $event['markdown'];
// Initialize Text example
$markdown->addInlineType('{', 'Rubytext');
// Add function to handle this
$markdown->inlineRubyText = function($excerpt) {
//COMMENT: FROM HERE I DID NOT TOUCHED ANYTHING I AM NOT ABLE TO:
if (preg_match('/^{c:([#\w]\w+)}([^{]+){\/c}/', $excerpt['text'], $matches))
{
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'span',
'text' => $matches[2],
'attributes' => array(
'style' => 'color: '.$matches[1],
),
),
);
}
};
}
}
model: MARKDOWN COLOR PLUGIN: this is {c:red}red text{/c} and this is {c:#000099}blue text{/c}
—html red text and this is blue text
*goal:* RUBYTEXT PLUGIN: ('r' is standing for 'ruby' and is arbitrary)
`this is {r}日本語{/r:にほんご}`
---html
<ruby><rb>日本語</rb><rt>にほんご</rt></ruby>
SUGGESTION: [please be indulgent, it’s my first code in php ever!!!] [i am autodidact here!!!] [I don’t know what I am trying to write!!!]
change of order between $matches[2] and $matches[1] to respect logic
//COMMENT: CHANGE IS INDICATED BY 'COMMENT CHANGE' BELOW
<?php
namespace Grav\Plugin;
use \Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event;
//COMMENT: THE NEW PLUGIN'S NAME IS 'RUBYTEXT':
class RubytextPlugin extends Plugin
{
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'onMarkdownInitialized' => ['onMarkdownInitialized', 0],
];
}
public function onMarkdownInitialized()
{
$markdown = $event['markdown'];
// Initialize Text example
$markdown->addInlineType('{', 'Rubytext');
// Add function to handle this
$markdown->inlineRubyText = function($excerpt) {
//COMMENT: FROM HERE IT'S REALLY DIFFICULT FOR ME AS i DON'T KNOW PHP AT ALL
if (preg_match('/^{r}([^{]+){\/r:([\w+)}/', $excerpt['text'], $matches))
{
return array(
'extent' => strlen($matches[0]),
'element' => array (
'name' => 'ruby'
'text' => array (
'element' => array(
'name' => 'rb',
//COMMENT CHANGE'
'text' => $matches[1]),
'element' => array(
'name' => 'rt'
'text' => $matches[2]),
),
),
),
);
}
};
}
}
renamed plugin to MardownRubyText on the model of MarkdownColor,
Here actual redaction of markdown-rubytext.php
<?php
namespace Grav\Plugin;
use \Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event;
class MarkdownRubyTextPlugin extends Plugin
{
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'onMarkdownInitialized' => ['onMarkdownInitialized', 0],
];
}
public function onMarkdownInitialized()
{
$markdown = $event['markdown'];
// Initialize Text example
$markdown->addInlineType('{', 'RubyText');
// Add function to handle this
$markdown->inlineRubyText = function($excerpt) {
if (preg_match('/^{r}([^{]+){\/r:([#\w]\w+)}/', $excerpt['text'], $matches))
{
return array(
'extent' => strlen($matches[0]),
'element' => array (
'name' => 'ruby',
'text' => array (
'element' => array(
'name' => 'rb',
'text' => $matches[1]),
'element' => array(
'name' => 'rt',
'text' => $matches[2]),
),
),
),
);
}
};
}
}
Here actual redaction of markdown-rubytext.yaml
enabled: true
Here actual redaction of blueprint.yaml
name: Markdown RubyText
version: 0.7.0
description: "Adds ability to output ruby tag text in Markdown"
icon: asterisk
author:
name: François Vidit
email: postmaster@francois-vidit.fr
url: http://francois-vidit.fr
license: MIT
form:
validation: strict
fields:
enabled:
type: toggle
label: Plugin status
highlight: 1
default: 0
options:
1: Enabled
0: Disabled
validate:
type: bool
Here the error I get (it’s getting better!)
I don’t really understand as ERROR occurs at a level that is exactly similar to plugin MarkdownColor… At such a level, I need php experience which I do not have yet. Capture4
As a reminder: this is {r}日本語{/r:にほんご}
—html
日本語にほんご
and it's gicing actually:
`{r}日本語{/r:にほんご}`
I don't understand this line:
`preg_match('/^{r}([^{]+){\/r:([\w]\w+)}/', $excerpt['text'], $matches)`
that I wrote it on the model of plugin `markdown-color`, adapting to goal.
Thanks in advance for your support ♪
below for rememberance, the actual code of `markdown-rubytext.php`:
<?php
namespace Grav\Plugin;
use \Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event;
class MarkdownRubyTextPlugin extends Plugin
{
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
‘onMarkdownInitialized’ => [‘onMarkdownInitialized’, 0],
];
}
public function onMarkdownInitialized(Event $event)
{
$markdown = $event[‘markdown’];
// Initialize Text example
$markdown->addInlineType(’{’, ‘RubyText’);
// Add function to handle this
$markdown->inlineRubyText = function($excerpt) {
if (preg_match(’/^{r}([^{]+){/r:([\w]\w+)}/’, $excerpt[‘text’], $matches))
{
return array(
‘extent’ => strlen($matches[0]),
‘element’ => array (
‘name’ => ‘ruby’,
‘text’ => array (
‘element’ => array(
‘name’ => ‘rb’,
‘text’ => $matches[1]),
‘element’ => array(
‘name’ => ‘rt’,
‘text’ => $matches[2]),
),
),
);
}
};
}
}