Skip to content

Commit 686d7e2

Browse files
doekenorgleblanc-simon
authored andcommitted
Format checkbox text
1 parent bdf632d commit 686d7e2

File tree

4 files changed

+1516
-10
lines changed

4 files changed

+1516
-10
lines changed

ParsedownCheckbox.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* This file is part of the ParsedownCheckbox package.
45
*
@@ -9,7 +10,7 @@
910
*/
1011
class ParsedownCheckbox extends ParsedownExtra
1112
{
12-
const VERSION = '0.1.0';
13+
const VERSION = '0.2.0';
1314

1415
public function __construct()
1516
{
@@ -73,7 +74,7 @@ protected function checkboxUnchecked($text)
7374
$text = self::escape($text);
7475
}
7576

76-
return '<input type="checkbox" disabled /> '.$text;
77+
return '<input type="checkbox" disabled /> ' . $this->format($text);
7778
}
7879

7980
protected function checkboxChecked($text)
@@ -82,6 +83,31 @@ protected function checkboxChecked($text)
8283
$text = self::escape($text);
8384
}
8485

85-
return '<input type="checkbox" checked disabled /> '.$text;
86+
return '<input type="checkbox" checked disabled /> ' . $this->format($text);
87+
}
88+
89+
/**
90+
* Formats the checkbox label without double escaping.
91+
* @param string $text the string to format
92+
* @return string the formatted text
93+
*/
94+
protected function format($text)
95+
{
96+
// backup settings
97+
$markup_escaped = $this->markupEscaped;
98+
$safe_mode = $this->safeMode;
99+
100+
// disable rules to prevent double escaping.
101+
$this->setMarkupEscaped(false);
102+
$this->setSafeMode(false);
103+
104+
// format line
105+
$text = $this->line($text);
106+
107+
// reset old values
108+
$this->setMarkupEscaped($markup_escaped);
109+
$this->setSafeMode($safe_mode);
110+
111+
return $text;
86112
}
87113
}

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
"erusev/parsedown-extra": "^0.8.0-beta-1",
1717
"erusev/parsedown": "^1.8.0-beta"
1818
},
19+
"require-dev": {
20+
"phpunit/phpunit": "^7.5"
21+
},
1922
"autoload": {
2023
"files": ["ParsedownCheckbox.php"]
2124
}
2225
}
23-

0 commit comments

Comments
 (0)