Skip to content

Commit

Permalink
Clean up README.
Browse files Browse the repository at this point in the history
  • Loading branch information
franzliedke committed Mar 21, 2015
1 parent 04d0725 commit f757c93
Showing 1 changed file with 1 addition and 104 deletions.
105 changes: 1 addition & 104 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ An object oriented, fully extensible CommonMark parser for PHP 5.4 and above.
[**CommonMark spec**][commonmark-spec]

* Forked from [Ciconia](https://github.com/kzykhys/ciconia) by [Kazuyuki Hayashi](https://github.com/kzykhys)
* [Github Flavored Markdown](https://help.github.com/articles/github-flavored-markdown) support (disabled by default)
* Multiple underscores in words
* New lines
* Fenced code blocks
* Task lists
* Table
* URL Autolinking
* Tested to comply with the [full CommonMark spec test suite][commonmark-spec]

## Requirements
Expand All @@ -36,7 +29,7 @@ Next, use Composer to install the library and its dependencies:

## Usage

### Traditional Markdown
### Parsing

```php
use FluxBB\CommonMark\Parser;
Expand All @@ -47,107 +40,11 @@ $html = $parser->render('Markdown is **awesome**');
// <p>Markdown is <em>awesome</em></p>
```

### Options

Option | Type | Default | Description |
-------------------|---------|---------|-------------------------------|
**strict** | boolean | false | Throws exception if markdown contains syntax error |

``` php
use FluxBB\CommonMark\Parser;

$parser = new Parser();
$html = $parser->render(
'Markdown is **awesome**',
['strict' => true]
);
```

Rendering
---------

The parser renders XHTML by default.

## Extensions

### How to Extend

Creating extensions is easy, you only need to implement the `FluxBB\CommonMark\Extension\ExtensionInterface`.

Your class must implement two methods.

#### _void_ register(`FluxBB\CommonMark\Markdown` $markdown)

Register any callbacks with the markdown event manager.
`FluxBB\CommonMark\Markdown` is an instance of the `FluxBB\CommonMark\Event\EmitterInterface` (similar to Node's EventEmitter)

#### _string_ getName()

Returns the name of your extension.
If your name is the same as one of the core extensions, the latter will be replaced by your extension.

### Extension Example

This sample extension turns any `@username` mentions into links.

``` php
<?php

use FluxBB\CommonMark\Common\Text;
use FluxBB\CommonMark\Extension\ExtensionInterface;

class MentionExtension implements ExtensionInterface
{

/**
* {@inheritdoc}
*/
public function register(\FluxBB\CommonMark\Markdown $markdown)
{
$markdown->on('inline', [$this, 'processMentions']);
}

/**
* @param Text $text
*/
public function processMentions(Text $text)
{
// Turn @username into [@username](http://example.com/user/username)
$text->replace('/(?:^|[^a-zA-Z0-9.])@([A-Za-z]+[A-Za-z0-9]+)/', function (Text $w, Text $username) {
return '[@' . $username . '](http://example.com/user/' . $username . ')';
});
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'mention';
}
}
```

Register your extension.

``` php
<?php

require __DIR__ . '/vendor/autoload.php';

$parser = new \FluxBB\CommonMark\Parser();
$parser->addExtension(new MentionExtension());
echo $parser->render('@admin my email address is [email protected]!');
```

Output

``` html
<p><a href="http://example.com/user/admin">@admin</a> my email address is [email protected]!</p>
```

Each extension handles string as a `Text` object. See [API section of kzykhys/Text][textapi].

## Command Line Interface

### Usage
Expand Down

0 comments on commit f757c93

Please sign in to comment.