commit a3b1e7d0519ce08c17982b892ebb093ddb94c1e7 Author: Simon Leblanc Date: Wed May 10 05:05:26 2017 +0200 First version of ParsedownCheckbox diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2298d51 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +phpunit.xml +/vendor/ + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4f87b89 --- /dev/null +++ b/LICENSE @@ -0,0 +1,8 @@ +Copyright (c) 2017 Simon Leblanc + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/ParsedownCheckbox.php b/ParsedownCheckbox.php new file mode 100644 index 0000000..b036d15 --- /dev/null +++ b/ParsedownCheckbox.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +class ParsedownCheckbox extends ParsedownExtra +{ + const VERSION = '0.0.1'; + + protected function blockListComplete($block) + { + if (null === $block) { + return null; + } + + if ( + false === isset($block['element']) + || false === isset($block['element']['text']) + || false === is_array($block['element']['text']) + ) { + return $block; + } + + $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] = ' '. + substr(trim($block['element']['text'][$iterator_element]['text'][$iterator_text]), 4); + } elseif ('[x] ' === $begin_line) { + $block['element']['text'][$iterator_element]['text'][$iterator_text] = ' '. + substr(trim($block['element']['text'][$iterator_element]['text'][$iterator_text]), 4); + } + } + } + + return $block; + } +} + diff --git a/README.md b/README.md new file mode 100644 index 0000000..0244871 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# Parsedown Checkbox + +An extension of [ParsedownExtra](https://github.com/erusev/parsedown-extra) and [Parsedown](http://parsedown.org/) that adds support for task list + +## Installation + +```bash +composer require leblanc-simon/parsedown-checkbox +``` + +## Example + +```php +text(' +- [ ] Add a pull request +- [x] Check the issues +'); +``` + +Prints : + +- [ ] Add a pull request +- [x] Check the issues + +## License + +- [MIT](http://opensource.org/licenses/MIT) + +## Author + +Simon Leblanc + diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a5922d0 --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "name": "leblanc-simon/parsedown-checkbox", + "description": "An extension of Parsedown and ParsedownExtra that adds support for checkbox", + "keywords": ["markdown", "markdown extra", "parser", "parsedown", "checkbox"], + "homepage": "https://github.com/leblanc-simon/parsedown-checkbox", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Simon Leblanc", + "email": "contact@leblanc-simon.eu", + "homepage": "https://www.leblanc-simon.fr" + } + ], + "require": { + "erusev/parsedown-extra": "^0.7.1" + }, + "autoload": { + "files": ["ParsedownCheckbox.php"] + } +} + diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..a18c139 --- /dev/null +++ b/composer.lock @@ -0,0 +1,105 @@ +{ + "_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", + "This file is @generated automatically" + ], + "hash": "9736195b93bfa2cec806d78b0c8661aa", + "content-hash": "655332acfbe94cf5bf8be89a4df9b70e", + "packages": [ + { + "name": "erusev/parsedown", + "version": "1.6.2", + "source": { + "type": "git", + "url": "https://github.com/erusev/parsedown.git", + "reference": "1bf24f7334fe16c88bf9d467863309ceaf285b01" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/erusev/parsedown/zipball/1bf24f7334fe16c88bf9d467863309ceaf285b01", + "reference": "1bf24f7334fe16c88bf9d467863309ceaf285b01", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "autoload": { + "psr-0": { + "Parsedown": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Emanuil Rusev", + "email": "hello@erusev.com", + "homepage": "http://erusev.com" + } + ], + "description": "Parser for Markdown.", + "homepage": "http://parsedown.org", + "keywords": [ + "markdown", + "parser" + ], + "time": "2017-03-29 16:04:15" + }, + { + "name": "erusev/parsedown-extra", + "version": "0.7.1", + "source": { + "type": "git", + "url": "https://github.com/erusev/parsedown-extra.git", + "reference": "0db5cce7354e4b76f155d092ab5eb3981c21258c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/erusev/parsedown-extra/zipball/0db5cce7354e4b76f155d092ab5eb3981c21258c", + "reference": "0db5cce7354e4b76f155d092ab5eb3981c21258c", + "shasum": "" + }, + "require": { + "erusev/parsedown": "~1.4" + }, + "type": "library", + "autoload": { + "psr-0": { + "ParsedownExtra": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Emanuil Rusev", + "email": "hello@erusev.com", + "homepage": "http://erusev.com" + } + ], + "description": "An extension of Parsedown that adds support for Markdown Extra.", + "homepage": "https://github.com/erusev/parsedown-extra", + "keywords": [ + "markdown", + "markdown extra", + "parsedown", + "parser" + ], + "time": "2015-11-01 10:19:22" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..af11c47 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,9 @@ + + + + + test/ParsedownCheckboxTest.php + + + + diff --git a/test/ParsedownCheckboxTest.php b/test/ParsedownCheckboxTest.php new file mode 100644 index 0000000..2ce2121 --- /dev/null +++ b/test/ParsedownCheckboxTest.php @@ -0,0 +1,35 @@ + +
  • test 1
  • +
  • [] test 2
  • +
  • test 3 +
      +
    • test 4
    • +
    • test 5
    • +
  • +
  • test 6
  • +
  • x test 7
  • + +EOF; + + $parsedown = new ParsedownCheckbox(); + $this->assertEquals($html, $parsedown->text($markdown)); + } +} + diff --git a/test/bootstrap.php b/test/bootstrap.php new file mode 100644 index 0000000..7cee29a --- /dev/null +++ b/test/bootstrap.php @@ -0,0 +1,8 @@ +