Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Conversation

Uzziahlukeka
Copy link
Contributor

quand j'essaie de convertir d'about en html , le sanitize n'arrive pas a faire passer les balises et ca ne fonctionne pas alors j'ai essaye ici de sanatize puis convertir alors ceci donne toujours la meme chose les balises ne passent pas ici

<?php

/*
 * This file is part of the EditorJs Sanitizer package.
 *
 * (c) Bernard Ngandu <bernard@devscast.tech>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Devscast\EditorJs\Blocks;

use Devscast\EditorJs\Assert;
use Devscast\EditorJs\Sanitizer;

/**
 * Class Paragraph.
 *
 * Basic text Tool for the Editor.js.
 *
 * @see https://github.com/editor-js/paragraph
 * @see https://github.com/editor-js/footnotes-tune
 * @see https://raw.githubusercontent.com/devscast/editorjs-sanitizer/refs/heads/main/schemas/paragraph.schema.json
 *
 * @author bernard-ng <bernard@devscast.tech>
 */
final readonly class Paragraph extends Block
{
    public function __construct(string $id, string $type, array $data, ?array $tunes, array $rules)
    {
        Assert::eq($type, 'paragraph');
        Assert::keyExists($data, 'text');

        if ($tunes !== null) {
            Assert::keyExists($tunes, 'footnotes');
            Assert::isArray($tunes['footnotes']);
        }

        parent::__construct($id, $type, $data, $tunes, $rules);
    }

    //convertion vers du html brut
    private function toRawHtml(array|string $sanatizedText): string
    {
        return "<p id=\"{$this->id}\">$sanatizedText</p>";
    }
    //nettoyage du html

    private function sanitizeHtml(string $html, array|string $allowedTags = [])
    {
        $sanitizer = Sanitizer::create($allowedTags);
        return $sanitizer->sanitize($html);
    }
    public function toHtml(): string
    {
        $allowedTags = [
            'a' => ['href', 'title', 'rel'],
            'strong' => [],
            'em' => [],
            'u' => [],
            'br' => [],
            'p' => ['id','strong'],
        ];
        $sanitizedHtml = $this->sanitizeHtml($this->data['text'], $allowedTags);
        $rawHtml = $this->toRawHtml($sanitizedHtml);

        dd($rawHtml);
        return $rawHtml;
    }
}
 

