Download the PHP package brotkrueml/twig-codehighlight without Composer

On this page you can find all versions of the php package brotkrueml/twig-codehighlight. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package twig-codehighlight

Twig extension for code highlighting

CI Status

This package provides a Twig extension for server-side code highlighting. Under the hood, the scrivo/highlight.php package is used which does the hard work. You can use every theme provided for highlight.js.

An addition to the highlighting of code this Twig extension provides additional (opinionated) features:

This package is in beta phase! You can use it already, but API might change.

Usage

Add the extension to the Twig environment:

Use it in Twig templates:

If the language is not available, a raw code block is displayed.

It is also possible to inject a logger that implements \Psr\Log\LoggerInterface to display warnings when a given language is not available, either via dependency injection or manually:

You can also use named arguments, the example above can be also written like:

This will render something like this:

Language aliases

When you have already an existing application with languages named alternatively than highlight.php provides them, you can assign an array of language aliases when instantiating the extension class:

In this example, we introduce text as an alias for plaintext and sh for shell.

Additional languages

Sometimes you have the need to add languages which are not shipped by the scrivo/highlight.php package. You can add one or more custom languages:

The array consists of the following values:

Line numbers

By default, no line numbers are displayed. You can switch them one by setting the second argument:

Use it in Twig templates:

Line numbers start with 1, but can also give a custom start number with another argument:

This adds a <span data-line-number="x">...</span> to each line, where x is the increasing line number.

You can then use a CSS rule to display the line number, for example:

Emphasize lines

You can emphasize lines which highlights one or more lines in a code snippet.

Use it in Twig templates:

This example emphasizes the lines 1,2,3 and 5.

This adds a <span data-emphasize-line>...</span> to each line which should be emphasized.

You can then use a custom CSS rule to highlight the line, for example:

Classes

There are two ways to set or more classes to the <pre> tag:

  1. To set the classes in an application use the classes constructor argument when instantiating the Twig extension:

    Which results in the following HTML code:

  2. You can add one or more additional classes to the <pre> tag for a special code block:

    Which results in the following HTML code:

Using both variants together results in the following HTML code:

List of available languages

Sometimes it can be useful to provide a list of available languages. The function codehighlight_languages() is available to output such a list:


All versions of twig-codehighlight with dependencies

PHP Build Version
Package Version
Requires php Version >= 8.1
scrivo/highlight.php Version ^9.18
twig/twig Version ^3.7
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package brotkrueml/twig-codehighlight contains the following files

Loading the files please wait ....