Git Product home page Git Product logo

torchlight-commonmark-php's Introduction

Laravel Torchlight Extension for Commonmark

Tests Latest Stable Version Total Downloads License

๐Ÿ“š The full docs can be found at torchlight.dev/docs/clients/commonmark-php.

A Torchlight syntax highlighting extension for the PHP League's Commonmark Markdown Parser in a Laravel application.

Supports both CommonMark version 1 and version 2.

Torchlight is a VS Code-compatible syntax highlighter that requires no JavaScript, supports every language, every VS Code theme, line highlighting, git diffing, and more.

Installation

To install, require the package from composer:

composer require torchlight/torchlight-commonmark

This will install the Laravel Client as well.

Adding the Extension

If you are using Graham Campbell's Laravel Markdown package, you can add the extension in your markdown.php file, under the "extensions" key.

'extensions' => [
    // Torchlight syntax highlighting
    TorchlightExtension::class,
],

If you aren't using the Laravel Markdown package, you can add the extension manually:

// CommonMark V1
$environment = Environment::createCommonMarkEnvironment();
$environment->addExtension(new TorchlightExtension);

// CommonMark V2
$environment = new Environment();
$environment->addExtension(new CommonMarkCoreExtension);
$environment->addExtension(new TorchlightExtension);

That's all you need to do! All of your code fences will now be highlighted via Torchlight.

Configuration

Once the package is downloaded, you can run the following command to publish your configuration file:

php artisan torchlight:install

Once run, you should see a new file torchlight.php in you config folder, with contents that look like this:

<?php
return [
    // The Torchlight client caches highlighted code blocks. Here
    // you can define which cache driver you'd like to use.
    'cache' => env('TORCHLIGHT_CACHE_DRIVER'),

    // Which theme you want to use. You can find all of the themes at
    // https://torchlight.dev/themes, or you can provide your own.
    'theme' => env('TORCHLIGHT_THEME', 'material-theme-palenight'),

    // Your API token from torchlight.dev.
    'token' => env('TORCHLIGHT_TOKEN'),

    // If you want to register the blade directives, set this to true.
    'blade_components' => true,

    // The Host of the API.
    'host' => env('TORCHLIGHT_HOST', 'https://api.torchlight.dev'),
];

Cache

Set the cache driver that Torchlight will use.

Theme

You can change the theme of all your code blocks by adjusting the theme key in your configuration.

Token

This is your API token from torchlight.dev. (Torchlight is completely free for personal and open source projects.)

Blade Components

By default Torchlight works by using a custom Laravel component. If you'd like to disable the registration of the component for whatever reason, you can turn this to false.

Host

You can change the host where your API requests are sent. Not sure why you'd ever want to do that, but you can!

torchlight-commonmark-php's People

Contributors

aarondfrancis avatar duncanmcclean avatar midnite81 avatar stylecibot avatar

Forkers

fludem

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.