• Stars
    star
    118
  • Rank 298,809 (Top 6 %)
  • Language
    PHP
  • License
    GNU General Publi...
  • Created about 6 years ago
  • Updated 7 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Extending the WordPress Code block with syntax highlighting rendered on the server, thus having faster frontend performance and being AMP-compatible.

Syntax-highlighting Code Block (with Server-side Rendering)

Banner

Extending the Code block with syntax highlighting rendered on the server, thus being AMP-compatible and having faster frontend performance.

Contributors: westonruter, allejo
Tags: block, code, code syntax, syntax highlight, code highlighting
Requires at least: 5.6
Tested up to: 6.3
Stable tag: 1.4.0
License: GPLv2 or later
Requires PHP: 5.6

Continuous Integration Built with Grunt

Description

This plugin extends the Code block in WordPress core to add syntax highlighting which is rendered on the server. Pre-existing Code blocks on a site are automatically extended to include syntax highlighting. Doing server-side syntax highlighting eliminates the need to enqueue any JavaScript on the frontend (e.g. Highlight.js or Prism.js) and this ensures there is no flash of unhighlighted code (FOUC?). Reducing script on the frontend improves frontend performance and it also allows for the syntax highlighted code to appear properly in AMP pages as rendered by the official AMP plugin (see also ampproject/amp-wp#972) or when JavaScript is turned off in the browser.

In addition to not adding any JavaScript to the frontend, the stylesheets needed for styling the Code block will only be added to the page if there is a Code block present. The stylesheets are added inline when the Code block is rendered, ensuring that they do not block rendering of any content higher in the page. If stylesheets fail to load for any reason, the block simply renders without styling, with one key exception: highlighted lines are wrapped in mark elements so they'll get highlighted regardless, including in RSS Feeds and posts syndicated in email (as long as the mark element is supported in the client).

This extended Code block uses language auto-detection to add syntax highlighting, but you can override the language in the block's settings sidebar. (There is currently no syntax highlighting of the Code block in the editor.) The plugin supports all programming languages that highlight.php supports (being a port of highlight.js). The Code block also is extended to support specifying the aforementioned highlighted lines. There is also a checkbox for whether to show line numbers on the frontend (with the numbers being non-selectable). Lastly, given inconsistencies across themes as to whether lines in a Code block should be wrapped, this plugin adds styling to force them to no-wrap by default, with a checkbox to opt-in to wrapping when desired.

For advanced usage, please see the plugin wiki.

This plugin is developed on GitHub. See list of current issues with the plugin. Please feel free to file any additional issues or requests that you may come across. Pull requests are welcome. See contributing information.

Credits

This is a fork of Code Syntax Block by Marcus Kazmierczak (mkaz), which is also available on WordPress.org. Copyright (c) 2018 Marcus Kazmierczak. Licensed under GPL 2.0 or later.

highlight.php is released under the BSD 3-Clause License. Copyright © 2006-2013, Ivan Sagalaev ([email protected]), highlight.js (original author). Copyright © 2013, Geert Bergman ([email protected]), highlight.php

Screenshots

Code blocks can be added as normal, optionally overriding the auto-detected language. Also specify any lines to be highlighted, whether to show line numbers, and if the lines should wrap.

Code blocks can be added as normal, optionally overriding the auto-detected language. Also specify any lines to be highlighted, whether to show line numbers, and if the lines should wrap.

The Code block renders with syntax highlighting on the frontend without any JavaScript enqueued. Stylesheets are added only when block is on the page.

The Code block renders with syntax highlighting on the frontend without any JavaScript enqueued. Stylesheets are added only when block is on the page.

Changelog

For the plugin’s changelog, please see the Releases page on GitHub.

More Repositories

1

webforms2

Web Forms 2.0 Cross-Browser Implementation
JavaScript
237
star
2

html5-audio-read-along

HTML5 Audio Read-Along
JavaScript
191
star
3

ipa-chart

International Phonetic Alphabet (IPA) Unicode Chart and Character Picker
HTML
125
star
4

esv-text-audio-aligner

ESV Text/Audio Aligner to programmatically obtain the timings for each word in the corresponding audio
JavaScript
88
star
5

spoken-word

Spoken Word
JavaScript
48
star
6

svg-tree-drawer

Drawing tree structures with SVG and JavaScript
JavaScript
34
star
7

json-xml-rpc

JSON/XML-RPC Client and Server Implementations
PHP
24
star
8

jquery-css-transitions

CSS Transitions via jQuery Animation
JavaScript
18
star
9

schemagraph

SchemaGraph: Visualizing Complex Databases
PHP
17
star
10

misc-cli-tools

Miscellaneous command-line tools to improve workflow
Python
14
star
11

css-gradients-via-canvas

CSS Gradients via Canvas
JavaScript
10
star
12

wp-manage

WordPress Manager Script
Perl
7
star
13

twentyseventeen-westonson

My child theme of Twenty Seventeen for testing.
PHP
4
star
14

djsango

Djsango: A Django-esque framework for client-side web applications
JavaScript
3
star
15

javascriptforwp-conference-amp-examples

HTML
2
star
16

raspberry-pi-cture-frame

Raspberry Pi-cture Frame
JavaScript
2
star
17

xhtml-document-write

XHTML document.write() Support
JavaScript
2
star
18

raspberry-pi-stuff

Python
2
star
19

amp-tablepress

AMP adapter plugin for the TablePress plugin for WordPress
PHP
2
star
20

wp-listenability

Listenability WordPress plugin
PHP
2
star
21

version.js

JavaScript object for representing and comparing version numbers (with major, minor, patch)
JavaScript
2
star
22

wp-script-loading-strategy-tests

Demo plugin that puts together various scenarios to test the script loading strategies proposed for WordPress core
PHP
1
star
23

rutersearch

One of my first programming projects (circa 1999)
1
star
24

amp-wp-theme-compat-analysis

HTML
1
star
25

benchmark-wp-html-tag-processor

HTML
1
star
26

westonruter.github.com

User pages
HTML
1
star
27

tweets.weston.ruter.net

Twitter archive for @westonruter
JavaScript
1
star
28

github-local-commit-log

Local viewer of commits in the current branch, filtering the log to commits containing certain file types, and other criteria, with permalinks back to GitHub for doing code reviews
PHP
1
star
29

taggame.js

The Game of Tag in Node.js
JavaScript
1
star
30

window-wrapper

Proof of concept for transparently wrapping a site in an iframe to allow for persistent elements on the page (e.g. chat)
JavaScript
1
star