Download the PHP package ryangjchandler/phiki without Composer

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

Phiki is a syntax highlighter written in PHP. It uses TextMate grammar files and Visual Studio Code themes to generate syntax highlighted code for the web and terminal.

Installation

Install Phiki via Composer:

Getting Started

The fastest way to get started is with the codeToHtml() method.

This method takes in the code you want to highlight, the target language, as well as the theme you want to use. It then returns the generated HTML as a string.

[!NOTE] All of Phiki's styling is applied using inline style attributes, so there's no need to add any CSS to your project.

Supported Languages

Phiki ships with 200+ grammars and 50+ themes. To provide a clean developer experience, you can find all supported grammars and themes when using the Phiki\Grammar\Grammar and Phiki\Theme\Theme enums.

These files are auto-generated when pulling in grammar and theme files from remote repositories so are always up-to-date.

CommonMark Integration

Phiki provides a convenient extension for the excellent league/commonmark package so that you can start using it on your blog or documentation site with very little effort.

All you need to do is register the extension through a CommonMark Environment object.

html

Hello, world!

Laravel

If you're using Laravel's Str::markdown() or str()->markdown() methods, you can use the same CommonMark extension by passing it through to the method.

Using custom languages and themes

To use a language or theme that Phiki doesn't support, you need to register it with a GrammarRepository or ThemeRepository.

This can be done by building a custom Environment object and telling Phiki to use this instead of the default one.

Terminal Output

Phiki has support for generating output designed for use in the terminal. This is available through the codeToTerminal() method which accepts the same parameters as the codeToHtml() method.

Line numbers

Each line has its own <span> element with a data-line attribute, so you can use CSS to display line numbers in the generated HTML. The benefit to this approach is that the text isn't selectable so you code snippets can be highlighted the same as before.

These styles are of course just a guide. You can change the colors and sizing to your own taste.

Known Limitations & Implementation Notes

The implementation of this package is inspired by existing art, namely vscode-textmate. The main reason that implementing a TextMate-based syntax highlighter in PHP is a complex task is down to the fact that vscode-textmate (and the TextMate editor) uses the Oniguruma engine for handling regular expressions.

PHP uses the PCRE2 engine which doesn't have support for all of Oniguruma's features. To reduce the risk of broken RegExs, Phiki performs a series of transformations with solid success rates:

One of the biggest differences between PCRE2 and Oniguruma is that Oniguruma has support for "variable-length lookbehinds". Variable-length lookbehinds, both positive and negative, are normally created when a quantifier such as + or * is used inside of the lookbehind.

PCRE2 does not support these types of lookbehinds and they're essentially impossible to translate into PCRE2-compatible equivalents. In these cases, Phiki also performs a series of manual "patches" on grammar files to get RegExs as close as possible to the intended output.

These patches are not perfect – there is still a chance of running into errors in your application when highlighting code! If you do encounter an error with a message like the one below, please check the Issues page or create a new issue with information about the grammar / language you're highlighting and a reproduction case.

Credits


All versions of phiki with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
league/commonmark Version ^2.5.3
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 ryangjchandler/phiki contains the following files

Loading the files please wait ....