Skip to content

Commit

Permalink
update readme and mention plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Oct 8, 2018
1 parent 883d8cb commit 252bc97
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 35 deletions.
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,13 @@ class Mention extends InlineListener
*/
public function process(Line $line)
{
// as "insert" value is not a string, it contains json notiation content:
if ($line->isJsonInsert()) {
// parse the given json into an array
$array = $line->getArrayInsert();
// it seems the array has a key with the name "mention":
if (isset($array['mention'])) {
// use default inline behavior, updates the content and append to next "block" element.
$this->updateInput($line, $array['mention']['value']);
}
}
// check if input is json, decodes to an array and checks if the key "mention"
// exsts, if yes return the value for this key.
$mention = $line->insertJsonKey('mention');
if ($mention) {
// use default inline behavior, updates the content and append to next "block" element.
// the value in this example would be "<mention>Basil</mention>".
$this->updateInput($line, '<mention>'.$mention['value'].'</mention>');
}
}
```
Expand Down
38 changes: 19 additions & 19 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions src/listener/Mention.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ class Mention extends InlineListener
*/
public function process(Line $line)
{
// @todo use: $line->insertJsonKey('mention');
if ($line->isJsonInsert()) {
$array = $line->getArrayInsert();
if (isset($array['mention'])) {
$this->updateInput($line, $array['mention']['value']);
}
$mention = $line->insertJsonKey('mention');

if ($mention) {
$this->updateInput($line, $mention['value']);
}
}
}

0 comments on commit 252bc97

Please sign in to comment.