Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom html tags and attributes #68

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
setting DefinitionRev to 1 to make sure the HTML5 defs are not alread…
…y cached and locked for modifying
  • Loading branch information
Maurits committed Apr 11, 2024
commit fb0e322bb42990c31d115b8dcdc2e3a164855ae2
16 changes: 6 additions & 10 deletions EditorJS/BlockHandler.php
Original file line number Diff line number Diff line change
@@ -245,14 +245,10 @@ private function getPurifier($allowedTags)

$sanitizer->set('HTML.Allowed', $allowedTags);

/**
* Define custom HTML Definition for mark tool

if ($def = $sanitizer->maybeGetRawHTMLDefinition()) {
$def->addElement('mark', 'Inline', 'Inline', 'Common');
// modify the raw HTML definition
$this->addCustomHTMLDefinitions($def);
}
*/
$this->addCustomHTMLDefinitions($sanitizer);

$purifier = new \HTMLPurifier($sanitizer);

@@ -262,10 +258,9 @@ private function getPurifier($allowedTags)
/**
* TODO
*/
private function addCustomHTMLDefinitions($sanitizer)
private function addCustomHTMLDefinitions($def)
{
if($this->rules->customTags){
$def = $sanitizer->maybeGetRawHTMLDefinition();

// default to be added
$def->addElement('mark', 'Inline', 'Inline', 'Common');
@@ -276,13 +271,13 @@ private function addCustomHTMLDefinitions($sanitizer)
* @param string $element Name of element to add
* @param string|bool $type What content set should element be registered to?
* Set as false to skip this step.
* @param string|HTMLPurifier_ChildDef $contents Allowed children in form of:
* @param string|\HTMLPurifier_ChildDef $contents Allowed children in form of:
* "$content_model_type: $content_model"
* @param array|string $attr_includes What attribute collections to register to
* element?
* @param array $attr What unique attributes does the element define?
* @see HTMLPurifier_ElementDef:: for in-depth descriptions of these parameters.
* @return HTMLPurifier_ElementDef Created element definition object, so you
* @return \HTMLPurifier_ElementDef Created element definition object, so you
* can set advanced parameters
*/

@@ -363,6 +358,7 @@ private function getDefaultPurifier()
$sanitizer->set('URI.AllowedSchemes', ['http' => true, 'https' => true, 'mailto' => true, 'tel' => true]);
$sanitizer->set('AutoFormat.RemoveEmpty', true);
$sanitizer->set('HTML.DefinitionID', 'html5-definitions');
$sanitizer->set('HTML.DefinitionRev', 1);

$cacheDirectory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'purifier';
if (!is_dir($cacheDirectory)) {