Syntax Highlighter supporting multiple languages, themes, fonts, highlighting from a URL, local file or post text.

Overview

Crayon Syntax Highlighter

Supports multiple languages, themes, fonts, highlighting from a URL, local file or post text.

snapshot

Written in PHP and jQuery. Crayon is a Wordpress plugin, but can be used in any PHP environment.

Download

Tag Editor

The Tag Editor makes adding code, changing settings and all that much easier with a simple dialog. I'd recommend it over the manual approach, since you can fine-tune the Crayon after the editor generates it :)

Pre-formatted Tags

You can also use <pre class="attributes" title="something">...</pre> so that:

  • Disabling Crayon still presents the code as pre-formatted text and is readable
  • Enforces proper encoding of entities (< in HTML view and not <)
  • The code snippets are reusable with other syntax highlighters

The Tag Editor generates tags like these. Attributes names are separated from values by either : (default) or _. E.g. <pre class="lang:php theme:twilight mark:1,2-4" title="something">...</pre> You can optionally provide the following attributes:

Attributes

Name Description Example
lang Specify a Language ID, these are the folders in the langs directory and appears in the list of Languages in Settings. lang="java"
url Load a file from the web or a local path. You give a relative local path instead of absolute (see Files). For languages with defined extensions (see Languages in Settings) you don't even need to provide the lang attribute, as this will be detected if your file ends with it, as in the example. url="http://example.com/code.java" or url="java/code.java"
title Give a title for your code snippet. Appears in the toolbar. title="Sample"
mark Mark some lines as important so they appear highlighted. You can specify single numbers, comma separted, a range, or a combination. mark="5-10,12"
range Specify the range of lines from the input code to use in the output. You can specify a single number or a single range. range="3-5", range="3"

Mixed Highlighting

You can even mix code together like on a real HTML page, by having <script>, <style> and <?php...?> tags all in a single Crayon and setting the language to HTML.

Languages

Language information is found here in the Wordpress Admin: Settings > Crayon > Languages > Show Languages You can customise and create new languages and define how to capture each element (keywords, comments, strings, etc.) with regular expressions. Languages are structured langs/lang-name/lang-name.txt. Take a look at langs/default/default.txt and check out the neat regex of the default/generic language. See the readme in langs/readme.md for more information about the language file syntax.

You can add custom languages in wp-content/uploads/crayon-syntax-highlighter/languages with the same format as those in the plugin directory and they will remain after plugin updates.

Themes

Crayon comes with built-in Themes to style your code. See a sample of the current set of themes. Themes are structured themes/theme-name/theme-name.css. If you know CSS, take a look at themes/default/default.css to get an idea of how they work and how you can change/create them. The specification for CSS classes is here.

You can add custom themes in wp-content/uploads/crayon-syntax-highlighter/themes with the same format as those in the plugin directory and they will remain after plugin updates. This is where user themes are stored when you customise stock themes in the Theme Editor.

Comments

You can enable support for Crayon comments by adding TinyMCE to the comment box. Add this code at the end of your theme's functions.php file. This requires at least version 3.3 of Wordpress.

add_filter('comment_form_defaults', 'tinymce_comment_enable');
function tinymce_comment_enable ( $args ) {
    ob_start();
    wp_editor('', 'comment', array('tinymce'));
    $args['comment_field'] = ob_get_clean();
    return $args;
}

Then enable these settings in Wordpress Admin > Settings > Crayon:

  • "Display the Tag Editor in any TinyMCE instances on the frontend (e.g. bbPress)"
  • "Allow Crayons inside comments"

Internationalization

Crayon comes translated in several languages already, and if yours is included it will translate Crayon given you've followed instructions about how to show Wordpress in Your Language. If Crayon doesn't support your language or you'd like to help improve it:

  • Download POEdit. Add .. to the source paths under catalog preferences, and crayon__, crayon_n and crayon_e under source keywords.
  • Update and start making translations.
  • Send the .po file to me at [email protected] and give me your name and a URL to your blog for credit. Alternatively, fork this repo and make a push request :)

Fonts

You can define fonts and font-sizes within Themes, but you can also override the theme's font with those inside fonts/ and also provide @font-face fonts just like in themes - it's just CSS after all.