`  

@Uzziahlukeka Uzziahlukeka requested a review from bernard-ng March 22, 2025 10:17
@bernard-ng
Copy link
Member

okay je vois, je vais essayer de lancer chez moi

@bernard-ng
Copy link
Member

bernard-ng commented Mar 23, 2025

@Uzziahlukeka crée un fichier index.php à la racine du projet

<?php

use Devscast\EditorJs\Editor;

require __DIR__ . '/vendor/autoload.php';


$data = <<<JSON
{
  "time": 1739980616433,
  "blocks": [
    {
      "id": "mhTl6ghSkV",
      "type": "paragraph",
      "data": {
        "text": "Hey. Meet the new Editor. On this picture you can see it in action. Then, try a demo 🤓"
      }
    },
    {
      "id": "l98dyx3yjb",
      "type": "header",
      "data": {
        "text": "Key features",
        "level": 3
      }
    },
    {
      "id": "os_YI4eub4",
      "type": "list",
      "data": {
        "style": "unordered",
        "meta": {},
        "items": [
          "It is a block-style editor",
          "It returns clean data output in JSON",
          "Designed to be extendable and pluggable with a <a href='https://editorjs.io/creating-a-block-tool'>simple API</a>"
        ]
      }
    },
    {
      "id": "1yKeXKxN7-",
      "type": "header",
      "data": {
        "text": "What does it mean «block-styled editor»",
        "level": 3
      }
    },
    {
      "id": "TcUNySG15P",
      "type": "paragraph",
      "data": {
        "text": "Workspace in classic editors is made of a single contenteditable element, used to create different HTML markups. Editor.js workspace consists of separate Blocks: paragraphs, headings, images, lists, quotes, etc. Each of them is an independent <sup data-tune='footnotes'>1</sup> contenteditable element (or more complex structure) provided by Plugin and united by Editor's Core."
      },
      "tunes": {
        "footnotes": [
          "It works more stable then in other WYSIWYG editors. Same time it has smooth and well-known arrow navigation behavior like classic editors."
        ]
      }
    },
    {
      "id": "M3UXyblhAo",
      "type": "header",
      "data": {
        "text": "What does it mean clean data output?",
        "level": 3
      }
    },
    {
      "id": "KOcIofZ3Z1",
      "type": "paragraph",
      "data": {
        "text": "There are dozens of ready-to-use Blocks and a simple API <sup data-tune='footnotes'>2</sup> for creating any Block you need. For example, you can implement Blocks for Tweets, Instagram posts, surveys and polls, CTA buttons, and even games."
      },
      "tunes": {
        "footnotes": [
          "Just take a look at our Creating Block Tool guide. You'll be surprised."
        ]
      }
    },
    {
      "id": "ksCokKAhQw",
      "type": "paragraph",
      "data": {
        "text": "Classic WYSIWYG editors produce raw HTML-markup with both content data and content appearance. On the contrary, <mark class='cdx-marker'>Editor.js outputs JSON object</mark> with data of each Block."
      }
    },
    {
      "id": "XKNT99-qqS",
      "type": "attaches",
      "data": {
        "file": {
          "url": "https://drive.google.com/user/catalog/my-file.pdf",
          "size": 12902,
          "name": "file.pdf",
          "extension": "pdf"
        },
        "title": "My file"
      }
    },
    {
      "id": "7RosVX2kcH",
      "type": "paragraph",
      "data": {
        "text": "Given data can be used as you want: render with HTML for Web clients, render natively for mobile apps, create the markup for Facebook Instant Articles or Google AMP, generate an audio version, and so on."
      }
    },
    {
      "id": "eq06PsNsab",
      "type": "paragraph",
      "data": {
        "text": "Clean data is useful to sanitize, validate and process on the backend."
      }
    },
    {
      "id": "hZAjSnqYMX",
      "type": "image",
      "data": {
        "file": {
          "url": "assets/codex2x.png"
        },
        "withBorder": false,
        "withBackground": false,
        "stretched": true,
        "caption": "CodeX Code Camp 2019"
      }
    }
  ]
}
JSON;

$editor = new Editor($data);

dd($editor);

pour tester facilement

@bernard-ng
Copy link
Member

@Uzziahlukeka continue avec cette base

@bernard-ng bernard-ng force-pushed the dev branch 2 times, most recently from 1256abb to 266de02 Compare March 23, 2025 02:28
@Uzziahlukeka
Copy link
Contributor Author

d'acccord

Copy link
Member

@bernard-ng bernard-ng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pour tester les blocks par toujours du JSON en utilisant le factory, pour simplifier pour l'instant test juste si on arrive a créer le block a partir d'un json via le factory et le deuxième si on arrive à convertir en html c'est tout.

'table' => Table::create($data, $allowedTags),
'warning' => Warning::create($data, $allowedTags),
};
self::initializeFactories();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

humm là tu crées tous les blocks avec la même donné et stock en mémoire le résultat qui ne sera peut être pas utilisé ! on doit y réfléchir encore un peu mais je ne pense pas qu'il ait un problème de performance à ce niveau.

le problème c'était avec la validation du schema, mais on va gérer ça après

Copy link
Member

@bernard-ng bernard-ng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Uzziahlukeka any updates ?

@Uzziahlukeka
Copy link
Contributor Author

i am a bit lost right now about what i should do before i saw the revision you made and i thought it was done

@bernard-ng
Copy link
Member

bernard-ng commented Apr 8, 2025 via email

@bernard-ng bernard-ng merged commit 947aa8d into main Apr 8, 2025
0 of 4 checks passed
@bernard-ng bernard-ng deleted the dev branch April 8, 2025 18:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants