-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bb0db1b
Showing
248 changed files
with
4,659 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/vendor/ | ||
/build/ | ||
composer.lock | ||
composer.phar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
language: php | ||
|
||
php: | ||
- 5.5 | ||
- 5.4 | ||
|
||
before_script: | ||
- curl -s http://getcomposer.org/installer | php | ||
- php composer.phar install --dev --no-interaction | ||
|
||
script: | ||
- mkdir -p build/logs | ||
- phpunit -c phpunit.xml.dist --coverage-clover build/logs/clover.xml | ||
|
||
after_script: | ||
- php vendor/bin/coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Copyright (c) 2013 Kazuyuki Hayashi | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
Ciconia - A New Markdown Parser for PHP | ||
======================================= | ||
|
||
The Markdown parser for PHP5.4, it is fully extensible. | ||
Ciconia is the collection of extension, so you can replace, add or remove each parsing mechanism. | ||
|
||
* Based on John Gruber's Markdown.pl | ||
|
||
* Github flavored markdown support. (disabled by default) | ||
|
||
* Multiple underscores in words | ||
* New lines | ||
* Fenced code blocks | ||
* Task lists | ||
|
||
* Tested with markdown-testsuite. | ||
|
||
Requirements | ||
------------ | ||
|
||
* PHP5.4+ | ||
* Composer | ||
|
||
Installation | ||
------------ | ||
|
||
create a `composer.json` | ||
|
||
``` json | ||
{ | ||
"require": { | ||
"kzykhys/ciconia": "0.1.*" | ||
} | ||
} | ||
``` | ||
|
||
and run | ||
|
||
``` | ||
php composer.phar install | ||
``` | ||
|
||
Usage | ||
----- | ||
|
||
### Traditional Markdown | ||
|
||
``` php | ||
use Ciconia\Ciconia; | ||
|
||
$ciconia = new Ciconia(); | ||
$html = $ciconia->render('Markdown is **awesome**'); | ||
|
||
// <p>Markdown is <em>awesome</em></p> | ||
``` | ||
|
||
### Github Flavored Markdown | ||
|
||
To activate 4 gfm features: | ||
|
||
``` php | ||
use Ciconia\Ciconia; | ||
use Ciconia\Extension\Gfm; | ||
|
||
$ciconia = new Ciconia(); | ||
$ciconia->addExtension(new Gfm\FencedCodeBlockExtension()); | ||
$ciconia->addExtension(new Gfm\TaskListExtension()); | ||
$ciconia->addExtension(new Gfm\InlineStyleExtension()); | ||
$ciconia->addExtension(new Gfm\WhiteSpaceExtension()); | ||
|
||
$html = $ciconia->render('Markdown is **awesome**'); | ||
|
||
// <p>Markdown is <em>awesome</em></p> | ||
``` | ||
|
||
Options | ||
------- | ||
|
||
Option | Type | Default | Description | | ||
---------------|---------|---------|-------------------------------| | ||
**tabWidth** | integer | 4 | Number of spaces | | ||
**nestedTagLevel** | integer | 3 | Max depth of nested HTML tags | | ||
|
||
``` php | ||
use Ciconia\Ciconia; | ||
|
||
$ciconia = new Ciconia(); | ||
$html = $ciconia->render('Markdown is **awesome**', array('tabWidth' => 8, 'nestedTagLevel' => 5)); | ||
``` | ||
|
||
Extend Ciconia | ||
-------------- | ||
|
||
### How to Extend | ||
|
||
Creating extension is easy, just implement `ExtensionInterface`. | ||
|
||
Your class must implement 2 methods. | ||
|
||
#### _void_ register(`Ciconia\Markdown` $markdown) | ||
|
||
Register your callback to markdown event manager. | ||
`Ciconia\Markdown` is instance of `Ciconia\Event\EmitterInterface` (looks like Node.js's EventEmitter) | ||
|
||
#### _string_ getName() | ||
|
||
Returns the name of your extension. | ||
If your name is the same as one of core extension, it will be replaced by your extension. | ||
|
||
### Extension Example | ||
|
||
``` php | ||
<?php | ||
|
||
use Ciconia\Common\Text; | ||
use Ciconia\Extension\ExtensionInterface; | ||
use Ciconia\Markdown; | ||
|
||
class YourExtension implements ExtensionInterface | ||
{ | ||
// Necessary if your extension calls other events | ||
$this->markdown; | ||
|
||
//@implement | ||
public function register(Markdown $markdown) | ||
{ | ||
// Necessary if your extension calls another event | ||
$this->markdown = $markdown; | ||
|
||
$markdown->on('block', array($this, 'processBlock')); | ||
} | ||
|
||
//@implement | ||
public function getName() | ||
{ | ||
return 'yourExtension'; | ||
} | ||
|
||
public function processBlock(Text $text) | ||
{ | ||
// Do regexp's | ||
$text->replace('/foo(bar)(baz)/', function (Text $whole, Text $bar, $text $baz) { | ||
// You can call other events registered by other extension | ||
$this->markdown->emit('inline', $bar); | ||
|
||
return $baz->upper(); | ||
}); | ||
} | ||
} | ||
``` | ||
|
||
### Events | ||
|
||
Possible events are: | ||
|
||
| Event | Description | | ||
|------------|-------------------------------------------------------------------------------------------| | ||
| initialize | Document level parsing. Called at the first of the sequence. | | ||
| block | Block level parsing. Called after `initialize` | | ||
| inline | Inline level parsing. Generally called by block level parsers. | | ||
| detab | Convert tabs to spaces. Generally called by block level parsers. | | ||
| outdent | Remove one level of line-leading tabs or spaces. Generally called by block level parsers. | | ||
| finalize | Called after `block` | | ||
|
||
[See the source code of Extensions](src/Ciconia/Extension) | ||
|
||
Testing | ||
------- | ||
|
||
Install of update `dev` dependencies. | ||
|
||
``` | ||
php composer.phar updated --dev | ||
``` | ||
|
||
and run `phpunit` | ||
|
||
License | ||
------- | ||
|
||
The MIT License | ||
|
||
Author | ||
------ | ||
|
||
Kazuyuki Hayashi (@kzykhys) | ||
github.com/kzykhys | ||
twitter.com/kzykhys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "kzykhys/ciconia", | ||
"description": "The Markdown parser for PHP5.4", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Kazuyuki Hayashi", | ||
"email": "hayashi@valnur.net" | ||
} | ||
], | ||
"minimum-stability": "stable", | ||
"autoload": { | ||
"psr-0": { | ||
"": "src/" | ||
} | ||
}, | ||
"require": { | ||
"php": ">5.4.0", | ||
"symfony/options-resolver": "2.3.x", | ||
"symfony/console":"2.3.x" | ||
}, | ||
"require-dev": { | ||
"symfony/finder": "2.3.x" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html --> | ||
<phpunit | ||
backupGlobals = "false" | ||
backupStaticAttributes = "false" | ||
colors = "true" | ||
convertErrorsToExceptions = "true" | ||
convertNoticesToExceptions = "true" | ||
convertWarningsToExceptions = "true" | ||
processIsolation = "false" | ||
stopOnFailure = "false" | ||
syntaxCheck = "false" | ||
bootstrap = "vendor/autoload.php" > | ||
|
||
<testsuites> | ||
<testsuite name="Project Test Suite"> | ||
<directory>test</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>src</directory> | ||
</whitelist> | ||
</filter> | ||
|
||
</phpunit> |
Oops, something went wrong.