You can add custom fonts in wp-content/uploads/crayon-syntax-highlighter/fonts with the same format as those in the plugin directory and they will remain after plugin updates.

Disable Highlighting

You can temporarily disable highlighting for a piece of code using the highlight="false" attribute. You can also prevent Crayon from touching any kind of tag by using the crayon="false" attribute. If using pre tags, put crayon:false in the class.

Minification

Crayon's CSS and JavaScript resources is already minified (see css and js).

Settings

Crayon is versatile so you can override global settings for individual Crayons with attributes. The Tag Editor lets you do all this using a simple dialog!

Setting Allowed Value Description
theme string ID of the theme to use
font string ID of the font to use
font-size number > 0 Custom font size in pixels
min-height/max-height number > 0 followed by px/% Minimum/maximum height in units
height number > 0 followed by px/% Height in units
min-width/max-width number > 0 followed by px/% Minimum/maximum width in units
width number > 0 followed by px/% Width in units
toolbar true/false/"always" Show or hide the toolbar. "always" shows always (without mouseover).
top-margin number >= 0 Top margin in pixels
bottom-margin number >= 0 Bottom margin in pixels
left-margin number >= 0 Left margin in pixels
right-margin number >= 0 Right margin in pixels
h-align "none/left/right/center" Horizontal alignment
float-enable true/false Allow floating elements to surround Crayon
toolbar-overlay true/false Overlay the toolbar on code rather than push it down when possible
toolbar-hide true/false Toggle the toolbar on single click when it is overlayed
toolbar-delay true/false Delay hiding the toolbar on MouseOut
show-title true/false Display the title when provided
show-lang "found/always/never" When to display the language.
striped true/false Display striped code lines
marking true/false Enable line marking for important lines
nums true/false Display line numbers by default
nums-toggle true/false Enable line number toggling
plain true/false Enable plain code. Disabling will also disable plain toggling and copy/paste which use the plain code.
crayon false Prevent from turning the tag into a Crayon.
highlight true/false Prevent from highlighting the code, treats it as plain text instead.
plain-toggle true/false Enable plain code toggling
show-plain-default true/false Show the plain code by default instead of the highlighted code
copy true/false Enable code copy/paste
popup true/false Enable opening code in a window
scroll true/false Show scrollbar on mouseover
tab-size number >= 0 Tab size
trim-whitespace true/false Trim the whitespace around the code
mixed true/false Enable mixed highlighting (multiple languages in code)
show_mixed true/false Show the mixed highlighting plus sign
start-line number >= 0 When to start line numbers from
fallback-lang string ID of the language to use when none is detected
local-path string Local path to load file from
touchscreen true/false Disable mouse gestures for touchscreen devices (eg. MouseOver)
disable-anim true/false Disable animations
runtime true/false Disable runtime stats
error-log true/false Log errors for individual Crayons
error-log-sys true/false Log system-wide errors
error-msg-show true/false Display custom message for errors
error-msg string The error message to show for errors
mixed true/false Allow mixed languages using delimiters and tags

Legacy Tags

Using the legacy tag [crayon attributes] some code [/crayon] is possible but I highly recommend using <pre> tags instead. You can also convert legacy tags automatically in the Wordpress settings screen.

Mini Tags

Using Mini Tags like [php]some code[/php] is supported but also deprecated in favour of <pre> tags.

Licence

Crayon is released under the GPLv3 licence. See license.txt.

