Download the PHP package ramsey/twig-codeblock without Composer

On this page you can find all versions of the php package ramsey/twig-codeblock. 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-codeblock

ramsey/twig-codeblock

🌿 Syntax highlighting for Twig with the {% codeblock %} tag.

Source Code Download Package PHP Programming Language Read License Build Status Codecov Code Coverage

About

Add code snippets with syntax highlighting and more to any Twig template with ramsey/twig-codeblock, a port of the {% codeblock %} Liquid tag for Octopress/Jekyll.

ramsey/twig-codeblock includes an adapter for using Pygments, the Python syntax highlighter, with ramsey/pygments, but it may use any syntax highlighter. To use another syntax highlighter, implement HighlighterInterface (see below for an example).

This project adheres to a code of conduct. By participating in this project and its community, you are expected to uphold this code.

Installation

Install this package as a dependency using Composer.

Usage

Attributes

A number of attributes are available to {% codeblock %}:

Attribute Example Description
lang lang:"php" Tells the syntax highlighter the programming language being highlighted. Pass "plain" to disable highlighting.
title title:"Figure 2." Add a title to your code block.
link link:"https://example.com" Add a link to your code block title.
link_text link_text:"Download Code" Text to use for the link. Defaults to "link".
linenos linenos:false Use false to disable line numbering. Defaults to true.
start start:42 Start the line numbering in your code block at this value.
mark mark:4-6,12 Mark specific lines of code. This example marks lines 4, 5, 6, and 12.
class class:"myclass foo" Add CSS class names to the code <figure> element.
format format:"html" The output format for the syntax highlighter. Defaults to "html."

[!TIP] Order of attributes does not matter.

[!WARNING] Not all highlighters will support all attributes. However, the Pygments highlighter does support each of these attributes.

Example

Configuration

To use ramsey/twig-codeblock, create a HighlighterReference that defines the highlighter you want to use. If using PygmentsHighlighter, by default, it will look for pygmentize in your PATH.

If pygmentize is not in the PATH, you may pass its location to the highlighter reference:

[!NOTE] We use a HighlighterReference instead of an actual instance of HighlighterInterface because these values will be compiled into the Twig templates and cached for later execution.

Pygments

This library provides PygmentsHighlighter, which depends on ramsey/pygments, but ramsey/pygments is not a dependency, since you may use other highlighters that implement Ramsey\Twig\CodeBlock\Highlighter\HighlighterInterface.

To use this library with ramsey/pygments, you must also require ramsey/pygments as a dependency:

Additionally, you will need to install Python and Pygments and ensure the pygmentize CLI tool is available on your system. See the Configuration section for help configuring Codeblock if pygmentize is not in your PATH.

Styles

A syntax highlighter, such as Pygments, requires a stylesheet for the markup it generates. Pygments provides some stylesheets for you, which you may list from the command line:

To output and save one of these styles for use in your application, use something like:

Additionally, there are many custom Pygments styles found on the web, or you may create your own.

Languages

If using Pygments, here are just a few of the languages (i.e., lexers) it supports:

To see more, type the following from the command line:

Using your own highlighter

If you have your own highlighter class that implements Ramsey\Twig\CodeBlock\Highlighter\HighlighterInterface, you may create a HighlighterReference using it. The array of values passed as the second argument will be passed to your class's constructor upon instantiation.

The arguments must be scalar values or arrays of scalar values, or they may be expressions that evaluate to scalar values or arrays of scalar values. Null values are also allowed. This restriction is because of the way these values are compiled into the Twig templates.

Contributing

Contributions are welcome! To contribute, please familiarize yourself with CONTRIBUTING.md.

Coordinated Disclosure

Keeping user information safe and secure is a top priority, and we welcome the contribution of external security researchers. If you believe you've found a security issue in software that is maintained in this repository, please read SECURITY.md for instructions on submitting a vulnerability report.

Copyright and License

The ramsey/twig-codeblock library is copyright © Ben Ramsey and licensed for use under the MIT License (MIT). Please see LICENSE for more information.


All versions of twig-codeblock with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
twig/twig Version ^3.11.2
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 ramsey/twig-codeblock contains the following files

Loading the files please wait ....