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 phpunit.xml
/vendor/ /vendor/
/.idea/

@ -6,51 +6,76 @@
* *
* For the full copyright and license information, please view the LICENSE * For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code. * 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 class ParsedownCheckbox extends ParsedownExtra
{ {
const VERSION = '0.0.2'; const VERSION = '0.1.1';
protected function blockListComplete($block) /**
{ * ParsedownCheckbox constructor.
if (null === $block) { *
return null; * @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 ( try {
false === isset($block['element']) ParsedownExtra::__construct();
|| false === isset($block['element']['text']) } catch (Exception $e) {
|| false === is_array($block['element']['text']) throw new Exception($e->getMessage());
) { }
return $block; }
}
$count_element = count($block['element']['text']); protected function blockListComplete(array $block)
for ($iterator_element = 0; $iterator_element < $count_element; $iterator_element++) { {
if ( if (null === $block) {
false === isset($block['element']['text'][$iterator_element]['text']) return null;
|| false === is_array($block['element']['text'][$iterator_element]['text']) }
) {
continue; if (!(isset($block['element']) && ($block['element']['name'] === 'ul') && is_array($block['element']['elements']))
} ) {
return $block;
$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); foreach ($block['element']['elements'] as &$element) {
if ('[ ] ' === $begin_line) { if (!isset($element['handler']['argument'][0])) {
$block['element']['text'][$iterator_element]['text'][$iterator_text] = '<input type="checkbox" disabled /> '. continue;
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']; $begin_line = substr(trim($element['handler']['argument'][0]), 0, 4);
} elseif ('[x] ' === $begin_line) { $re = '/.*(\s{2,})$/';
$block['element']['text'][$iterator_element]['text'][$iterator_text] = '<input type="checkbox" checked disabled /> '. if ('[ ] ' === $begin_line) {
substr(trim($block['element']['text'][$iterator_element]['text'][$iterator_text]), 4); if (preg_match_all($re, $element['handler']['argument'][0], $matches, PREG_SET_ORDER, 0) > 0) {
$block['element']['text'][$iterator_element]['attributes'] = ['class' => 'parsedown-task-list parsedown-task-list-close']; $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", "name": "Simon Leblanc",
"email": "contact@leblanc-simon.eu", "email": "contact@leblanc-simon.eu",
"homepage": "https://www.leblanc-simon.fr" "homepage": "https://www.leblanc-simon.fr"
},
{
"name": "NEYOWO",
"email": "mira@neyowo.com",
"homepage": "https://neyowo.com"
} }
], ],
"require": { "require": {
"erusev/parsedown-extra": "^0.7.1" "erusev/parsedown": "1.8.0-beta-4",
"erusev/parsedown-extra": "0.8.0-beta-1"
}, },
"autoload": { "autoload": {
"files": ["ParsedownCheckbox.php"] "files": ["ParsedownCheckbox.php"]
} }
} }

42
composer.lock generated

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