Comments
  • error with caption image

    error with caption image

    Wordpress 3.9.1 one plugin activated: Crayon Syntax Highlighter

    situation:

    • create new article
    • add an image using the button "add media" (include a caption text too)
    • save article
    • close article
    • open article to edit... notice the caption text of the image is next to the image now. See screenshot below.

    screen shot 2014-06-02 at 14 32 06

    When I disable the plugin "Crayon Syntax Highlighter" this unwanted behaviour doesn't happen. See screenshot below.

    screen shot 2014-06-02 at 14 34 08

    I expect the same behaviour in my editor with or without "Cryon Syntax Highlighter" activated. Can you help me out?

    opened by hans2103 17
  • 1.11 Breaks site (Uncaught ReferenceError: CrayonSyntaxSettings is not defined)

    1.11 Breaks site (Uncaught ReferenceError: CrayonSyntaxSettings is not defined)

    So, Syntax Highlighter is beautiful - great job. Has been working peachy until 1.11 where I get this problem:

    Uncaught ReferenceError: CrayonSyntaxSettings is not defined

    If I roll back to 1.10 all is good again.

    I'm running Wordpress 3.4.2. Need any further info let me know.

    opened by benfrain 13
  • Crayon plugin - JavaScript not working in subpages - ReferenceError: Undefined variable: jQuery

    Crayon plugin - JavaScript not working in subpages - ReferenceError: Undefined variable: jQuery

    On the main page plugin are works fine. Example: http://blog.lordswm.org/page/2/

    But in any post inside - not. Example: http://blog.lordswm.org/oracle-cloud-12c-agent-reports-error-with-java-io-ioexception-error24-too-many-open-files/

    JS error: Inline script thread Uncaught exception: ReferenceError: Undefined variable: jQuery Error thrown at line 1, column 0 in http://blog.lordswm.org/wp-content/plugins/crayon-syntax-highlighter/js/min/crayon.min.js?ver=2.6.0: var jQueryCrayon=jQuery;

    opened by kerberois 11
  • Line Wrapping Breaks Line Numbering

    Line Wrapping Breaks Line Numbering

    When line wrapping is enabled, two line numbers are used when a line has been wrapped (see line-wrapping-01.png). This results in the lines at the end of a code segment not having any line numbering as they have already been used by the wrapped lines above it (see line-wrapping-02.png)

    line-wrapping-01.png line-wrapping-01

    line-wrapping-02.png line-wrapping-02

    opened by cdodd 11
  • THANK YOU!

    THANK YOU!

    Sorry for all caps title. :wink:

    This is just meant to be a big thank you post/issue. Where I just say thank you for everything!

    Thanks for everything! For making this awesome plugin which really is the best currently available. And thank you very much for doing this for free except for the donations (which I will provide when I can). :smile:

    Eduan out.

    opened by greduan 11
  • Documentation issues for theme makers

    Documentation issues for theme makers

    • The classes .n and .f don't have a clear meaning, how do you invoke them? How do you achieve them in code and/or in the editor.
    • The classes .p and .ta are not described at all. In this documentation.
    • I wasn't able to find the class for integers... If you know which one it is, it's supposed to have the following color, the Solarized dark/light colorscheme: #2aa198
    • For some reason true/false is not recognized as a constant or boolean if inside a function call. (E.g. functionName(true, false, 1) true/false are the same color as the rest of arguments...)

    Those are some issues I ran across, thought I would open a new topic so you can look into them. :wink:

    opened by greduan 11
  • Solrazied color scheme

    Solrazied color scheme

    Hi, just wanted to say.

    Would it be possible to add the Solarized color schemes? Light and dark versions?

    I would be interested in doing this myself, if I could just get some documentation on what each thing does and highlights. :)

    - Eduan

    opened by greduan 11
  • Uncaught ReferenceError: CrayonSyntaxSettings is not defined

    Uncaught ReferenceError: CrayonSyntaxSettings is not defined

    I'm using this plugin with W3 Total Cache on my blog. If I enable JS minify the highlighter gives JS errors in the console: Uncaught ReferenceError: CrayonSyntaxSettings is not defined

    Because of this error other plugins doesn't work propper too (in my case the Shareaholic SexyBookmark plugin).

    I hope you can fix this so I can re-enable the JS minify function from W3 Total Cache!

    opened by royduin 11
  • Crayon button in visual editor not working on wordpress 3.9

    Crayon button in visual editor not working on wordpress 3.9

    When in the visual editor, when clicking on the add code button no dialog appears, works OK when in HTML mode though. Can this be fixed as I like to work visually and switching between the two is a pain.

    Thanks

    opened by shaunfreeman 10
  • Editor not working with 3.8.1

    Editor not working with 3.8.1

    The post/page editor in admin does not work with this plugin installed, on version 3.8.1. I have my blog set to update to the latest nightly builds - not sure if that has anything to do with it. When I disable Crayon, the editor works again.

    opened by kennyr 10
  • Backticks are ignored when no other code is formatted

    Backticks are ignored when no other code is formatted

    In order for backticks to be captured, there must be some other code formatted with Crayon in the posting.

    This seems like a bug to me.

    When I have a posting that contains blocks of code and they are formatted with Crayon, any other code posted inline and highlighted with backticks is automatically captured and formatted as per my Crayon settings.

    However, if the post does not contain any code blocks formatted with Crayon, then any code posted inline code using backticks is totally ignored.

    How can I have Crayon capture backticks automatically?

    There are no errors in the Crayon log file.

    opened by sparky672 10
  • Deprecated: implode() function

    Deprecated: implode() function

    Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters

    Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in wp-content/plugins/crayon-syntax-highlighter/util/crayon_util.class.php on line 73
    
    opened by yasuda-farm 1
  • Plugin appears to be abandoned ...

    Plugin appears to be abandoned ...

    This is true? Details: It was last updated 5 years 11 months ago and tested up to WordPress 4.2.0. Plugins can be removed from wordpress.org for various reasons. This can include benign issues like a plugin author discontinuing development or moving the plugin distribution to their own site, but some might also be due to security issues. In any case, future updates may or may not be available, so it is worth investigating the cause and deciding whether to temporarily or permanently replace or remove the plugin

    opened by catafest 0
  • Some problem with <> brackets

    Some problem with <> brackets

    This is My original code

    class _SecondScreenState extends State<SecondScreen> {
    
    }
    

    this is what your plugin show

    class _SecondScreenState extends State&lt;SecondScreen&gt; {
     
    }
    
    opened by dhameliyamilan 0
  • On Wordpress 5.5: Error Uncaught TypeError: $(...).live is not a function

    On Wordpress 5.5: Error Uncaught TypeError: $(...).live is not a function

    Uncaught TypeError: $(...).live is not a function

    at Object.base.init (crayon_admin.js?ver=_2.7.2_beta:131)
    at HTMLDocument.<anonymous> (options-general.php?page=crayon_settings:226)
    at i (load-scripts.php?c=0&load[chunk_0]=jquery,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-resizable,jquery-ui-draggable,jquery-ui-button,jquery-ui-&load[chunk_1]=position,jquery-ui-dialog,wpdialogs,jquery-ui-tabs,jquery-ui-slider,jquery-ui-droppable,jquery-ui-selectable&ver=5.5:2)
    at Object.fireWith [as resolveWith] (load-scripts.php?c=0&load[chunk_0]=jquery,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-resizable,jquery-ui-draggable,jquery-ui-button,jquery-ui-&load[chunk_1]=position,jquery-ui-dialog,wpdialogs,jquery-ui-tabs,jquery-ui-slider,jquery-ui-droppable,jquery-ui-selectable&ver=5.5:2)
    at Function.ready (load-scripts.php?c=0&load[chunk_0]=jquery,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-resizable,jquery-ui-draggable,jquery-ui-button,jquery-ui-&load[chunk_1]=position,jquery-ui-dialog,wpdialogs,jquery-ui-tabs,jquery-ui-slider,jquery-ui-droppable,jquery-ui-selectable&ver=5.5:2)
    at HTMLDocument.J (load-scripts.php?c=0&load[chunk_0]=jquery,utils,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-resizable,jquery-ui-draggable,jquery-ui-button,jquery-ui-&load[chunk_1]=position,jquery-ui-dialog,wpdialogs,jquery-ui-tabs,jquery-ui-slider,jquery-ui-droppable,jquery-ui-selectable&ver=5.5:2)
    
    opened by yzxoi 1
