定制 johannschopplich/kirby-highlighter 二次开发

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

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

johannschopplich/kirby-highlighter

最新稳定版本:3.2.0

Composer 安装命令:

composer require johannschopplich/kirby-highlighter

包简介

Server-side syntax highlighting for Kirby CMS

README 文档

README

Note

This package is deprecated in favor of Kirby Code Highlighter – powered by Phiki, that uses TextMate grammars and VS Code themes to generate syntax-highlighted code within Kirby's code block and KirbyText.

Kirby Highlighter

Server-side code highlighting available as custom block and for KirbyText.

Built upon highlight.php which itself is a port of highlight.js.

Key Features

  • 🏗 Works with Kirby's code block
  • 🏳️‍🌈 Supports 189 languages
  • 💫 94 styles available
  • ⛳️ Automatic language detection for KirbyText

Requirements

  • Kirby 3.8+

Installation

Composer

composer require johannschopplich/kirby-highlighter

Download

Download and copy this repository to /site/plugins/kirby-highlighter.

Usage

With Kirby Blocks Field

This plugin overwrites Kirby's internal code block. Thus, you won't have to change a thing.

Use the code block just like before, the output will be highlighted automatically:

fields:
    example:
        label: Paste code here
        type: blocks
        fieldsets:
            - code

Within KirbyText

Create a code block in your KirbyText field and optionally set the code language:

```css
.currentColor {
  color: currentColor;
}
```

Or use the new code-KirbyTag from this plugin with a base64 encoded code string:

(code: LmN1cnJlbnRDb2xvciB7CiAgY29sb3I6IGN1cnJlbnRDb2xvcjsKfQ== lang: css)

Which outputs:

<pre class="hljs"><code><span class="hljs-selector-class">.currentColor</span> {
    <span class="hljs-attribute">color</span>: currentColor;
}</code></pre>

The syntax highlighting functionality can be changed. You can choose between two highlighting modes:

  1. Explicit mode (default)
  2. Automatic language detection mode (opt-in)

Explicit Mode

In explicit mode, you have to define which language the code block is. Otherwise highlighting will be skipped.

Automatic Language Detection

Alternatively you can use the automatic detection mode, which highlights your code with the language the library thinks is best. It is highly recommended you explicitly choose the language or limit the number of languages to automatically detect from. This reduces the number of inaccuracies and skips this extremely inefficient selection process.

To enable automatic language detection, set:

  • johannschopplich.highlighter.autodetect to true
  • johannschopplich.highlighter.languages to an array of names from which languages should be chosen

Options

Option  Default Description
johannschopplich.highlighter.class hljs Style class for Highlight to be added to the pre element.
johannschopplich.highlighter.autodetect false Indicates if the library should define which language thinks is best. Only applies when no language was set on the KirbyText code block.
johannschopplich.highlighter.languages [] Array of language names to be auto-detected. If empty, every language will be auto-detectable.
johannschopplich.highlighter.line-numbering false Indicates if the library should split up the highlighted code on each new line and wrap it in a <span> element.
johannschopplich.highlighter.line-numbering-class hljs-code-line CSS class applied to highlighted code lines, respectively <span> elements.

Styling in the Frontend

Since this plugin handles highlighting code only and thus just wraps span's around code, you have to link styles in your frontend yourself. I recommend choosing one of the available themes directly from the highlight.js project: highlight.js/src/styles/

The CSS files over at the repository are maintained and new ones arrive from time to time, therefore it would be redundant to include a copy in this repository.

One of my favorite themes is Night Owl by Sarah Drasner. For example you could download the CSS file and save it in your Kirby project under assets/css/hljs-night-owl.css. Now you just have to include it in your template <?= css('assets/css/hljs-night-owl.css') ?>. Alternatively, use a CSS bundler of your choice.

Line Numbering

If you choose to activate the line numbering option, you will need to include additional CSS style to display line numbering.

A basic example using pseudo-elements:

pre.hljs .hljs-code-line {
    counter-increment: line;
}

pre.hljs .hljs-code-line::before {
    content: counter(line);
    display: inline-block;
    margin-right: 1em;
    opacity: 0.5;
}

Credits

  • Geert Bergman and contributors for the awesome highlight.php port.
  • Martin Folkers for his Kirby Highlight plugin which built the base of this package.

License

MIT License © 2020-PRESENT Johann Schopplich

johannschopplich/kirby-highlighter 适用场景与选型建议

johannschopplich/kirby-highlighter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.39k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2020 年 07 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「highlight」 「highlighter」 「kirby」 「hljs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 johannschopplich/kirby-highlighter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 johannschopplich/kirby-highlighter 我们能提供哪些服务?
定制开发 / 二次开发

基于 johannschopplich/kirby-highlighter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.39k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 21
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-19