Skip to content

Instantly share code, notes, and snippets.

@zmax
Last active December 15, 2015 15:09
Show Gist options
  • Save zmax/5279571 to your computer and use it in GitHub Desktop.
Save zmax/5279571 to your computer and use it in GitHub Desktop.
Parsing Github Fenced code blocks
Route::get('/regtest', function(){
$test = '
```php
use Namespace1\Namespace2\Namespace3;
class Article extends Model
{
public function identifiableName()
{
return $this->title;
}
}
```
```javascript
use Namespace1\Namespace2\Namespace3;
class Article extends Model
{
public function identifiableName()
{
return $this->title;
}
}
```
';
$test = addslashes($test);
// Added by Starck Lin - parsing Github Fenced code blocks
$test = preg_replace("/\n```([A-z :]+)([^```]+?)\n```/", '<pre class="lang:$1">$2</pre>', $content );
$test = preg_replace("/\n```([^```]+?)\n```/", '<pre>$1</pre>;', $content );
return $test;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment