PHPackages                             calebporzio/gitdown - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. calebporzio/gitdown

AbandonedArchivedLibrary[Parsing &amp; Serialization](/categories/parsing)

calebporzio/gitdown
===================

A simple package to parse Github Flavored Markdown in PHP

v1.3.2(7y ago)21713.8k8[22 PRs](https://github.com/calebporzio/gitdown/pulls)MITPHP

Since Mar 6Pushed 3y ago2 watchersCompare

[ Source](https://github.com/calebporzio/gitdown)[ Packagist](https://packagist.org/packages/calebporzio/gitdown)[ Docs](https://github.com/calebporzio/gitdown)[ RSS](/packages/calebporzio-gitdown/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (2)Versions (30)Used By (0)

[![GitDown - a simple package to parse markdown in PHP](banner.png)](banner.png)

GitDown
=======

[](#gitdown)

A simple package for parsing (GitHub Flavored) Markdown in PHP.

WARNING
-------

[](#warning)

This package is a fraud. All it does is fire off your markdown to a [public GitHub API](https://developer.github.com/v3/markdown/) that returns the parsed result.

Knowing this, if you don't store the result, or take advantage of the provided caching features, you'll end up with slow page loads, or worse, rate-limit errors from GitHub.

Markdown parsing is super annoying, and this tradeoff is well worth it to me, I hope you embrace it as well.

Installation
------------

[](#installation)

```
composer require calebporzio/gitdown
```

TLDR;
-----

[](#tldr)

```
// Optionally set a GitHub Personal Access Token to increase rate-limit.
GitDown::setToken($token);

GitDown::parse($markdown);

// Uses Laravel's cache()->rememberForever() under the hood.
GitDown::parseAndCache($markdown);
```

Optionally, add the `@gitdown` snippet to your template's `` section, and a `.markdown-body` class to a wrapper element, for GitHub markdown/code-syntax styling.

```

    [...]
    @gitdown

        {!! GitDown::parseAndCache($content) !!}

```

Authenticating With GitHub
--------------------------

[](#authenticating-with-github)

Without authentication, GitHub will limit your API calls to 60 calls/hour. If you use authentication tokens, you can increase this limit to 5000 calls/minute. It is highly recommended that you use a "Personal Access Token" with this package. To obtain one, [click here](https://github.com/settings/tokens). (You can leave the permissions blank for this token.)

First, publish the package's config file.

`php artisan vendor:publish --provider="GitDown\GitDownServiceProvider"`

Then, add the following entry to your `.env` file.

```
[...]
GITHUB_TOKEN=your-token-here

```

Usage
-----

[](#usage)

```
GitDown::parse($markdown);

// Will be cached forever. (suggested)
GitDown::parseAndCache($markdown);

// Will be cached for 24 hours. (minutes in Laravel < 5.8, seconds otherwise)
GitDown::parseAndCache($markdown, $seconds = 86400);

// Pass in your own custom caching strategy.
GitDown::parseAndCache($markdown, function ($parse) {
    return Cache::rememberForever(sha1($markdown), function () use ($parse) {
        return $parse();
    });
});
```

Allowing Dangerous Tags
-----------------------

[](#allowing-dangerous-tags)

By default, GitHub sanitizes HTML tags it deems "unsafe" like ``s. However, it's common to embed video or audio into your markdown with ``s.

GitDown can intelligently preserve your tags by filling the `allowedTags` config array option in `config/gitdown.php` with the tags you want to prevent being parsed.

```
"allowedTags" => [
    'iframe',
],
```

Non-Laravel Usage
-----------------

[](#non-laravel-usage)

You can set a GitHub Personal Access Token by passing it into the `GitDown`'s constructor. `new GitDown\GitDown($token)`

```
// You can pass config options into the constructur:
$gitDown = new GitDown\GitDown(
    $token = 'foo',
    $context = 'your/repo',
    $allowedTags = []
);

$gitDown->parse($markdown);

// Pass in your own custom caching strategy.
$gitDown->parseAndCache($markdown, function ($parse) {
    return Cache::rememberForever(sha1($markdown), function () use ($parse) {
        return $parse();
    });
});
```

Markdown/Syntax CSS
-------------------

[](#markdownsyntax-css)

Styling markdown with CSS has always been a bit of a pain for me. Not to mention trying to style syntax inside code blocks. Not to worry!

GitDown ships with all the CSS you need to make your markdown look exactly like it does on GitHub. Just add this code somewhere on your HTML page, preferably near your other stylesheets in the `` section.

```

    [...]
    @gitdown

```

**Non-Laravel**

```

    [...]
