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

Expose quill parser format and blot classes #9860

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
79 changes: 79 additions & 0 deletions library/Vanilla/Formatting/Quill/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,83 @@ private function stripTrailingNewlines(array &$operations) {
$lastOp["insert"] = preg_replace('/\s+$/', "\n", $lastOp["insert"]);
}
}

/**
* Replace a registered blot class.
*
* @return bool
* @throws \Exception If the replacement class isn't a subclass of the existing blot class.
*/
public function replaceBlot(string $newBlotClass, string $existingBlotClass): bool {
if (!is_subclass_of($newBlotClass, $existingBlotClass)) {
throw new \Exception($newBlotClass . " should be a subclass of " . $existingBlotClass);
}

$key = array_search($existingBlotClass, $this->blotClasses);

if ($key !== false) {
$this->blotClasses[$key] = $newBlotClass;

return true;
}

return false;
}

/**
* Remove a registered blot class.
*
* @return bool
*/
public function removeBlot(string $existingBlotClass): bool {
$key = array_search($existingBlotClass, $this->blotClasses);

if ($key !== false) {
unset($this->blotClasses[$key]);

return true;
}

return false;
}

/**
* Replace a registered format class.
*
* @return bool
* @throws \Exception If the replacement class isn't a subclass of the existing format class.
*/
public function replaceFormat(string $newFormatClass, string $existingFormatClass): bool {
if (!is_subclass_of($newFormatClass, $existingFormatClass)) {
throw new \Exception($newFormatClass . " should be a subclass of " . $existingFormatClass);
}

$key = array_search($existingFormatClass, $this->formatClasses);

if ($key !== false) {
$this->formatClasses[$key] = $newFormatClass;

return true;
}

return false;
}

/**
* Remove a registered format class.
*
* @return bool
*/
public function removeFormat(string $existingFormatClass): bool {
$key = array_search($existingFormatClass, $this->formatClasses);

if ($key !== false) {
unset($this->formatClasses[$key]);

return true;
}

return false;
}

}