All Projects β†’ kadet1090 β†’ KeyLighter

kadet1090 / KeyLighter

Licence: MIT license
Yet another syntax highlighter for PHP

Programming Languages

PHP
23972 projects - #3 most used programming language
ruby
36898 projects - #4 most used programming language
powershell
5483 projects
c
50402 projects - #5 most used programming language
python
139335 projects - #7 most used programming language
C#
18002 projects

Projects that are alternatives of or similar to KeyLighter

KodeEditor
A simple code editor with syntax highlighting and pinch to zoom
Stars: ✭ 60 (+106.9%)
Mutual labels:  syntax-highlighting, highlighter
core
🌈 light, fast, and easy to use, dependencies free javascript syntax highlighter, with automatic language detection
Stars: ✭ 40 (+37.93%)
Mutual labels:  syntax-highlighting, highlighter
Codeview
Android Code Highlighter
Stars: ✭ 204 (+603.45%)
Mutual labels:  syntax-highlighting, highlighter
vim-log-highlighting
Syntax highlighting for generic log files in VIM
Stars: ✭ 164 (+465.52%)
Mutual labels:  syntax-highlighting
sublime-coconut
Coconut syntax highlighting for Sublime Text and VSCode.
Stars: ✭ 18 (-37.93%)
Mutual labels:  syntax-highlighting
code editor
A code editor (dart, js, html, ...) for Flutter with syntax highlighting and custom theme.
Stars: ✭ 48 (+65.52%)
Mutual labels:  syntax-highlighting
PlantUml-Language-Service
PlantUml Language Service extension for Visual Studio 2017 and 2019
Stars: ✭ 24 (-17.24%)
Mutual labels:  syntax-highlighting
highlightjs-badge
Addon component to highlightjs that lets you copy code snippets to the clipboard and displays the active syntax
Stars: ✭ 44 (+51.72%)
Mutual labels:  syntax-highlighting
lslforge
LSLForge - Eclipse plugin to assist with LSL scripting for Second Life. This repository is used for development, pull requests and bug reports.
Stars: ✭ 17 (-41.38%)
Mutual labels:  syntax-highlighting
sora-editor
A cool code editor library on Android with syntax-highlighting and auto-completion. (aka CodeEditor)
Stars: ✭ 580 (+1900%)
Mutual labels:  syntax-highlighting
vscode-LaTeX-support
LaTeX language support for Visual Studio Code
Stars: ✭ 17 (-41.38%)
Mutual labels:  syntax-highlighting
elm-syntax-highlighting
Syntax Highlighting for Elm in Sublime Text
Stars: ✭ 27 (-6.9%)
Mutual labels:  syntax-highlighting
vscode-liquid
πŸ’§Liquid language support for VS Code
Stars: ✭ 137 (+372.41%)
Mutual labels:  syntax-highlighting
vim-ember-hbs
Ember Handlebars/HTMLBars plugin for Vim with indentation support
Stars: ✭ 45 (+55.17%)
Mutual labels:  syntax-highlighting
xmlspectrum
XSLT 2.0 coded syntax highlighter for XSLT 3.0, XPath 3.0...
Stars: ✭ 46 (+58.62%)
Mutual labels:  syntax-highlighting
winprint
winprint 2.0 - Advanced source code and text file printing. The perfect tool for printing source code, web pages, reports generated by legacy systems, documentation, or any text or HTML file. It works interactively or from the command line making it great for single users or whole enterprises. Works great with Powershell.
Stars: ✭ 52 (+79.31%)
Mutual labels:  syntax-highlighting
Assembly-Syntax-Definition
This is the greatest syntax definition of All Time
Stars: ✭ 23 (-20.69%)
Mutual labels:  syntax-highlighting
robotframework-vim
Some vim scripts for use with the Robot framework.
Stars: ✭ 89 (+206.9%)
Mutual labels:  syntax-highlighting
rehype-highlight
plugin to highlight code blocks
Stars: ✭ 127 (+337.93%)
Mutual labels:  syntax-highlighting
sb-dynlex
Configurable lexer for PHP featuring a fluid API.
Stars: ✭ 27 (-6.9%)
Mutual labels:  syntax-highlighting

Logo

Packagist Scrutinizer Code Quality Travis build Code Coverage Try it

stability: stable stability: unstable

Yet another Syntax Highlighter in PHP meant to be as extensible and easy to use as it only can, but with performance in mind.

You can try it live with the most recent version on https://keylighter.kadet.net/.

Name

Name "KeyLighter" is inspired by Key Light concept in photography and cinematography.

The key light is the first and usually most important light a photographer, cinematographer, lighting cameraman, or other scene composer will use in a lighting setup. The purpose of the key light is to highlight the form and dimension of the subject.

KeyLighter is supposed to do the same thing - for code.

Installation

$ composer require kadet/keylighter

To use KeyLighter you just need PHP 7.1.3 or later, no special extensions required.

Global installation

It's possible to install KeyLighter as a global composer library

$ composer global require kadet/keylighter

Then you can use builtin simple cli highlighting app:

$ keylighter [command = highlight] [-l|--language [LANGUAGE]] [-f|--format [FORMAT]] [-d|--debug [DEBUG]] [--]  <path>...

If you want pipe into KeyLighter just specify php://stdin as path. You can use list command to see all available commands, and --help argument for detailed help. You don't have to specify highlight command explicitly.

PowerShell

You're using PowerShell on Windows? Cool! KeyLighter comes with integrated PowerShell module that makes CLI usage even better. Just import module (For example in profile), and you're ready to go.

PS> Import-Module "${env:APPDATA}\Composer\vendor\kadet\keylighter\bin\KeyLighter.psd1"

To use autocompletion features you will need PowerShell v5 (Comes with windows 10) or install TabExpansion++ Module.

Powershell Support

Why KeyLighter?

Simple to use

use Kadet\Highlighter\Language;

echo \Kadet\Highlighter\highlight($source, new Language\Php(), $formatter);
// or
echo \Kadet\Highlighter\KeyLighter::get()->highlight($source, new Language\Php(), $formatter);
// or
$keylighter = new \Kadet\Highlighter\KeyLighter([options]);
echo $keylighter->highlight($source, new Language\Php(), $formatter);

You can find all available languages here and formatters here.

It works on CLI! And more!

KeyLighter was originally designed as CLI highlighter for my own usage, but then I decided that it should be able to generate any possible output, currently supported:

Cli \Kadet\Highlighter\Formatter\CliFormatter

CLI

It can even be styled, default styles are stored in Styles\Cli\Default.php, but you can just pass additional argument into a constructor:

new \Kadet\Highlighter\Formatter\CliFormatter([
    'string'      => ['color' => 'green'],
    'keyword'     => ['color' => 'yellow'],
    ...
])

HTML \Kadet\Highlighter\Formatter\HtmlFormatter

HTML

Every token is placed inside it's own span and classes are prefixed so it can be easily styled with css and should not interfere with any of your existing classes

<span class="kl-variable">$maxOption</span>
pre > span.kl-variable { color: #F7750D; }

Your own?

It's easy to write your own formatters. Documentation coming soon.

Context sensitive

Some tokens are valid in some contexts, some are not. This library is context sensitive, and you can define when they are valid.

In this case, context mean just "inside of other token", for example lets assume that string token is defined as everything from " to the next " and keyword is defined as 'sit' substring.

↓ string:start     ↓ keyword:start
"Lorem ipsum dolor sit amtet"
         keyword:end ↑      ↑ string:end

Token tree:

Token.name           Token.pos
------------------------------
string:start         0
    keyword:start    21
    keyword:end      23
string:end           30

So as you can see keyword is inside of string, and therefore is not valid and should be deleted. You can define tokens valid only in some context, or invalid in other.

Oh, and token names cascade, it means that string.single is string, but string is necessarily not string.single.

Write your own language definitions easily

It's possible to easily extend KeyLighter with new languages, more detailed documentation coming soon.

For example XML definition looks like this:

class Xml extends GreedyLanguage
{
    private const IDENTIFIER = '(?P<namespace>[\w\.-]+:)?(?P<name>[\w\.-]+)';

    /**
     * Tokenization rules
     */
    public function setupRules()
    {
        $this->rules->addMany([
            'tag.open'  => [
                new OpenRule(new RegexMatcher('/(<[\w\.-]+)[:\/>:\s]/')),
                new CloseRule(new SubStringMatcher('>'), ['context' => ['!string', '!comment']])
            ],
            'tag.close' => new Rule(new RegexMatcher('/(<\/' . self::IDENTIFIER . '>)/')),

            'symbol.tag' => new Rule(new RegexMatcher('/<\\/?' . self::IDENTIFIER . '/', [
                'name'      => Token::NAME,
                'namespace' => '$.namespace'
            ]), ['context' => ['tag', '!string']]),

            'symbol.attribute' => new Rule(new RegexMatcher('/' . self::IDENTIFIER . '=/', [
                'name'      => Token::NAME,
                'namespace' => '$.namespace'
            ]), ['context' => ['tag', '!string']]),

            'constant.entity' => new Rule(new RegexMatcher('/(&(?:\#\d+|[a-z])+;)/si')),

            'comment' => new Rule(new CommentMatcher(null, [['<!--', '-->']])),
            'string'  => CommonFeatures::strings(['single' => '\'', 'double' => '"'], ['context' => ['tag']]),
        ]);
    }

    /** {@inheritdoc} */
    public function getIdentifier()
    {
        return 'xml';
    }

    public static function getMetadata()
    {
        return [
            'name'      => ['xml'],
            'mime'      => ['application/xml', 'text/xml'],
            'extension' => ['*.xml']
        ];
    }
}

I will try to write as many definitions as I only can, but any PRs are welcome.

Embedding languages

Many languages can be used simultaneously, css or js inside html, sql in
php and so on. KeyLighter can handle and highlight embedded languages without any problem.

Embedded languages

Fast

Even though it wasn't supposed to be fastest code highlighter in PHP it is still quite fast, more than 2x faster than GeSHi.

Testing Code Coverage

KeyLighter uses phpunit for testing:

$ ./vendor/bin/phpunit

Roadmap

There are still few things to do, you can find all on trello.

Contributing

See CONTRIBUTING.md for details.

Thanks

For Maciej, Maciej and Monika for all support, moral too.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].