Owner
Aram Kocharyan
🚀 Software Engineer
Aram Kocharyan
Render (GitHub Flavoured with syntax highlighting) Markdown, and generate CSS for each of GitHub’s themes.

render-gfm Render (GitHub Flavoured with syntax highlighting) Markdown, and generate CSS for each of GitHub’s themes. GitHub Repository npm Package Do

Shaun Bharat 12 Oct 10, 2022
A refined tool for exploring open-source projects on GitHub with a file tree, rich Markdown and image previews, multi-pane multi-tab layouts and first-class support for Ink syntax highlighting.

Ink codebase browser, "Kin" ?? The Ink codebase browser is a tool to explore open-source code on GitHub, especially my side projects written in the In

Linus Lee 20 Oct 30, 2022
Syntax Highlighter bot for Telegram.

??️ Syntax Highlighter Bot Kind of a copy; highly inspired from Piterden/syntax-highlighter-bot - Telegram Bot here Minimal syntax highlighting bot fo

Dunkan 18 Nov 11, 2022
An experimental syntax highlighter web app bot based on Telegram's WebApp update.

Syntax Highlighter WebApp Inspired by zubiden/tg-web-bot-demo. Try the demo bot running here: @syntaxyybot Recently Telegram released a big update for

Dunkan 12 Nov 8, 2022
✏️ Super lightweight JSX syntax highlighter, around 1KB after minified and gzipped

