Skip to content

Conversation

@oiseauroch
Copy link
Contributor

@oiseauroch oiseauroch commented Oct 14, 2025

Current behavior

Creating a new component with body and then as a closing {{end elem="mycustomelement" }} element require to add code in the core of yeswiki to add **customelement** into end.php` file.

Expected behavior

I would like to be ablo to add a custom element without modifying something that could be removed by update.

Proposal

We could had a default case for end element that look for a end() fonction in the extra YesWiki action like this :

            default:
                echo $this->services->get(Performer::class)->run($elem, 'action', [], true);
                break;
  • proposition validated
  • implementation tested

@oiseauroch
Copy link
Contributor Author

a new custom action can now be written as :

<?php

use YesWiki\Core\YesWikiAction;

class ColorAction extends YesWikiAction
{

    public function run()
    {
        $class = $this->arguments['class'] ?? '';
        $color = $this->arguments['color'] ?? (empty($class) ? 'var(--neutral-color)': 'var(--' . $class . ')' );

        if ($this->check_end_elem('color')) {
            return "<span class='color-elem' style='color: $color;'>";
        } else {
            return $this->generate_error_msg('color');
        }

    }

    public function end(): string {
        return '</span>';
    }
}

and use like this :

{{color color="#FFFFFF"}}
my colored text
{{end elem="color"}}

@mrflos
Copy link
Contributor

mrflos commented Jan 29, 2026

Hi @oiseauroch !
Sorry, i didn't find the time to check on your proposal before...
But i like it!!

I think we should change all existing actions using end before merging.

Also i have some minor changes to propose like coding styles (class Method should be camelCased(), we no 🦀 )
And maybe just raise an error in the checkEndElem() that we can caught at a higher level, i like the idea of a method for error messages but it should be more generic like generateMsg(string $message,string $type = 'error') but this should not be in this PR scope.

Do you plan to come to Lyon for yeswiki sprint in march?

Regards

@oiseauroch
Copy link
Contributor Author

Nice !

I think we should change all existing actions using end before merging.

It's not a little work because all actions using end are not yet class of YesWikiAction and then should be heavily tested.

Feel free to rework this PR as you want. I'm not sure about how do you want to do with error raising in checkEndElem().

I'm not sure for the sprint in March but could you remind me the date ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants