Code Monkey home page Code Monkey logo

torchlight-laravel's Introduction

Laravel Torchlight Client

Tests Latest Stable Version Total Downloads License

A Torchlight syntax highlighting extension for the Laravel framework.

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-laravel

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-laravel's People

Contributors

aarondfrancis avatar bakerkretzmar avatar binotaliu avatar davidwessman avatar dissnik avatar laravel-shift avatar nuernbergera avatar philonl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

torchlight-laravel's Issues

Torchlight API token

First, thanks for this awesome API package, it really helps!

I'm using torchlight in both jigsaw & Laravel applications, and I can't figure out how to grab the API token to connect to the API.

I got this section in the docs, but I didn't understand

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

Is Torchlight is completely free for personal and open source projects phrase the API token? Or there is something I didn't understand?

Any help it will be really appreciate

Copy-paste snippet on Firefox adds newline between every line

When viewed on Firefox, if you copy a code snippet from Torchlight it adds an additional newline for every line. Copying an example on the homepage to the clipboard and then pasting results in the following:

<x-code-torchlight language='php'>

    // Any code here will be highlighted by Torchlight!

</x-code-torchlight>

While on Chrome it copies like it should:

<x-code-torchlight language='php'>
    // Any code here will be highlighted by Torchlight!
</x-code-torchlight>

It looks like Firefox copies the span.line-number as an empty line. I removed these elements from the DOM and then copying is as expected

cURL error 28: Operation timed out

From my logs:

(GuzzleHttp\\Exception\\ConnectException(code: 0): cURL error 28: Operation timed out after 5001 milliseconds
with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for 
https://api.torchlight.dev/highlight at 
/var/www/html/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php:210)

Not installing in Laravel 11

Hi I am trying to install in Laravel 11 project.

`composer require torchlight/torchlight-laravel
./composer.json has been updated
Running composer update torchlight/torchlight-laravel
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
- torchlight/torchlight-laravel[v0.1.0, ..., v0.5.10] require illuminate/support ^7.26.0|^8.0 -> found illuminate/support[v7.26.0, ..., v7.30.6, v8.0.0, ..., v8.83.27] but these were not loaded, likely because it conflicts with another require.
- torchlight/torchlight-laravel[v0.5.11, ..., v0.5.12] require illuminate/support ^7.26.0|^8.0|^9.0 -> found illuminate/support[v7.26.0, ..., v7.30.6, v8.0.0, ..., v8.83.27, v9.0.0, ..., v9.52.16] but these were not loaded, likely because it conflicts with another require.
- torchlight/torchlight-laravel v0.5.13 requires illuminate/support ^7.26.0|^8.0|^9.0|^10.0 -> found illuminate/support[v7.26.0, ..., v7.30.6, v8.0.0, ..., v8.83.27, v9.0.0, ..., v9.52.16, v10.0.0, ..., v10.48.10] but these were not loaded, likely because it conflicts with another require.
- torchlight/torchlight-laravel v0.5.14 requires illuminate/support ^8.0|^9.0|^10.0 -> found illuminate/support[v8.0.0, ..., v8.83.27, v9.0.0, ..., v9.52.16, v10.0.0, ..., v10.48.10] but these were not loaded, likely because it conflicts with another require.
- Root composer.json requires torchlight/torchlight-laravel * -> satisfiable by torchlight/torchlight-laravel[v0.1.0, ..., v0.5.14].

You can also try re-running composer require with an explicit version constraint, e.g. "composer require torchlight/torchlight-laravel:*" to figure out if any version is installable, or "composer require torchlight/torchlight-laravel:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.`

I am getting this error.

Please anyone can help me to figure it out.

Thank you. ☺️

Code block does not update

I added a code block into my blade file. and then after changing the theme or removing line numbers, it doesnt reflect the update. Does this have to do with the caching?

Thank you

Line numbers getting copied on mac

It seems that line numbers are being copied on Mac/safari. It even happens in the examples in the docs.

Is there a known workaround, or is it just not possible on Mac?

Diff with Razor language not working

Hi team, I try using Torchlight to highlight a Razor code that using Diff but it's seem not working.

image

```razor
@page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
}

<div class="text-center">
    <h1 class="display-4">Welcome</h1>
    <p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p> // [tl! --]
    <p>Hello, world! The time on the server is @DateTime.Now</p> // [tl! ++]
 </div>

I hope Torchlight team fix it help me. Thanks so much.

is_file(): open_basedir restriction in effect on shared hosting

Torchlight doesn't work on shared hosting. I'm getting the below error:

[2023-08-12 14:29:53] production.ERROR: is_file(): open_basedir restriction in effect. File(/##LARAVEL_TRIM_FIXER##[
    {
        "message": "Test message"
    }
]) is not within the allowed path(s): (/usr/www/wwws/users/xxxxxxxx:/usr/wwws/users/xxxxxxxx:/usr/www/users/xxxxxxxx:/usr/home/xxxxxxxx:/usr/local/rmagic:/usr/share/php:/usr/local/lib/php:/tmp:/usr/bin:/usr/local/bin:/usr/local/share/www:/usr/www/share/www:/usr/share/misc:/dev/urandom:/var/www/php_profiler/xhgui) {"view":{"view":"/usr/www/users/xxxxxxxx/storage/framework/views/e27a4533eb8db3852c74356c2d86f009b7ba2033.blade.php","data":{"errors":"<pre class=sf-dump id=sf-dump-1706485823 data-indent-pad=\"  \"><span class=sf-dump-note>Illuminate\\Support\\ViewErrorBag</span> {<a class=sf-dump-ref>#1682</a><samp data-depth=1 class=sf-dump-expanded>
  #<span class=sf-dump-protected title=\"Protected property\">bags</span>: []
</samp>}

If I comment out the below in Manager.php it works fine:

if (is_file($directory . $file)) {
    return file_get_contents($directory . $file);
}

Option to ignore Torchlight when there's a missing token

Is it possible to disable the exceptions when there's a missing token?

For example, we have a documentation site that people will want to contribute to.
When contributors run the site locally, if they don't add an API token, they'll run into an exception.

We can work around this by either setting the app environment to production, or make our token available to everyone, but those both feel dangerous.

Background colors do not render

Hi, This is a strange thing but the theme background colors do not render. In this example I wrapped the Torchlight component in a div styled with Tailwind, bg red. The Torchlight bg is styled but does not show. All cache has been cleared several times with no luck.
Screen Shot 2022-06-29 at 9 03 41 AM

Disable lines number

I would like to know if it is possible to disable the lines in a specific example

Feature Request: Beautify Snippets

I couldn't find any mention in the docs if there is an option for torchlight to beautify the code sent. My specific need was formatting an SQL query cleanly.

Looks like `<!-- Comments --> in PHP/HTML files do not work

Hey Aaron! I've been converting my blog from WordPress to Laravel. With that I'm also switching to Torchlight.

One thing that struck me was the following code snippet:

Schermafbeelding 2022-03-10 om 18 03 51

This is a code snippet in a PHP that is rendered as HTML. In this case, the first line is just an HTML-comment, but it isn't grey like it should be.

Is this indeed a bug or should I use a different filetype than PHP?

Thanks!

Torchlight not working with Statamic SSG

I am using / trying to use Torchlight with Statamic and used the docs to install it.
All works local in default Statamic install. But it fails when I deploy to Netlify, and also fails when I generate the the static files with SSG locally. The code blocks are not rendered but I see code blocks with __torchlight-block-[9a3f0b40-2ec4-4169-9788-22e812836e47]__ messages.

Help is appreciated. The website repo is here: https://github.com/mbootsman/marcelbootsman-statamic

πŸ’‘ Add a cache command

I've been trying to build a cache command for Torchlight but haven't been able to wrap my head around how to approach this. If you use a post-processor, everything can be cached up front, similar to view:cache. This will eliminate on-demand requests.

Do you think this is possible with the current setup?

Basic CSS Styles Not Styled Correctly

I'm not sure, if this is the right repo for this issue, but I found no docs repo available.

Steps to produce:

I was following the docs instruction for basic styling, and I noticed on each style we need to put a comma between pre tag and the code tag.

Solution

I'm sure it's a simple mistake by the creator (@aarondfrancis), and if we put a comma between the pre and the code tag, it'll be the solution.

Instead of

pre code.torchlight {
    @apply block py-4 min-w-max;
}

We need to do this

pre, code.torchlight {
    @apply block py-4 min-w-max;
}

Extra docs for Statamic static site generation

There were issues I ran into and had to resolve when using Statamic with their Static Site Generation plugin. This isn't an issue with Torchlight exactly but with how SSG is performed in the plugin.

When generating the pages via php please ssg:generate, views are generated with the raw Torchlight placeholders:

Screen Shot 2022-01-06 at 11 19 52 AM

After creating a Statamic custom page generator and forcing the page to be rendered in full by manually calling the RenderTorchlight middleware, we get the full HTML code snippets:

Screen Shot 2022-01-06 at 11 20 00 AM

Results can be seen here: https://stevebauman.ca/create-api-responses-with-eloquent-factories/

Here's the code for forcing code generation:

// app/Providers/AppServiceProvider.php

use App\CustomGenerator;
use Statamic\StaticSite\Tasks;
use Statamic\Facades\Markdown;
use Statamic\StaticSite\Generator;
use Torchlight\Commonmark\V2\TorchlightExtension;

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    Markdown::addExtension(function () {
        return new TorchlightExtension;
    });

    $this->app->singleton(Generator::class, function ($app) {
        return new CustomGenerator($app, $app['files'], $app['router'], $app[Tasks::class]);
    });
}
// app/CustomGenerator.php

namespace App;

use Statamic\StaticSite\Generator;

class CustomGenerator extends Generator
{
    protected function createPage($content)
    {
        return new CustomPage($this->files, $this->config, $content);
    }
}
// app/CustomPage.php

namespace App;

use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\RedirectResponse;
use Statamic\StaticSite\GeneratedPage;
use Statamic\StaticSite\Page;
use Torchlight\Middleware\RenderTorchlight;

class CustomPage extends Page
{
    protected function write($request)
    {
        $response = (new RenderTorchlight())->handle($request, function ($request) {
            try {
                $response = $this->content->toResponse($request);
            } catch (HttpResponseException $e) {
                $response = $e->getResponse();
                throw_unless($response instanceof RedirectResponse, $e);
            }
            
            // This has to be set/overridden, as additional pages being generated
            // by Statamic SSG will have a `null` content type and Torchlight
            // relies on this to return the full response instead of Blade.
            $response->headers->set('content-type', 'html');

            return $response;
        });

        $html = $response->getContent();

        if (! $this->files->exists($this->directory())) {
            $this->files->makeDirectory($this->directory(), 0755, true);
        }

        $this->files->put($this->path(), $html);

        return new GeneratedPage($this, $response);
    }
}

I hope this helps someone who is looking to do the same thing! πŸ˜„

Is there any prebuild style available?

I'd like to have the same effect as the documentation

I see that there is not css file or something, only style in generated code from the api.

Does someone have make a css style to have this kind of render ?:
image

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.