All Projects → johannschopplich → kirby-highlighter

johannschopplich / kirby-highlighter

Licence: MIT license
🌐 Server-side syntax highlighting for the Kirby code block & KirbyText

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to kirby-highlighter

kirby-highlight
Themeable server-side syntax highlighting for Kirby
Stars: ✭ 14 (-22.22%)
Mutual labels:  kirby, highlighting, kirby-plugin
Kirby Uniform
A versatile Kirby plugin to handle web form actions.
Stars: ✭ 214 (+1088.89%)
Mutual labels:  kirby, kirby-plugin
Kirby Imageset
A flexible, responsive image component for Kirby 2, featuring lazy-loading, fancy placeholders and much more.
Stars: ✭ 122 (+577.78%)
Mutual labels:  kirby, kirby-plugin
Kirby Focus
Better image cropping for Kirby CMS
Stars: ✭ 170 (+844.44%)
Mutual labels:  kirby, kirby-plugin
Kirby Typography
Typographic enhancements for your Kirby-driven website.
Stars: ✭ 80 (+344.44%)
Mutual labels:  kirby, kirby-plugin
search-for-kirby
Kirby 3 plugin for adding a search index (sqlite or Algolia).
Stars: ✭ 42 (+133.33%)
Mutual labels:  kirby, kirby-plugin
Embed
Media embed plugin for Kirby 2 CMS
Stars: ✭ 73 (+305.56%)
Mutual labels:  kirby, kirby-plugin
retour-for-kirby
Kirby 3 plugin to manage redirects and track 404s right from the Panel
Stars: ✭ 96 (+433.33%)
Mutual labels:  kirby, kirby-plugin
Kirby Sri
Subresource integrity hashing & cache-busting static assets for Kirby
Stars: ✭ 9 (-50%)
Mutual labels:  kirby, kirby-plugin
Select A Structure
A select field for Kirby populated by a structure field.
Stars: ✭ 44 (+144.44%)
Mutual labels:  kirby, kirby-plugin
Panel Bar
panelBar for Kirby 2 CMS
Stars: ✭ 70 (+288.89%)
Mutual labels:  kirby, kirby-plugin
kirby-blade
Enable Laravel Blade Template Engine for Kirby 3
Stars: ✭ 20 (+11.11%)
Mutual labels:  kirby, kirby-plugin
Cartkit
Cartkit - The [quick] starter kit!
Stars: ✭ 39 (+116.67%)
Mutual labels:  kirby, kirby-plugin
Kirby Visual Markdown
Visual Markdown Editor for Kirby CMS 2
Stars: ✭ 171 (+850%)
Mutual labels:  kirby, kirby-plugin
kirby-architect
📐 Easily reference Blueprint data from anywhere in your Kirby application.
Stars: ✭ 38 (+111.11%)
Mutual labels:  kirby, kirby-plugin
Kirby Calendar Plugin
A plugin for the Kirby CMS to easily implement an event calendar.
Stars: ✭ 76 (+322.22%)
Mutual labels:  kirby, kirby-plugin
Kirby Autogit
⬢ Saves every change made via Kirby Panel to a Git repository
Stars: ✭ 147 (+716.67%)
Mutual labels:  kirby, kirby-plugin
kirbyup
🆙 Zero-config bundler for Kirby Panel plugins
Stars: ✭ 33 (+83.33%)
Mutual labels:  kirby, kirby-plugin
queue-for-kirby
Basic queue for Kirby 2, using Cron and Kirby's flat file system
Stars: ✭ 17 (-5.56%)
Mutual labels:  kirby, kirby-plugin
kirby-copy-files
Clone page dashboard widget for Kirby panel
Stars: ✭ 12 (-33.33%)
Mutual labels:  kirby, kirby-plugin

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

Download

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

Git Submodule

git submodule add https://github.com/johannschopplich/kirby-highlighter.git site/plugins/kirby-highlighter

Composer

composer require johannschopplich/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;
}
```

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-2023 Johann Schopplich

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].