Skip to content

Instantly share code, notes, and snippets.

@leblanc-simon
Created May 29, 2019 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leblanc-simon/798a4fde9b410b207b32744c728fc706 to your computer and use it in GitHub Desktop.
Save leblanc-simon/798a4fde9b410b207b32744c728fc706 to your computer and use it in GitHub Desktop.
avoid double encoding with line
<?php
class ParsedownCheckbox extends ParsedownExtra
{
protected function checkboxUnchecked($text)
{
if ($this->markupEscaped || $this->safeMode) {
$text = self::escape($text);
// Disable escape to convert data with line (avoid double encoding)
$this->disableEspace();
$text = $this->line($text);
// Re-enable escape
$this->enableEspace();
} else {
$text = $this->line($text);
}
return '<input type="checkbox" disabled /> '.$text;
}
protected function checkboxChecked($text)
{
if ($this->markupEscaped || $this->safeMode) {
$text = self::escape($text);
// Disable escape to convert data with line (avoid double encoding)
$this->disableEspace();
$text = $this->line($text);
// Re-enable escape
$this->enableEspace();
} else {
$text = $this->line($text);
}
return '<input type="checkbox" checked disabled /> '.$text;
}
private function disableEspace()
{
if ($this->markupEscaped) {
$this->setMarkupEscaped(false);
}
if ($this->safeMode) {
$this->setSafeMode(false);
}
}
private function enableEspace()
{
if (!$this->markupEscaped) {
$this->setMarkupEscaped(true);
}
if (!$this->safeMode) {
$this->setSafeMode(true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment