定制 dominus77/yii2-highlight-plugin 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dominus77/yii2-highlight-plugin

最新稳定版本:v1.1.2

Composer 安装命令:

composer require dominus77/yii2-highlight-plugin

包简介

Yii2 Syntax highlighting with support for line numbering for the Web.

README 文档

README

Latest Stable Version License Build Status codecov Scrutinizer Code Quality Total Downloads PayPal donate button SensioLabsInsight

Yii2 Syntax highlighting with support for line numbering for the Web.

176 languages and 79 styles

The plugin is based on highlight.js, added support for line numbering with the plugin highlightjs-line-numbers.js

Auto language definition

<pre><code>...</code></pre>

Explicit language specification

<pre><code class="php">...</code></pre>
<pre><code class="css">...</code></pre>
<pre><code class="json">...</code></pre>
...

Add class hljs, render full block code

<pre><code class="php hljs">...</code></pre>
<pre><code class="css hljs">...</code></pre>
<pre><code class="json hljs">...</code></pre>
...

Watch demo

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require dominus77/yii2-highlight-plugin "*"

or add

"dominus77/yii2-highlight-plugin": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by View:

<?php
/** $this \yii\web\View */
\dominus77\highlight\Plugin::register($this);

Configure plugin

Theme

See the following link for supported topics Styles

<?php
\dominus77\highlight\Plugin::$options = [
    'theme' => 'paraiso-dark',// Styles       
];
/** $this \yii\web\View */
\dominus77\highlight\Plugin::register($this);

Line Numbers

By default, line numbers are disabled

<?php
\dominus77\highlight\Plugin::$options = [
    //...
    'lineNumbers' => true,    // Show line numbers
    'singleLine' => true,     // Show number if one line    
];
/** $this \yii\web\View */
\dominus77\highlight\Plugin::register($this);

Custom init

<?php
\dominus77\highlight\Plugin::$options = [
    //...
    // Custom init Highlight
    'highlightInit' => new \yii\web\JsExpression("
        $('pre code').each(function(i, block) {
            hljs.highlightBlock(block);
        });
    "),
    // Custom init Highlight Line Numbers
    'lineNumbersInit' => new \yii\web\JsExpression("
        $('code.hljs').each(function(i, block) {
            hljs.lineNumbersBlock(block);
        });
    "),
];
/** $this \yii\web\View */
\dominus77\highlight\Plugin::register($this);

Testing

$ phpunit

More Information

Please, check the highlight.js and highlightjs-line-numbers.js

License

The MIT License (MIT). Please see License File for more information.

Sensio Labs

SensioLabsInsight

统计信息

  • 总下载量: 913
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3
  • 更新时间: 2017-10-04