Source Code
The core Code block shows monospace text in one colour. This block highlights the syntax of 26 languages on the server (so it is coloured without any script and never runs code), and adds a copy button, download, several files in tabs, line numbers starting anywhere, highlighted lines, diff colours, a “show more” for long code, eight themes and a caption. It converts to and from the core Code and Preformatted blocks.
Ready-made patterns
Inserter → Patterns → Moduly.
Fetch with a timeout
Abort a request that takes too long — the highlighted lines do the work.
// Give up after `ms` milliseconds.export async function fetchWithTimeout( url, ms = 5000 ) { const controller = new AbortController(); const timer = setTimeout( () => controller.abort(), ms ); try { const res = await fetch( url, { signal: controller.signal } ); return await res.json(); } finally { clearTimeout( timer ); }}A toggle button
<button class="toggle" aria-pressed="false"> Dark mode</button>.toggle { padding: .6em 1.2em; border-radius: 999px;}.toggle[aria-pressed="true"] { background: #111827; color: #fff;}document.querySelector( '.toggle' ).addEventListener( 'click', ( e ) => { const on = e.currentTarget.getAttribute( 'aria-pressed' ) === 'true'; e.currentTarget.setAttribute( 'aria-pressed', String( ! on ) ); document.documentElement.classList.toggle( 'dark', ! on );} );What changed
@@ -12,7 +12,8 @@ function shipping_cost( $cart ) {- if ( $cart->total > 50 ) {+ $free_from = (float) get_option( 'free_shipping_from', 50 );+ if ( $cart->total >= $free_from ) { return 0; } return 4.95;Eight themes
Midnight
<?php// Register a custom post type.add_action( 'init', function () { register_post_type( 'book', [ 'label' => __( 'Books', 'my-theme' ), 'public' => true, ] );} );Daylight
<?php// Register a custom post type.add_action( 'init', function () { register_post_type( 'book', [ 'label' => __( 'Books', 'my-theme' ), 'public' => true, ] );} );Monokai
<?php// Register a custom post type.add_action( 'init', function () { register_post_type( 'book', [ 'label' => __( 'Books', 'my-theme' ), 'public' => true, ] );} );Dracula
<?php// Register a custom post type.add_action( 'init', function () { register_post_type( 'book', [ 'label' => __( 'Books', 'my-theme' ), 'public' => true, ] );} );Nord
<?php// Register a custom post type.add_action( 'init', function () { register_post_type( 'book', [ 'label' => __( 'Books', 'my-theme' ), 'public' => true, ] );} );Solarized light
<?php// Register a custom post type.add_action( 'init', function () { register_post_type( 'book', [ 'label' => __( 'Books', 'my-theme' ), 'public' => true, ] );} );GitHub light
<?php// Register a custom post type.add_action( 'init', function () { register_post_type( 'book', [ 'label' => __( 'Books', 'my-theme' ), 'public' => true, ] );} );Synthwave
<?php// Register a custom post type.add_action( 'init', function () { register_post_type( 'book', [ 'label' => __( 'Books', 'my-theme' ), 'public' => true, ] );} );Languages
Python
from statistics import mean @cachedef average(values: list[float]) -> float: """Return the mean, or 0 for an empty list.""" return mean(values) if values else 0.0 print(average([3, 4, 5])) # 4SQL
SELECT c.name, SUM(o.total) AS spentFROM customers cJOIN orders o ON o.customer_id = c.idWHERE o.created_at >= '2026-01-01'GROUP BY c.nameORDER BY spent DESCLIMIT 10;Bash
#!/usr/bin/env bashset -euo pipefail for site in blog shop docs; do echo "Deploying $site…" rsync -az ./dist/$site/ "deploy@example.com:/var/www/$site"doneJSON
{ "name": "my-shop", "version": "1.4.0", "private": true, "scripts": { "build": "vite build" }}Rust
fn main() { let items = vec![3, 1, 2]; let total: i32 = items.iter().sum(); println!("Total: {}", total);}YAML
services: db: image: mariadb:11 environment: MARIADB_ROOT_PASSWORD: secret # change me ports: - "3306:3306"Options
Collapsed after 8 lines
<?phpreturn [ 'option_1' => 'value', 'option_2' => true, 'option_3' => true, 'option_4' => 'value', 'option_5' => true, 'option_6' => true, 'option_7' => 'value', 'option_8' => true, 'option_9' => true, 'option_10' => 'value', 'option_11' => true, 'option_12' => true, 'option_13' => 'value', 'option_14' => true, 'option_15' => true, 'option_16' => 'value', 'option_17' => true, 'option_18' => true, 'option_19' => 'value', 'option_20' => true, 'option_21' => true, 'option_22' => 'value', 'option_23' => true, 'option_24' => true, 'option_25' => 'value', 'option_26' => true, 'option_27' => true, 'option_28' => 'value', 'option_29' => true, 'option_30' => true,];Maximum height 220 px (scrolls)
<?phpreturn [ 'option_1' => 'value', 'option_2' => true, 'option_3' => true, 'option_4' => 'value', 'option_5' => true, 'option_6' => true, 'option_7' => 'value', 'option_8' => true, 'option_9' => true, 'option_10' => 'value', 'option_11' => true, 'option_12' => true, 'option_13' => 'value', 'option_14' => true, 'option_15' => true, 'option_16' => 'value', 'option_17' => true, 'option_18' => true, 'option_19' => 'value', 'option_20' => true, 'option_21' => true, 'option_22' => 'value', 'option_23' => true, 'option_24' => true, 'option_25' => 'value', 'option_26' => true, 'option_27' => true, 'option_28' => 'value', 'option_29' => true, 'option_30' => true,];Line numbers from 120 · highlight 121-122
if ( cart.items.length === 0 ) { showEmptyState(); return;}renderTotals( cart );Long lines wrapped · no numbers
# Release notes This release makes the checkout faster by loading the payment form only when it is needed, which saves roughly 180 kB of JavaScript on the first page view for most visitors. - **Fixed:** coupon codes with spaces- `npm run build` is now twice as fastNo header · icon-only copy and download float
:root { --neon: #ff7edb;}h1 { color: var(--neon); text-shadow: 0 0 8px currentColor; }Grey dots · no language · radius 4 · 16 px
# Local settingsAPP_ENV=localAPP_DEBUG=trueDB_HOST=127.0.0.1Wide, with four files and a caption
<?php/** * Plugin Name: My Plugin */add_action( 'wp_enqueue_scripts', function () { wp_enqueue_script( 'my-plugin', plugins_url( 'app.js', __FILE__ ), [], '1.0', true );} );document.addEventListener( 'DOMContentLoaded', () => { console.log( 'My Plugin is ready' );} );.my-plugin { display: grid; gap: 1rem; }=== My Plugin ===Requires at least: 6.5Stable tag: 1.0