Product knowledge base

Quick Links

Video

TBD: create a video tutorial

Technical description

The widget allow users to add code block with the abilities to:

Known issues / attention needed

Style (CSS)

All the css files for the 6 themes and 3 plugins are local and combined to a single CSS file instead of using the CDN, in order to avoid too many requests. Another reason is because we use custom classes to handle the selected themes and features (as line-numbers and such) when the code highlight is being used more than once in the same page.

There are 3 SCSS files that gets combined into a single file:

There is a small CSS fix in main-style.scss which solves a conflict when highlighting lines while hiding line numbers.

Functionality (JS)

All the scripts are requested from a CDN instead of using local files since we found it difficult to manage all the plugins to work properly when combined to a single local file.

There are 7 JS Files which we use from a CDN, the last 3 are added only if the user chose the functionality they responsible for:

handler.js - For the “word wrap” feature to work, we use the onElementChange method to run the prism plugin again and adjust to the changes.

There is a plugin named inline-color that we had to remove since it only worked when we used the PrismJS plugin with all the languages included in the same file. That means one big file that includes the whole functionality of the plugin AND all the languages, which is a huge performance penalty. Instead, we use the prisms-loader plugin which dynamically loads the needed language when the user selects it and it means a smaller JS bundle.

Functionality (PHP)

code-highlight.php - The language control is used to give the user a code language selection from the most popular code languages. We've added an apply_filter to the control in order to give the user more flexibility when choosing a code language.

We replaced the typography group control with just a font-size control since we didn’t manage to make the line-height work with the line numbers. This decision was made since most of the controls in the typography group control are not so useful in this case anyway.