Download the PHP package mensbeam/lit without Composer

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

Lit

Lit is a multilanguage syntax highlighter written in PHP. It takes code as input and returns an HTML pre element containing the code highlighted using span elements with classes based upon tokens in the code. It is loosely based upon Atom's Highlights which is used in the Atom text editor to syntax highlight code. Atom's Highlights is in turn based upon TextMate's syntax highlighting using its concepts of scope selectors and common keywords for components of programming languages. Lit is not a port of Atom's Highlights but instead an independent implementation of what I can understand of TextMate's grammar syntax, parsing, and tokenization by analyzing other implementations. It aims to at least have feature parity or better with Atom's Highlights.

Warning Before Using

This library is experimental. The code is not tested at all, and writing tests for it will be an incredible undertaking because there's no specification whatsoever to test against. It would require creating a specification as well which is beyond the scope of a project that exists just to scratch an itch. Atom's Highlights is also barely tested itself for the same reason. There's numerous PHP libraries out there without a test suite; not having one is not up to our usual standards, though. So, that's why this warning exists.

Documentation

MensBeam\Lit\Grammar::__construct

Creates a new MensBeam\Lit\Grammar object.

Parameters

In normal usage of the library the parameters won't be used (see MensBeam\Lit\Grammar::loadJSON and examples below for more information), but they are listed below for completeness' sake.

scopeName - The scope name of the grammar
patterns - The list of patterns in the grammar
name - A human-readable name for the grammar
injections - The list of injections in the grammar
repository - The list of repository items in the grammar

MensBeam\Lit\Grammar::loadJSON

Imports an Atom JSON grammar into the MensBeam\Lit\Grammar object.

Parameters

filename - The JSON file to be imported

MensBeam\Lit\GrammarRegistry::clear

Clears all grammars from the registry

MensBeam\Lit\GrammarRegistry::get

Retrieves a grammar from the registry

Parameters

scopeName - The scope name (eg: text.html.php) of the grammar that is being requested

Return Values

Returns a MensBeam\Lit\Grammar object on success and false on failure.

MensBeam\Lit\GrammarRegistry::set

Retrieves a grammar from the registry

Parameters

scopeName - The scope name (eg: text.html.php) of the grammar that is being set
grammar - The grammar to be put into the registry

Return Values

Returns true on success and false on failure.

MensBeam\Lit\Highlight::toElement

Highlights incoming string data and outputs a PHP DOMElement.

Parameters

data - The input data string
scopeName - The scope name (eg: text.html.php) of the grammar that's needed to highlight the input data
document - An existing DOMDocument to use as the owner document of the returned DOMElement; if omitted one will be created instead
encoding - The encoding of the input data string; only used if a document wasn't provided in the previous parameter, otherwise it uses the encoding of the existing DOMDocument; defaults to HTML standard default windows-1252

Return Values

Returns a pre DOMElement.

MensBeam\Lit\Highlight::toString

Highlights incoming string data and outputs a string containing serialized HTML.

Parameters

data - The input data string
scopeName - The scope name (eg: text.html.php) of the grammar that's needed to highlight the input data
encoding - The encoding of the input data string; defaults to HTML standard default windows-1252

Return Values

Returns a string.

Examples

Here's an example of highlighting PHP code:

This will produce:

An already existing DOMDocument may be used as the owner document of the returned pre element:

Other DOM libraries which inherit from and/or encapsulate PHP's DOM such as MensBeam\HTML-DOM may also be used:

Of course Lit can simply output a string, too:

Lit has quite a long list of out-of-the-bag supported languages, but sometimes other languages need to be highlighted:

Supported Languages & Formats


All versions of lit with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-dom Version *
ext-json Version *
mensbeam/framework Version ^1.0
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 mensbeam/lit contains the following files

Loading the files please wait ....