pull/1/merge
Mira 6 years ago committed by GitHub
commit f225275704
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

2
.gitignore vendored

@ -1,3 +1,3 @@
phpunit.xml
/vendor/
/.idea/

@ -6,51 +6,76 @@
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Update for ParsedownExtra version 0.8.0-beta-1 by ms502040 <mira@neyowo.com>
*
* If you don't want points before checkbox add to style:
* .task-list-item {
* list-style-type: none;
* }
* .task-list-item-checkbox {
* margin: 0 0.2em 0.25em -1.6em;
* vertical-align: middle;
* }
*/
class ParsedownCheckbox extends ParsedownExtra
{
const VERSION = '0.0.2';
const VERSION = '0.1.1';
protected function blockListComplete($block)
{
if (null === $block) {
return null;
}
/**
* ParsedownCheckbox constructor.
*
* @throws \Exception Incompatible parent version
*/
function __construct()
{
if (version_compare(parent::version, '0.8.0-beta-1', '<')) {
throw new Exception('ParsedownCheckbox requires a minimum version 0.8.0-beta-1 of ParsedownExtra');
}
if (
false === isset($block['element'])
|| false === isset($block['element']['text'])
|| false === is_array($block['element']['text'])
) {
return $block;
}
try {
ParsedownExtra::__construct();
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}
$count_element = count($block['element']['text']);
for ($iterator_element = 0; $iterator_element < $count_element; $iterator_element++) {
if (
false === isset($block['element']['text'][$iterator_element]['text'])
|| false === is_array($block['element']['text'][$iterator_element]['text'])
) {
continue;
}
$count_text = count($block['element']['text'][$iterator_element]['text']);
for ($iterator_text = 0; $iterator_text < $count_text; $iterator_text++) {
$begin_line = substr(trim($block['element']['text'][$iterator_element]['text'][$iterator_text]), 0, 4);
if ('[ ] ' === $begin_line) {
$block['element']['text'][$iterator_element]['text'][$iterator_text] = '<input type="checkbox" disabled /> '.
substr(trim($block['element']['text'][$iterator_element]['text'][$iterator_text]), 4);
$block['element']['text'][$iterator_element]['attributes'] = ['class' => 'parsedown-task-list parsedown-task-list-open'];
} elseif ('[x] ' === $begin_line) {
$block['element']['text'][$iterator_element]['text'][$iterator_text] = '<input type="checkbox" checked disabled /> '.
substr(trim($block['element']['text'][$iterator_element]['text'][$iterator_text]), 4);
$block['element']['text'][$iterator_element]['attributes'] = ['class' => 'parsedown-task-list parsedown-task-list-close'];
}
}
protected function blockListComplete(array $block)
{
if (null === $block) {
return null;
}
if (!(isset($block['element']) && ($block['element']['name'] === 'ul') && is_array($block['element']['elements']))
) {
return $block;
}
foreach ($block['element']['elements'] as &$element) {
if (!isset($element['handler']['argument'][0])) {
continue;
}
$begin_line = substr(trim($element['handler']['argument'][0]), 0, 4);
$re = '/.*(\s{2,})$/';
if ('[ ] ' === $begin_line) {
if (preg_match_all($re, $element['handler']['argument'][0], $matches, PREG_SET_ORDER, 0) > 0) {
$element['handler']['argument'][0] = trim($element['handler']['argument'][0]) . '<br>';
}
$element['handler']['argument'][0] = '<input type="checkbox" class="task-list-item-checkbox" disabled /> ' . substr($element['handler']['argument'][0], 4);
$element['attributes'] = array('class' => 'task-list-item');
return $block;
} elseif ('[x] ' === $begin_line) {
if (preg_match_all($re, $element['handler']['argument'][0], $matches, PREG_SET_ORDER, 0) > 0) {
$element['handler']['argument'][0] = trim($element['handler']['argument'][0]) . '<br>';
}
$element['handler']['argument'][0] = '<input type="checkbox" class="task-list-item-checkbox" checked disabled /> ' . substr($element['handler']['argument'][0], 4);
$element['attributes'] = array('class' => 'task-list-item');
}
}
}
unset($element);
$block['element']['attributes'] = array('class' => 'contains-task-list');
return $block;
}
}

@ -10,13 +10,18 @@
"name": "Simon Leblanc",
"email": "contact@leblanc-simon.eu",
"homepage": "https://www.leblanc-simon.fr"
},
{
"name": "NEYOWO",
"email": "mira@neyowo.com",
"homepage": "https://neyowo.com"
}
],
"require": {
"erusev/parsedown-extra": "^0.7.1"
"erusev/parsedown": "1.8.0-beta-4",
"erusev/parsedown-extra": "0.8.0-beta-1"
},
"autoload": {
"files": ["ParsedownCheckbox.php"]
}
}