Sugar High Introduction Super lightweight JSX syntax highlighter, around 1KB after minified and gzipped Usage npm install --save sugar-high import { h

Jiachi Liu 67 Dec 8, 2022
A beautiful Syntax Highlighter.

Shiki Shiki is a beautiful Syntax Highlighter. Demo. Usage npm i shiki const shiki = require('shiki') shiki .getHighlighter({ theme: 'nord' }

Shiki 4.2k Dec 31, 2022
Backend API Rest application for ShortLink, a URL shortening service where you enter a valid URL and get back an encoded URL

ShortLink - The Shortest URL (API) Sobre o Projeto | Como Usar | Importante! Sobre o projeto The Shortest URL é um projeto back-end de ShortLink, um s

Bruno Weber 2 Mar 22, 2022
Syntax highlighting, like GitHub

Close up of The Starry Night by Vincent van Gogh (1889) with examples of starry-night over it starry-night Syntax highlighting, like what GitHub uses

Titus 585 Dec 21, 2022
URL Shortener API in NodeJS supporting pagination, sort params and lot more

node-url-shortener Built with ❤️ in NodeJS A simple URL Shortner REST API that uses shortid npm package to generate short endpoints for your long URL.

Dhairya Ostwal 3 Sep 22, 2022
Move all the disks from the left hand post to the right hand post, only moving the disks one at a time and a bigger disk can never be placed on a smaller disk.

Hanoi Tower Description The Tower of Hanoi was a famous problem posed by a mathematician in 1883, The "puzzle" is to move all the disks from the left

Dustin J Sellers 1 Feb 5, 2022
🍎Transform an SVG icon into multiple themes, and generate React icons,Vue icons,svg icons

IconPark English | 简体中文 Introduction IconPark gives access to more than 2000 high-quality icons, and introduces an interface for customizing your icon

Bytedance Inc. 6.8k Jan 5, 2023
A lib for text highlighting by using Canvas.

canvas-highlighter 基于 canvas 实现的文本划词高亮,与文本展示的结构完全解耦,不改变文本内容的 DOM 结构。 Installation npm install canvas-highlighter Usage 最简单的实现文本划词直接高亮 import CanvasHig

null 72 Dec 24, 2022
Quickly create console debugging information for multiple languages.

Debugger for Console Quickly create console debugging information for multiple languages. This plugin uses antfu/starter-vscode as the initial templat

Chestnut 5 Oct 21, 2022
Add multiple languages support for RPG Maker MV games.

============================================================================ __ __ _ _ _ _ |

Nozaki Yuu (野崎悠) 2 Dec 19, 2022
Create your frontend website in multiple languages by using this class.

Javascript Langauge Selector Create your frontend website in multiple languages by using this class. Features Simple but yet powerful. Enable RTL auto

Muhammad Umer Farooq 7 Dec 14, 2022
Piccloud is a full-stack (Angular & Spring Boot) online image clipboard that lets you share images over the internet by generating a unique URL. Others can access the image via this URL.

Piccloud Piccloud is a full-stack application built with Angular & Spring Boot. It is an online image clipboard that lets you share images over the in

Olayinka Atobiloye 3 Dec 15, 2022
An enhanced HTML 5 file input for Bootstrap 5.x/4.x./3.x with file preview, multiple selection, and more features.

bootstrap-fileinput An enhanced HTML 5 file input for Bootstrap 5.x, 4.x, and 3.x with file preview for various files, offers multiple selection, resu

Kartik Visweswaran 5.2k Jan 3, 2023
Privacy-focused Google Fonts alternative

Privacy-focused Google Fonts CDN alternative I wrote it in an hour, so please report bugs here. Several improvements could be made here and there, so

coolLabs 245 Dec 27, 2022