nadar / quill-delta-parser

A PHP library to parse and render Quill WYSIWYG Deltas into HTML - Flexibel and extendible for custom elements.
MIT License
121 stars 20 forks source link

Font size Feature #89

Open joelsantosbr opened 1 month ago

joelsantosbr commented 1 month ago

Describe the bug Size attribute is not being recognized as default

The delta code which generates the Problem

Example:

{
    "attributes": {
        "color": "#e74c3c",
        "size": "21pt",
        "font": "Lancelot, cursive"
    },
    "insert": "Lorem ipsum!"
}

I create this new listener

class Size extends InlineListener
{
    /**
     * {@inheritDoc}
     */
    public function process(Line $line)
    {
        $size = $line->getAttribute('size');
        if ($size) {
            $this->updateInput($line, $this->applyTemplate($size, $line));
        }
    }

    public function applyTemplate($size, Line $line)
    {
        return '<span style="font-size: '.$line->getLexer()->escape($size).';">'. $line->getInput() . '</span>';
    }
}

Is possible to add by default in your lib?

nadar commented 1 month ago

hi @joelsantosbr, nice that you could easy get your job done by extending the parser, but yes i think this would make sense :+1: Would you like to create a pull request? Version would be 3.5

joelsantosbr commented 1 month ago

great, i will create ; )