42
composer.lock generated

@ -1,29 +1,32 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"hash": "9736195b93bfa2cec806d78b0c8661aa",
"content-hash": "655332acfbe94cf5bf8be89a4df9b70e",
"content-hash": "945149d723dda7bfd03e649ff058f8b4",
"packages": [
{
"name": "erusev/parsedown",
"version": "1.6.2",
"version": "1.8.0-beta-4",
"source": {
"type": "git",
"url": "https://github.com/erusev/parsedown.git",
"reference": "1bf24f7334fe16c88bf9d467863309ceaf285b01"
"reference": "1f69f7e69797104e73fdceaae22a4b4e3978f0a4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/erusev/parsedown/zipball/1bf24f7334fe16c88bf9d467863309ceaf285b01",
"reference": "1bf24f7334fe16c88bf9d467863309ceaf285b01",
"url": "https://api.github.com/repos/erusev/parsedown/zipball/1f69f7e69797104e73fdceaae22a4b4e3978f0a4",
"reference": "1f69f7e69797104e73fdceaae22a4b4e3978f0a4",
"shasum": ""
},
"require": {
"ext-mbstring": "*",
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35"
},
"type": "library",
"autoload": {
"psr-0": {
@ -47,24 +50,30 @@
"markdown",
"parser"
],
"time": "2017-03-29 16:04:15"
"time": "2018-05-08T21:46:15+00:00"
},
{
"name": "erusev/parsedown-extra",
"version": "0.7.1",
"version": "0.8.0-beta-1",
"source": {
"type": "git",
"url": "https://github.com/erusev/parsedown-extra.git",
"reference": "0db5cce7354e4b76f155d092ab5eb3981c21258c"
"reference": "e756b1bf8642ab1091403e902b0503f1cec7527d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/erusev/parsedown-extra/zipball/0db5cce7354e4b76f155d092ab5eb3981c21258c",
"reference": "0db5cce7354e4b76f155d092ab5eb3981c21258c",
"url": "https://api.github.com/repos/erusev/parsedown-extra/zipball/e756b1bf8642ab1091403e902b0503f1cec7527d",
"reference": "e756b1bf8642ab1091403e902b0503f1cec7527d",
"shasum": ""
},
"require": {
"erusev/parsedown": "~1.4"
"erusev/parsedown": "^1.8.0|^1.8.0-beta-4",
"ext-dom": "*",
"ext-mbstring": "*",
"php": ">=5.3.6"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35"
},
"type": "library",
"autoload": {
@ -91,13 +100,16 @@
"parsedown",
"parser"
],
"time": "2015-11-01 10:19:22"
"time": "2018-05-08T21:54:32+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"stability-flags": {
"erusev/parsedown": 10,
"erusev/parsedown-extra": 10
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],

@ -0,0 +1,62 @@
### test GitHub's checkbos
~~~~
- [ ] test 1
- [] test 2
- [x] test 3
- [ ] test 4
- [x] test 5
- [test](https://markdown.org) 6
- [x](https://markdown.org) test 7
another
- [ ] test 10
- [x] test 10
list
- test 20
- test 21
~~~~
- [ ] test 1
- [] test 2
- [x] test 3
- [ ] test 4
- [x] test 5
- [test](https://markdown.org) 6
- [x](https://markdown.org) test 7
another
- [ ] test 10
- [x] test 10
list
- test 20
- test 21
~~~~html
<ul class="contains-task-list">
<li class="task-list-item"><input id="" disabled="" class="task-list-item-checkbox" type="checkbox"> test 1</li>
<li>[] test 2</li>
<li class="task-list-item"><input id="" disabled="" class="task-list-item-checkbox" checked="" type="checkbox"> test 3
<ul class="contains-task-list">
<li class="task-list-item"><input id="" disabled="" class="task-list-item-checkbox" type="checkbox"> test 4</li>
<li class="task-list-item"><input id="" disabled="" class="task-list-item-checkbox" checked="" type="checkbox"> test 5</li>
</ul>
</li>
<li><a href="https://markdown.org" rel="nofollow">test</a> 6</li>
<li><a href="https://markdown.org" rel="nofollow">x</a> test 7</li>
</ul>
<p>another</p>
<ul class="contains-task-list">
<li class="task-list-item"><input id="" disabled="" class="task-list-item-checkbox" type="checkbox"> test 10</li>
<li class="task-list-item"><input id="" disabled="" class="task-list-item-checkbox" checked="" type="checkbox"> test 10</li>
</ul>
<p>list</p>
<ul>
<li>test 20</li>
<li>test 21</li>
</ul>
~~~~
Loading…
Cancel
Save