<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>Visual Studio Code &#8211; Wade Tregaskis</title>
	<atom:link href="https://wadetregaskis.com/tags/visual-studio-code/feed/" rel="self" type="application/rss+xml" />
	<link>https://wadetregaskis.com</link>
	<description></description>
	<lastBuildDate>Thu, 07 Mar 2024 02:32:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://wadetregaskis.com/wp-content/uploads/2016/03/Stitch-512x512-1-256x256.png</url>
	<title>Visual Studio Code &#8211; Wade Tregaskis</title>
	<link>https://wadetregaskis.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">226351702</site>	<item>
		<title>Swift code syntax highlighting in WordPress</title>
		<link>https://wadetregaskis.com/swift-code-syntax-highlighting-in-wordpress/</link>
					<comments>https://wadetregaskis.com/swift-code-syntax-highlighting-in-wordpress/#comments</comments>
		
		<dc:creator><![CDATA[]]></dc:creator>
		<pubDate>Sat, 30 Dec 2023 02:34:43 +0000</pubDate>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Meta]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Code Block Pro]]></category>
		<category><![CDATA[Code Syntax Block]]></category>
		<category><![CDATA[CodeColorer]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Dark mode]]></category>
		<category><![CDATA[Dracula Dark Mode]]></category>
		<category><![CDATA[Enlighter]]></category>
		<category><![CDATA[EnlighterJS]]></category>
		<category><![CDATA[GeSHi]]></category>
		<category><![CDATA[highlight.js]]></category>
		<category><![CDATA[highlight.php]]></category>
		<category><![CDATA[Highlighting Code Block]]></category>
		<category><![CDATA[Prism.js]]></category>
		<category><![CDATA[Prismatic]]></category>
		<category><![CDATA[Shiki]]></category>
		<category><![CDATA[syntax highlighting]]></category>
		<category><![CDATA[Syntax-highlighting Code Block (with Server-side Rendering)]]></category>
		<category><![CDATA[SyntaxHighlighter Evolved]]></category>
		<category><![CDATA[Tested]]></category>
		<category><![CDATA[TextMate]]></category>
		<category><![CDATA[Urvanov Syntax Highlighter]]></category>
		<category><![CDATA[Visual Studio Code]]></category>
		<category><![CDATA[WP Dark Mode]]></category>
		<category><![CDATA[Xcode]]></category>
		<guid isPermaLink="false">https://blog.wadetregaskis.com/?p=5561</guid>

					<description><![CDATA[The built-in &#8220;code&#8221; block for WordPress (the CMS I use for this site) is virtually useless &#8211; it&#8217;s just a &#60;pre&#62; block, essentially. The appearance may vary depending on WordPress theme, but will virtually always be bland. In fact, it&#8217;s not even guaranteed to use a monospaced font &#8211; the example I&#8217;ve shown here is&#8230; <a class="read-more-link" href="https://wadetregaskis.com/swift-code-syntax-highlighting-in-wordpress/" data-wpel-link="internal">Read more</a>]]></description>
										<content:encoded><![CDATA[



<div class="alignnormal"><div id="metaslider-id-6572" style="max-width: 611px;" class="ml-slider-3-107-0 metaslider metaslider-flex metaslider-6572 ml-slider ms-theme-default nav-hidden" role="region" aria-label="Syntax highlighting: WordPress default" data-height="1158" data-width="611">
    <div id="metaslider_container_6572">
        <div id="metaslider_6572" class="flexslider">
            <ul class='slides'>
                <li style="display: block; width: 100%;" class="slide-6575 ms-image " aria-roledescription="slide" data-date="2023-12-12 11:07:27" data-filename="WordPress-default-Light.webp" data-slide-type="image"><img fetchpriority="high" decoding="async" width="1222" height="2316" src="https://wadetregaskis.com/wp-content/uploads/2023/12/WordPress-default-Light.webp" class="slider-6572 slide-6575 msDefaultImage" alt="" rel="" title="WordPress default (Light)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/WordPress-default-Light.webp 1222w, https://wadetregaskis.com/wp-content/uploads/2023/12/WordPress-default-Light-135x256.webp 135w, https://wadetregaskis.com/wp-content/uploads/2023/12/WordPress-default-Light-270x512@2x.webp 540w, https://wadetregaskis.com/wp-content/uploads/2023/12/WordPress-default-Light-1081x2048.webp 1081w, https://wadetregaskis.com/wp-content/uploads/2023/12/WordPress-default-Light-270x512.webp 270w, https://wadetregaskis.com/wp-content/uploads/2023/12/WordPress-default-Light-540x1024@2x.webp 1080w" sizes="(max-width: 1222px) 100vw, 1222px" /><div class="caption-wrap"><div class="caption">Light mode</div></div></li>
                <li style="display: none; width: 100%;" class="slide-6576 ms-image " aria-roledescription="slide" data-date="2023-12-12 11:07:28" data-filename="WordPress-default-Dark.webp" data-slide-type="image"><img decoding="async" width="1222" height="2316" src="https://wadetregaskis.com/wp-content/uploads/2023/12/WordPress-default-Dark.webp" class="slider-6572 slide-6576 msDefaultImage" alt="" rel="" title="WordPress default (Dark)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/WordPress-default-Dark.webp 1222w, https://wadetregaskis.com/wp-content/uploads/2023/12/WordPress-default-Dark-135x256.webp 135w, https://wadetregaskis.com/wp-content/uploads/2023/12/WordPress-default-Dark-270x512@2x.webp 540w, https://wadetregaskis.com/wp-content/uploads/2023/12/WordPress-default-Dark-1081x2048.webp 1081w, https://wadetregaskis.com/wp-content/uploads/2023/12/WordPress-default-Dark-270x512.webp 270w, https://wadetregaskis.com/wp-content/uploads/2023/12/WordPress-default-Dark-540x1024@2x.webp 1080w" sizes="(max-width: 1222px) 100vw, 1222px" /><div class="caption-wrap"><div class="caption">Dark mode</div></div></li>
            </ul>
        </div>
        
    </div>
</div></div>



<p>The built-in &#8220;code&#8221; block for <a href="https://wordpress.org" data-wpel-link="external" target="_blank" rel="external noopener">WordPress</a> (the <a href="https://en.wikipedia.org/wiki/Content_management_system" data-wpel-link="external" target="_blank" rel="external noopener">CMS</a> I use for this site) is virtually useless &#8211; it&#8217;s just a &lt;pre&gt; block, essentially.</p>



<p>The appearance may vary depending on WordPress theme, but will virtually always be bland.</p>



<p>In fact, it&#8217;s not even guaranteed to use a monospaced font &#8211; the example I&#8217;ve shown here is what you&#8217;ll <em>probably</em> get with any given WordPress theme, but it&#8217;s not actually the default for the theme I use (<a href="https://generatepress.com" data-wpel-link="external" target="_blank" rel="external noopener">GeneratePress</a>) due to <a href="https://github.com/tomusborne/generatepress/issues/395" data-wpel-link="external" target="_blank" rel="external noopener">a known bug in GeneratePress</a> (which the theme authors outright refuse to fix!).</p>



<p class="wp-container-content-9cfa9a5a">In any case, you have to use <a href="https://wordpress.org/plugins/search/code+syntax+highlighter/" data-wpel-link="external" target="_blank" rel="external noopener">WordPress plug-ins</a> to extend or replace it with something that actually looks in any way decent.</p>



<p class="wp-container-content-9cfa9a5a">Unfortunately, Swift is a complicated language, even just at the &#8220;superficial&#8221; level of syntax highlighting.  And most generally-popular syntax highlighting tools are both:</p>



<ol class="wp-block-list">
<li>Focused on languages like JavaScript and HTML, not Swift.</li>



<li>Written in JavaScript or Ruby, with no access to standard tooling like the <a href="https://github.com/apple/sourcekit-lsp" data-wpel-link="external" target="_blank" rel="external noopener">Swift Language Server Protocol</a>.</li>
</ol>



<p>Since I&#8217;m using WordPress for this site, Ruby&#8217;s not a good option (and I didn&#8217;t find any relevant WordPress plug-ins which rely on it, anyway).  Hypothetically I could add a Ruby environment to my server and do static generation through it, but, ugh.  It&#8217;s annoying enough dealing with JavaScript and PHP.  If you&#8217;re going to go to that much trouble, you&#8217;d probably be better off actually using Swift (e.g. <a href="https://github.com/apple/swift-syntax" data-wpel-link="external" target="_blank" rel="external noopener">SwiftSyntax</a>).  And while I&#8217;d welcome a WordPress plug-in which does exactly that, alas no such plug-in exists today.</p>



<p>So, I spent <em>way</em> too much of my time trying out a <em>bunch</em> of the available WordPress plug-ins, and now I shall report the results so others don&#8217;t have to suffer [as much].</p>



<p>I&#8217;ve presented previews for both light and dark modes (but my apologies to dark-mode viewers that all the samples default to light mode &#8211; an unfortunate limitation of my CMS).</p>



<h1 class="wp-block-heading">Baseline: Xcode</h1>



<div class="alignnormal"><div id="metaslider-id-6568" style="max-width: 492px;" class="ml-slider-3-107-0 metaslider metaslider-flex metaslider-6568 ml-slider ms-theme-default nav-hidden nav-hidden" role="region" aria-label="Syntax highlighting: Xcode [Default]" data-height="1100" data-width="492">
    <div id="metaslider_container_6568">
        <div id="metaslider_6568" class="flexslider">
            <ul class='slides'>
                <li style="display: block; width: 100%;" class="slide-6570 ms-image " aria-roledescription="slide" data-date="2023-12-12 10:47:45" data-filename="Xcode-Default-Light.webp" data-slide-type="image"><img decoding="async" width="984" height="2200" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Xcode-Default-Light.webp" class="slider-6568 slide-6570 msDefaultImage" alt="" rel="" title="Xcode [Default] (Light)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Xcode-Default-Light.webp 984w, https://wadetregaskis.com/wp-content/uploads/2023/12/Xcode-Default-Light-115x256.webp 115w, https://wadetregaskis.com/wp-content/uploads/2023/12/Xcode-Default-Light-229x512@2x.webp 458w, https://wadetregaskis.com/wp-content/uploads/2023/12/Xcode-Default-Light-916x2048.webp 916w, https://wadetregaskis.com/wp-content/uploads/2023/12/Xcode-Default-Light-229x512.webp 229w, https://wadetregaskis.com/wp-content/uploads/2023/12/Xcode-Default-Light-115x256@2x.webp 230w" sizes="(max-width: 984px) 100vw, 984px" /><div class="caption-wrap"><div class="caption">Light mode</div></div></li>
                <li style="display: none; width: 100%;" class="slide-6569 ms-image " aria-roledescription="slide" data-date="2023-12-12 10:47:45" data-filename="Xcode-Default-Dark.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="984" height="2200" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Xcode-Default-Dark.webp" class="slider-6568 slide-6569 msDefaultImage" alt="" rel="" title="Xcode [Default] (Dark)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Xcode-Default-Dark.webp 984w, https://wadetregaskis.com/wp-content/uploads/2023/12/Xcode-Default-Dark-115x256.webp 115w, https://wadetregaskis.com/wp-content/uploads/2023/12/Xcode-Default-Dark-229x512@2x.webp 458w, https://wadetregaskis.com/wp-content/uploads/2023/12/Xcode-Default-Dark-916x2048.webp 916w, https://wadetregaskis.com/wp-content/uploads/2023/12/Xcode-Default-Dark-229x512.webp 229w, https://wadetregaskis.com/wp-content/uploads/2023/12/Xcode-Default-Dark-115x256@2x.webp 230w" sizes="auto, (max-width: 984px) 100vw, 984px" /><div class="caption-wrap"><div class="caption">Dark mode</div></div></li>
            </ul>
        </div>
        
    </div>
</div></div>



<p>Syntax highlighting theming is a very subjective and somewhat personal preference.  I really must stress this, as something to keep in mind as I critique these plug-ins based on <em>my</em> preference, which is pretty close to Xcode&#8217;s default theme.</p>



<p>I&#8217;ve tried to focus mostly on how well the plug-ins understand Swift syntax &amp; grammar and what functionality they offer broadly, rather than which ones look prettier out of the box.  Most have at least some degree of custom theming support, or at least permit unofficial theming through straightforward CSS overrides.</p>



<p>It is unsurprising that Xcode does by <em>far</em> the best job of understanding and correctly syntax-highlighting Swift code, of anything tested here.  It has the advantage of being able to actually compile and analyse the code with full context &#8211; the example shown here has supporting type and function definitions &#8220;off-screen&#8221; &#8211; which WordPress plug-ins do not<sup data-fn="f5cd2d93-b8e5-4773-8838-26add7d33f48" class="fn"><a href="#f5cd2d93-b8e5-4773-8838-26add7d33f48" id="f5cd2d93-b8e5-4773-8838-26add7d33f48-link">1</a></sup>.  While I set out on this exploration hoping to find something effectively as good as Xcode, I wasn&#8217;t really expecting to (and spoiler: I did not).</p>



<p>Allow me to call out a particular few things Xcode does right, that (as you&#8217;ll see) few if any of the WordPress plug-ins do:</p>



<ul class="wp-block-list">
<li>In short, it supports <em>all</em> Swift syntax.  It correctly identifies all the keywords (<em>and</em> things that are <em>not</em> keywords but happen to be the same word, such as static properties called <code>default</code> as in the example code).</li>



<li>It utilises not just colour but font and font weight.  This permits it to effectively delineate things without having to use an excessive variety of hues.<br><br>Some might finds its results comparatively bland with the default theme as shown here, in light mode especially, but it has other themes for those that want a more hue-centric approach, and supports a very good degree of theme customisation.<br><br>The default theme doesn&#8217;t &#8220;demo&#8221; well (in light mode), in the same way that colour-accurate TVs look rather bland and unattractive in the showroom but are actually great in real-world use in your home.</li>



<li>Even though it uses multiple font weights, it still preserves correct letter spacing.</li>



<li>It understands DocC&#8217;s limited Markdown-like markup within documentation comments (and can even render them as properly styled text, although that&#8217;s not shown here).</li>
</ul>



<p>I&#8217;ll also call out one thing which &#8211; in my opinion &#8211; it gets <em>wrong</em>, which is essentially not recognising custom type names.  It renders them as plain text &#8211; no highlighting at all &#8211; yet gives special treatment to &#8220;built-in&#8221; types (from the Swift standard library) like <code>String</code>.  It&#8217;s fine if it wants to distinguish between those two sets of type names, but it should use some kind of highlighting for <em>both</em> of them.  Many of the WordPress plug-ins actually do a better job in this respect.</p>



<h1 class="wp-block-heading">Common limitation: no Light/Dark mode support</h1>



<p>One thing that <em>none</em> of these plug-ins do, that you would think they could and reasonably should, is explicitly support light / dark mode &#8211; even though most include both light and dark themes (some plug-ins even include light and dark variations of the <em>same</em> theme &#8211; so close!).</p>



<p>Instead, you have to pick just one theme.  Furthermore, if you want proper light <em>and</em> dark mode support you have to pick a light theme specifically, to match WordPress&#8217;s default mode of light.  This limits your control over the appearance in dark mode &#8211; and may make it difficult for you to find a theme which suits your aesthetic preferences in <em>both</em> modes.</p>



<p>WordPress itself doesn&#8217;t support light/dark mode &#8211; you have to<sup data-fn="395a26f7-0a74-4647-ae97-e770481a032a" class="fn"><a href="#395a26f7-0a74-4647-ae97-e770481a032a" id="395a26f7-0a74-4647-ae97-e770481a032a-link">2</a></sup> use 3rd-party plug-ins.  Depending on which one you use, you might get viable automatic switching anyway.  The several that I experimented with were all able to make my theme adapt actually quite well.</p>



<p>I initially used <a href="https://wordpress.org/plugins/wp-dark-mode/" data-wpel-link="external" target="_blank" rel="external noopener">WP Dark Mode</a>, but discovered it was buggy in that it would load pages in light mode first and only after the initial render would it switch them to dark, making browsing my site in dark mode very uncomfortable.  It also didn&#8217;t work properly with <a href="#syntaxhighlighter-evolved" data-type="internal" data-id="#syntaxhighlighter-evolved">SyntaxHighlighter Evolved</a>.  I consequently switched to <a href="https://wordpress.org/plugins/dracula-dark-mode/" data-wpel-link="external" target="_blank" rel="external noopener">Dracula Dark Mode</a> which is a <em>very</em> similar plug-in but doesn&#8217;t have those bugs.</p>



<p>Note that most of the dark-mode screenshots shown here were taken while using WP Dark Mode.  There may be slight differences in colours with Dracula Dark Mode (or some other dark mode plug-in), but in my brief experimentation the results are virtually indistinguishable.</p>



<h1 class="wp-block-heading">The contestants</h1>



<h2 class="wp-block-heading" id="code-block-pro"><a href="https://code-block-pro.com" data-wpel-link="external" target="_blank" rel="external noopener">Code Block Pro</a></h2>



<div class="alignnormal"><div id="metaslider-id-6687" style="max-width: 572px;" class="ml-slider-3-107-0 metaslider metaslider-flex metaslider-6687 ml-slider ms-theme-default nav-hidden nav-hidden nav-hidden" role="region" aria-label="Syntax highlighting: Code Block Pro [Light Plus]" data-height="1284" data-width="572">
    <div id="metaslider_container_6687">
        <div id="metaslider_6687" class="flexslider">
            <ul class='slides'>
                <li style="display: block; width: 100%;" class="slide-6690 ms-image " aria-roledescription="slide" data-date="2023-12-13 20:22:37" data-filename="Code-Block-Pro-Light-Plus-Light.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="1144" height="2568" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-Light.webp" class="slider-6687 slide-6690 msDefaultImage" alt="" rel="" title="Code Block Pro [Light Plus] (Light)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-Light.webp 1144w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-Light-114x256.webp 114w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-Light-228x512@2x.webp 456w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-Light-912x2048.webp 912w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-Light-228x512.webp 228w" sizes="auto, (max-width: 1144px) 100vw, 1144px" /><div class="caption-wrap"><div class="caption">Light mode</div></div></li>
                <li style="display: none; width: 100%;" class="slide-6691 ms-image " aria-roledescription="slide" data-date="2023-12-13 20:22:37" data-filename="Code-Block-Pro-Light-Plus-Dark.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="1144" height="2568" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-Dark.webp" class="slider-6687 slide-6691 msDefaultImage" alt="" rel="" title="Code Block Pro [Light Plus] (Dark)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-Dark.webp 1144w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-Dark-114x256.webp 114w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-Dark-228x512@2x.webp 456w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-Dark-912x2048.webp 912w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-Dark-228x512.webp 228w" sizes="auto, (max-width: 1144px) 100vw, 1144px" /><div class="caption-wrap"><div class="caption">Dark mode</div></div></li>
            </ul>
        </div>
        
    </div>
</div></div>



<p>This advertises itself as using the syntax highlighting engine from <a href="https://code.visualstudio.com" data-wpel-link="external" target="_blank" rel="external noopener">Visual Studio Code</a>, but that&#8217;s actually misleading &#8211; it uses <a href="https://github.com/shikijs/shiki" data-wpel-link="external" target="_blank" rel="external noopener">Shiki</a>, which is really its own engine albeit one that utilises the same TextMate-inspired grammar definitions and themes as does Visual Studio Code.</p>



<p>It&#8217;s <a href="https://github.com/KevinBatdorf/code-block-pro" data-wpel-link="external" target="_blank" rel="external noopener">open source</a> and free for the most part &#8211; for a token $12 you can support the author and obtain a couple of dozen extra themes, adding to the two dozen or so that it includes by default.</p>



<h3 class="wp-block-heading">Performance</h3>



<p>If you&#8217;re familiar with Visual Studio Code for Swift development, then you basically already know how it performs, as the results are (in my testing) identical.</p>



<p>That&#8217;s only <em>mostly</em> a compliment, though.  This plug-in, like Visual Studio Code, doesn&#8217;t <em>really</em> understand Swift, it merely does a relatively good job of faking it.</p>



<p>Unlike every other plug-in tested, where the grammar parsing is completely independent of the theming, the performance of this plug-in <em>does</em> vary between themes.  Thus, some themes might have colours you hate yet be the only ones that actually identify Swift keywords correctly, while others are the reverse.  This is demonstrated in the example shown here &#8211; the <em>Light Plus</em> theme &#8211; where the colours are the least ugly of the themes available but it doesn&#8217;t recognise some basic Swift syntax, like protocol conformances, which <em>is</em> recognised in other &#8211; albeit uglier &#8211; themes.</p>



<p>But, in <em>general</em>, it:</p>



<ul class="wp-block-list">
<li>Actually understands the difference between function parameter labels, parameter names, and parameter types.</li>



<li>Tends not to recognise custom type names, only the Swift stdlib &amp; Foundation ones (e.g. notice it doesn&#8217;t recognise <code>Floor</code> but does recognise <code>String</code>).  This is somewhat common behaviour amongst the plug-ins tested (and Xcode itself).</li>



<li>Doesn&#8217;t recognise some important keywords, such as <code>async</code> and <code>some</code>.<br><br>As it happens, this is because the Swift grammar file it uses is quite a few years old and seems like it might be largely abandoned (other than sporadic community updates such as <a href="https://forums.swift.org/t/updated-syntax-highlighting-in-github-vs-code/68972" data-wpel-link="external" target="_blank" rel="external noopener">this</a> which might or might not be incorporated by this plug-in).  This is the same grammar file that Visual Studio Code uses, making it doubly-surprising, but I guess it says a lot about the level of interest the Visual Studio Code community has in Swift.</li>



<li>Is not easily fooled by the use of ambiguous names, e.g. the <code>default</code> static property of <code>HomeItem</code> that&#8217;s often mistaken for the <code>default</code> keyword by other plug-ins.</li>
</ul>



<h3 class="wp-block-heading">Pros</h3>



<ul class="wp-block-list">
<li>Includes the ability to highlight an arbitrary set of lines by blurring out all the others (but readers can mouse over the code block to unblur everything, if they want to see the full context of what you&#8217;re highlighting).  This particular approach &#8211; blurring rather than just using a different background colour &#8211; is unique amongst all the plug-ins I found, and aesthetically far superior.  Most of the other plug-ins don&#8217;t even have a way to highlight or hide certain lines.</li>



<li>Uses server-side rendering with CSS inlined into the HTML, so code is highlighted right from page load without delays or visual glitches.<br><br>Some other plug-ins tested here do server-side syntax analysis too, but to actually effect styling they use class tagging of HTML <code>span</code>s with CSS, which can mean rendering glitches if the CSS takes a while to load and the browser renders the code without it in the interim.  Code Block Pro avoids that (and might also play better with other styling plug-ins or modifications, such as dark mode plug-ins).</li>



<li>Has a <a href="https://code-block-pro.com/themes?theme=andromeda&amp;lang=swift" data-wpel-link="external" target="_blank" rel="external noopener">live playground</a> so you can easily test it out (although that playground is hard-coded to use the Fira Code font, which is only one of a number of open-source font options it provides).</li>
</ul>



<h3 class="wp-block-heading">Cons</h3>



<ul class="wp-block-list">
<li>No global settings &#8211; if you decide to change <em>any</em> settings, such as the theme, at any point, you have to manually find and adjust every existing code snippet manually.<br><br>This might be considered a positive by some users, where they want existing content to remain as-is.  However, some plug-ins offer both a global setting <em>and</em> the ability to override that on a per-case basis, providing more flexibility.</li>



<li>The provided themes &#8211; even with the paid expansion pack &#8211; are predominately intended only for dark mode, and most of the light mode ones are pastel.  So if you want a clean light mode theme, as I do, you have only about three options with this plug-in.<br><br>Furthermore, the performance varies between themes, as &#8211; unlike every other plug-in tested here &#8211; the themes are in essence tied into the parsing.<br><br>None of the provided themes really do Swift justice compared to how well they work for other languages.  Especially within the limited selection of light-mode themes, there&#8217;s precious few that don&#8217;t make obvious mistakes (like conflating the <code>some</code> keyword with operators, or being confounded by generics syntax).</li>



<li>Theme customisation options are extremely limited, not just officially but even unofficially with custom CSS.  Although, <a href="https://github.com/KevinBatdorf/code-block-pro/issues/270#issuecomment-1820896240" data-wpel-link="external" target="_blank" rel="external noopener">the author seems receptive to theme suggestions</a> &#8211; to add to the <em>paid</em> expansion pack &#8211; if you find something you like in the <a href="https://marketplace.visualstudio.com/search?target=VSCode&amp;category=Themes&amp;sortBy=Installs" data-wpel-link="external" target="_blank" rel="external noopener">Visual Studio Code Marketplace</a>.
<ul class="wp-block-list">
<li>The only way it officially allows any custom theming is with an unusual mechanism documented only in <a href="https://github.com/KevinBatdorf/code-block-pro/discussions/168" data-wpel-link="external" target="_blank" rel="external noopener">a tangential GitHub discussion</a>: you select the theme called &#8220;Use CSS Variables&#8221;, which is a &#8216;theme&#8217; that merely specifies <code>var(--xyz)</code> values for the <code>color</code> CSS property.  You&#8217;re then expected to specify values for those CSS variables in some suitable stylesheet (which the plug-in does <em>not</em> facilitate).<br><br>This custom theming functionality is only available in the paid version.</li>



<li>It only officially supports adjusting the colours &#8211; you nominally don&#8217;t have the ability to adjust font families, sizes, weights, or styles.<br><br>It is <em>possible</em> to match each type of element, but it&#8217;s pretty clumsy and fragile, because…</li>



<li>As mentioned under <em>Pros</em>, it inlines the style information directly into the HTML <code>span</code> tags, as simple <code>color</code> style attributes.  While that&#8217;s good for avoiding rendering glitches, the downsides are that:
<ul class="wp-block-list">
<li>It produces more verbose HTML than if it just used a short class name on the <code>span</code>s (as all the other plug-ins do), which can hurt page load times.</li>



<li>It&#8217;s more difficult to customise the styling with CSS, since you have to match on the colours &#8211; using CSS attribute queries like <code>span[style*=#xxyyzz]</code> &#8211; which is not just awkward but can be impossible to do precisely for multiple distinct grammar elements depending on the base theme used.</li>



<li>It optimises the HTML by merging (server-side) <code>span</code> elements with the same style information.  That&#8217;s great for reducing page size and load times, but if the base theme doesn&#8217;t already <em>visually</em> distinguish between two distinct grammar elements, it&#8217;s impossible to distinguish them through custom CSS.</li>
</ul>
</li>
</ul>
</li>



<li>Custom themes don&#8217;t render in the post editor &#8211; you just get plain pre-formatted text.  (built-in themes work fine in the editor)</li>



<li>Uses a custom Gutenberg block type, rather than just extending the standard Code block.  So you can&#8217;t just upgrade your whole existing site &#8211; you have to manually go through and find every existing Code block, and manually migrate each one.<br><br>Inversely it&#8217;ll also be more difficult to migrate away from, if you choose to do that some day, as you&#8217;ll likely have to repeat that whole process no matter what replacement plug-in you choose.</li>



<li>If you enable the &#8216;Copy&#8217; button for the convenience of your readers, it includes a duplicate copy of the code in a hidden <code>span</code> (as do at least some of the other plug-ins tested, although I didn&#8217;t always call it out here).</li>
</ul>



<p>So in a nutshell, if you&#8217;re completely happy with its built-in theme options, then this is one of your better options.  But if you want theme customisation, it becomes <em>worse</em> than many of the other plug-ins, sadly.</p>



<h2 class="wp-block-heading"><a href="https://wordpress.org/plugins/codecolorer/" data-wpel-link="external" target="_blank" rel="external noopener">CodeColorer</a></h2>



<div class="alignnormal"><div id="metaslider-id-7047" style="max-width: 435px;" class="ml-slider-3-107-0 metaslider metaslider-flex metaslider-7047 ml-slider ms-theme-default nav-hidden nav-hidden nav-hidden nav-hidden" role="region" aria-label="Syntax highlighting: CodeColorer [Slush &amp; Poppies]" data-height="300" data-width="435">
    <div id="metaslider_container_7047">
        <div id="metaslider_7047" class="flexslider">
            <ul class='slides'>
                <li style="display: block; width: 100%;" class="slide-7053 ms-image " aria-roledescription="slide" data-date="2023-12-29 10:32:25" data-filename="CodeColorer-Slush-Poppies-Light.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="870" height="600" src="https://wadetregaskis.com/wp-content/uploads/2023/12/CodeColorer-Slush-Poppies-Light.webp" class="slider-7047 slide-7053 msDefaultImage" alt="" rel="" title="CodeColorer [Slush &amp; Poppies] (Light)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/CodeColorer-Slush-Poppies-Light.webp 870w, https://wadetregaskis.com/wp-content/uploads/2023/12/CodeColorer-Slush-Poppies-Light-256x177.webp 256w, https://wadetregaskis.com/wp-content/uploads/2023/12/CodeColorer-Slush-Poppies-Light-512x353.webp 512w" sizes="auto, (max-width: 870px) 100vw, 870px" /><div class="caption-wrap"><div class="caption">Light mode</div></div></li>
                <li style="display: none; width: 100%;" class="slide-7052 ms-image " aria-roledescription="slide" data-date="2023-12-29 10:32:24" data-filename="CodeColorer-Slush-Poppies-Dark.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="870" height="600" src="https://wadetregaskis.com/wp-content/uploads/2023/12/CodeColorer-Slush-Poppies-Dark.webp" class="slider-7047 slide-7052 msDefaultImage" alt="" rel="" title="CodeColorer [Slush &amp; Poppies] (Dark)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/CodeColorer-Slush-Poppies-Dark.webp 870w, https://wadetregaskis.com/wp-content/uploads/2023/12/CodeColorer-Slush-Poppies-Dark-256x177.webp 256w, https://wadetregaskis.com/wp-content/uploads/2023/12/CodeColorer-Slush-Poppies-Dark-512x353.webp 512w" sizes="auto, (max-width: 870px) 100vw, 870px" /><div class="caption-wrap"><div class="caption">Dark mode</div></div></li>
            </ul>
        </div>
        
    </div>
</div></div>



<p>A <em>very</em> old &#8211; though nominally still maintained &#8211; plug-in uniquely based on GeSHi.</p>



<p>It&#8217;s <a href="https://github.com/kpumuk/codecolorer/" data-wpel-link="external" target="_blank" rel="external noopener">open source</a> and free (as is the <a href="https://github.com/GeSHi/geshi-1.0" data-wpel-link="external" target="_blank" rel="external noopener">GeSHi</a> engine underneath it).</p>



<p>Neither the plug-in itself nor the GeSHi engine have seen a lot of activity in recent years (and confusingly <a href="http://qbnz.com/highlighter/" data-wpel-link="external" target="_blank" rel="external noopener">the old GeSHi webpage</a> is still up as is <a href="https://sourceforge.net/projects/geshi/" data-wpel-link="external" target="_blank" rel="external noopener">the early GeSHi page on SourceForge</a>, creating an even worse first impression).  Both predate the [public] existence of Swift entirely.</p>



<p>To be honest I&#8217;m including it here only for completeness.  It basically doesn&#8217;t work &#8211; especially for Swift &#8211; and shouldn&#8217;t actually be considered.  It seems intended <em>solely</em> for use via shortcodes &#8211; even though it does take over all existing <code>&lt;code&gt;</code> blocks &#8211; which I didn&#8217;t test as the use of shortcodes in WordPress is archaic, and poorly supported in the modern (Gutenberg) editor.  <a href="https://wordpress.com/support/wordpress-editor/blocks/shortcode-block/" data-wpel-link="external" target="_blank" rel="external noopener">They <em>seem</em> to still be officially supported</a>, and not formally deprecated, but I think introducing any new reliance on them at this point is foolish.</p>



<h3 class="wp-block-heading">Performance</h3>



<p>So, yeah… no syntax highlighting at all.  It&#8217;s not apparent to me if this is a failure specific to Swift or if the plug-in in general just doesn&#8217;t work.  It does offer a [non-live] preview in its settings, which does work for its example snippet of JavaScript.</p>



<p>It also (by default) forces the code into a tiny box, although you can fix this through its settings.</p>



<p>There&#8217;s no per-use customisation since it just takes over any existing <code>&lt;code&gt;</code> blocks, and there&#8217;s very few global settings &#8211; including an absence of any setting for a default language.</p>



<p>I won&#8217;t bother trying to enumerate its specific pros and cons &#8211; it&#8217;s clearly not a viable contender.</p>



<h2 class="wp-block-heading" id="code-syntax-block"><a href="https://wordpress.org/plugins/code-syntax-block/" data-wpel-link="external" target="_blank" rel="external noopener">Code Syntax Block</a></h2>



<div class="alignnormal"><div id="metaslider-id-6738" style="max-width: 594px;" class="ml-slider-3-107-0 metaslider metaslider-flex metaslider-6738 ml-slider ms-theme-default nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden" role="region" aria-label="Syntax highlighting: Code Syntax Block [GitHub (Light)]" data-height="1158" data-width="594">
    <div id="metaslider_container_6738">
        <div id="metaslider_6738" class="flexslider">
            <ul class='slides'>
                <li style="display: block; width: 100%;" class="slide-6741 ms-image " aria-roledescription="slide" data-date="2023-12-15 21:44:10" data-filename="Code-Syntax-Block-GitHub-Light-Light.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="1188" height="2316" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Light.webp" class="slider-6738 slide-6741 msDefaultImage" alt="" rel="" title="Code Syntax Block [GitHub (Light)] (Light)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Light.webp 1188w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Light-131x256.webp 131w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Light-525x1024.webp 525w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Light-1051x2048.webp 1051w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Light-263x512.webp 263w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Light-131x256@2x.webp 262w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Light-525x1024@2x.webp 1050w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Light-263x512@2x.webp 526w" sizes="auto, (max-width: 1188px) 100vw, 1188px" /><div class="caption-wrap"><div class="caption">Light mode</div></div></li>
                <li style="display: none; width: 100%;" class="slide-6742 ms-image " aria-roledescription="slide" data-date="2023-12-15 21:44:10" data-filename="Code-Syntax-Block-GitHub-Light-Dark.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="1188" height="2316" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Dark.webp" class="slider-6738 slide-6742 msDefaultImage" alt="" rel="" title="Code Syntax Block [GitHub (Light)] (Dark)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Dark.webp 1188w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Dark-131x256.webp 131w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Dark-525x1024.webp 525w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Dark-1051x2048.webp 1051w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Dark-263x512.webp 263w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Dark-131x256@2x.webp 262w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Dark-525x1024@2x.webp 1050w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Syntax-Block-GitHub-Light-Dark-263x512@2x.webp 526w" sizes="auto, (max-width: 1188px) 100vw, 1188px" /><div class="caption-wrap"><div class="caption">Dark mode</div></div></li>
            </ul>
        </div>
        
    </div>
</div></div>



<p>A simple plug-in based on <a href="https://prismjs.com" data-wpel-link="external" target="_blank" rel="external noopener">Prism.js</a>, with very limited customisation options.</p>



<p>It&#8217;s <a href="https://github.com/mkaz/code-syntax-block" data-wpel-link="external" target="_blank" rel="external noopener">open source</a> and free (as is the <a href="https://github.com/PrismJS/prism" data-wpel-link="external" target="_blank" rel="external noopener">Prism.js</a> engine underneath it).</p>



<h3 class="wp-block-heading">Performance</h3>



<p>Prism.js prides itself on being [relatively] small.  Perhaps because of that goal of being &#8220;lightweight&#8221;, its performance is a bit mediocre.</p>



<p>The default theme makes it look even worse than it really is, because it bizarrely doesn&#8217;t provide any distinguishing styling for important things, like type names.</p>



<p>On the upside, it does get a few things right which other plug-ins often don&#8217;t &#8211; even others which also use Prism.js, curiously, like <a href="#highlighting-code-block">Highlighting Code Block</a>.  Things like it:</p>



<ul class="wp-block-list">
<li>Recognises @-attributes, such as macro and property wrapper invocations.</li>



<li>Recognises relatively new Swift keywords such as <code>async</code> &amp; <code>await</code>.</li>



<li>Understands multi-line and raw strings.</li>
</ul>



<p>On the downside it:</p>



<ul class="wp-block-list">
<li>Doesn&#8217;t recognise a <em>lot</em> of very basic Swift syntax &#8211; or, at least, doesn&#8217;t distinguish them with a <code>span</code> and therefore resigns them to the default, plain text styling of the overall <code>code</code> block &#8211; including but not limited to:
<ul class="wp-block-list">
<li>Variable names (neither their declaration nor references to them).</li>



<li>Function parameter labels &amp; names.</li>



<li>Property names.</li>



<li>Tuple field labels.</li>
</ul>
</li>



<li>Doesn&#8217;t recognise method calls consistently (e.g. <code>pack</code> &amp; <code>reduce</code> vs <code>map</code> in the example shown).</li>
</ul>



<p>Although you can&#8217;t tell with its default theme, it actually recognises custom type names (although doesn&#8217;t distinguish them from Swift standard library types, like Xcode &#8211; though it&#8217;s debatable whether that&#8217;s a feature).</p>



<p>It uses font weight, not just colour, which <em>would</em> go a long way towards giving it higher fidelity without making it look garish <em>if</em> it didn&#8217;t use it really weirdly.  Instead of bolding keywords, for example, it bolds function &amp; method names &#8211; sometimes, when it recognises them correctly.</p>



<p>At least it defaults to Menlo, which is actually a respectable choice and makes it one of the few plug-ins tested that have a decent default for Apple platforms.  In case you&#8217;re unfamiliar, <a href="https://en.wikipedia.org/wiki/Menlo_(typeface)" data-wpel-link="external" target="_blank" rel="external noopener">Menlo</a> was the default monospace font for Snow Leopard through Yosemite (before it was replaced by SF Mono).  You&#8217;d most likely have encountered it in Terminal or Xcode, if you used a Mac in that timeframe (2009 &#8211; 2015).  It&#8217;s still available on every Apple device (as of time of writing, December 2023).</p>



<h3 class="wp-block-heading">Pros</h3>



<ul class="wp-block-list">
<li>Extends the built-in, standard Code block.  This makes it comparatively trivial to adopt if you&#8217;ve already got Code blocks on your website (although you may still need to go through and customise some things, such as the language in case auto-detection doesn&#8217;t work correctly).<br><br>This also makes it easier to switch syntax-highlighting plug-ins, <em>provided</em> that the one you switch from or to also supports the standard Code block, which is sadly a minority of them.</li>
</ul>



<h3 class="wp-block-heading">Cons</h3>



<ul class="wp-block-list">
<li>Hasn&#8217;t been updated in a year &#8211; possibly abandoned.</li>



<li>Does everything client-side, so there&#8217;s a noticeable delay before syntax highlighting is actually applied (especially on first load, when the relevant JavaScript &amp; CSS isn&#8217;t cached in the browser).  It&#8217;s a bit visually jarring as the unstyled code is replaced with the styled.</li>



<li>Adds its Prism CSS &amp; JavaScript files to <em>every</em> page load, irrespective of whether the page actually needs them or not.  This is the core Prism.js library only &#8211; the grammar file for each language is only loaded when actually needed.<br><br>They are somewhat small files, at least &#8211; most of it is Prism.js at 30 KB alone, plus a few extra KBs for the chosen theme&#8217;s CSS.  With Brotli compression they&#8217;re ~13 KB.  Language grammar files tend to be only 3 KB or less.</li>



<li>Very few built-in themes &#8211; only four &#8211; and using a custom theme is technically possible but awkward.  <a href="https://github.com/mkaz/code-syntax-block" data-wpel-link="external" target="_blank" rel="external noopener">The official instructions</a> didn&#8217;t work for me, either &#8211; I had to use the <a href="https://wpcode.com" data-wpel-link="external" target="_blank" rel="external noopener">WPCode</a> plug-in to execute the relevant PHP:<br><br><code>add_filter('mkaz_prism_css_url', function() {</code><br><code>&nbsp;&nbsp;&nbsp;&nbsp;return '/wp-content/themes/prism-xcode.css';<br>});</code></li>



<li>Theming is controlled globally with no ability to override it for specific uses.<br><br>This is (IMO) better than not having any global controls at all, as with some plug-ins, but it can be problematic if you use more than one language in these code blocks across your website, as you might prefer different themes for different languages.<br><br>You can technically work around this limitation using custom CSS, since the language is included as a class on the relevant <code>pre</code> and <code>code</code> HTML elements.</li>



<li>Doesn&#8217;t render the syntax highlighting in the Gutenberg editor, so you&#8217;re stuck with the generic <code>pre</code> appearance there.</li>
</ul>



<h2 class="wp-block-heading"><a href="https://wordpress.org/plugins/enlighter/" data-wpel-link="external" target="_blank" rel="external noopener">Enlighter</a></h2>



<div class="alignnormal"><div id="metaslider-id-6694" style="max-width: 473px;" class="ml-slider-3-107-0 metaslider metaslider-flex metaslider-6694 ml-slider ms-theme-default nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden" role="region" aria-label="Syntax highlighting: Enlighter [Default]" data-height="1023" data-width="473">
    <div id="metaslider_container_6694">
        <div id="metaslider_6694" class="flexslider">
            <ul class='slides'>
                <li style="display: block; width: 100%;" class="slide-6697 ms-image " aria-roledescription="slide" data-date="2023-12-13 21:31:57" data-filename="Enlighter-Default-theme-Light.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="946" height="2046" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Enlighter-Default-theme-Light.webp" class="slider-6694 slide-6697 msDefaultImage" alt="" rel="" title="Enlighter [Default theme] (Light)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Enlighter-Default-theme-Light-473x1024@2x.webp 946w, https://wadetregaskis.com/wp-content/uploads/2023/12/Enlighter-Default-theme-Light-473x1024.webp 473w, https://wadetregaskis.com/wp-content/uploads/2023/12/Enlighter-Default-theme-Light-118x256.webp 118w, https://wadetregaskis.com/wp-content/uploads/2023/12/Enlighter-Default-theme-Light-237x512.webp 237w, https://wadetregaskis.com/wp-content/uploads/2023/12/Enlighter-Default-theme-Light-118x256@2x.webp 236w, https://wadetregaskis.com/wp-content/uploads/2023/12/Enlighter-Default-theme-Light-237x512@2x.webp 474w" sizes="auto, (max-width: 946px) 100vw, 946px" /><div class="caption-wrap"><div class="caption">Light mode</div></div></li>
                <li style="display: none; width: 100%;" class="slide-6698 ms-image " aria-roledescription="slide" data-date="2023-12-13 21:31:58" data-filename="Enlighter-Default-theme-Dark.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="946" height="2046" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Enlighter-Default-theme-Dark.webp" class="slider-6694 slide-6698 msDefaultImage" alt="" rel="" title="Enlighter [Default theme] (Dark)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Enlighter-Default-theme-Dark-473x1024@2x.webp 946w, https://wadetregaskis.com/wp-content/uploads/2023/12/Enlighter-Default-theme-Dark-473x1024.webp 473w, https://wadetregaskis.com/wp-content/uploads/2023/12/Enlighter-Default-theme-Dark-118x256.webp 118w, https://wadetregaskis.com/wp-content/uploads/2023/12/Enlighter-Default-theme-Dark-237x512.webp 237w, https://wadetregaskis.com/wp-content/uploads/2023/12/Enlighter-Default-theme-Dark-118x256@2x.webp 236w, https://wadetregaskis.com/wp-content/uploads/2023/12/Enlighter-Default-theme-Dark-237x512@2x.webp 474w" sizes="auto, (max-width: 946px) 100vw, 946px" /><div class="caption-wrap"><div class="caption">Dark mode</div></div></li>
            </ul>
        </div>
        
    </div>
</div></div>



<p>The official WordPress plug-in for the <a href="https://enlighterjs.org/" data-wpel-link="external" target="_blank" rel="external noopener">EnlighterJS</a> engine.</p>



<p>It&#8217;s <a href="https://github.com/EnlighterJS/Plugin.WordPress" data-wpel-link="external" target="_blank" rel="external noopener">open source</a> and free (as is the <a href="https://github.com/EnlighterJS/EnlighterJS" data-wpel-link="external" target="_blank" rel="external noopener">EnlighterJS</a> engine underneath it).</p>



<h3 class="wp-block-heading">Performance</h3>



<p>Generally it does a poor job, with Swift code, and it&#8217;s not really a mystery why &#8211; <a href="https://github.com/EnlighterJS/EnlighterJS/blob/a0e3a9be4b6a09a5506567fc18f456a177eeed31/src/lang/swift.js" data-wpel-link="external" target="_blank" rel="external noopener">its grammar file for Swift</a> is <em>especially</em> spartan and hasn&#8217;t been updated since it was created over five years ago!  That&#8217;s the Swift 4.1 era at best.</p>



<p>It actually behaves very similarly to the <a href="#syntaxhighlighter-evolved" data-type="internal" data-id="#syntaxhighlighter-evolved">SyntaxHighlighter Evolved</a> plug-in, but with the significant difference that it leaves things it doesn&#8217;t understand as the plain text colour (e.g. black in Light mode), so it&#8217;s <em>much</em> more apparent even at a glance that it doesn&#8217;t really understand much.</p>



<p>For example, it:</p>



<ul class="wp-block-list">
<li>Doesn&#8217;t understand @-attributes, such as macro and property wrapper invocations.</li>



<li>Has no idea about the difference between function parameter labels and parameter arguments.</li>



<li>Doesn&#8217;t consistently recognise references to properties, such as when they&#8217;re part of KeyPaths.</li>



<li>Doesn&#8217;t understand some important keywords, like <code>async</code>, <code>await</code>, <code>Never</code>, etc.</li>



<li>Recognises <em>only</em> a limited selection of types &#8211; all from the Swift standard library &#8211; and has no idea about custom types.</li>



<li>Doesn&#8217;t recognise method calls consistently (e.g. <code>pack</code> &amp; <code>reduce</code> vs <code>map</code> in the example shown).</li>
</ul>



<p>In a nutshell, it&#8217;s doing little more than picking out a pre-defined list of keywords, identifying string &amp; numeric literals, and comments.</p>



<p>Though it does at least handle multi-line and raw strings correctly (albeit only in some themes &#8211; in a few it underlines strings and mistakes the indentation as part of the string, for multi-line strings).</p>



<p>The choice of Courier New as the default font is… brave.  It&#8217;s not actually its preferred default &#8211; it favours Source Code Pro foremost, with Liberation Mono as a second choice.  They&#8217;re both reasonable open-source monospace fonts, but neither are standard fonts on any Apple devices, and the plug-in doesn&#8217;t include them.</p>



<p>You can customise the font to a very limited degree &#8211; the plug-in provides only five options, none of which are standard Apple OS fonts so the choice is effectively pointless.  Thankfully you can override its font choices, like pretty much all its styling, with custom CSS.</p>



<h3 class="wp-block-heading">Pros</h3>



<ul class="wp-block-list">
<li>Supports both a global theme setting as well as use-specific overrides.</li>



<li>Supports both soft &amp; hard wrapping (the latter meaning it uses a horizontal scroller if necessary, rather than fitting the text to the viewport &#8211; generally not what I recommend since it&#8217;s pretty hostile to small screens but it&#8217;s a notable feature to make this behaviour configurable).</li>



<li>Includes a pretty extensive theme customiser, as an actual HTML forms-style interface in the plug-in settings pages.  That GUI is ultimately just a bespoke configurator for the CSS &#8211; which helpfully it also provides, in case you want to save or serve that elsewhere.<br><br>And if that proves insufficient &#8211; or you just prefer to do it manually &#8211; it uses a sensible system of spans with suitable classes, so it&#8217;s easy to write custom CSS for styling.</li>



<li>Provides its own Gutenberg block, but can also optionally be applied to the built-in WordPress Code block, as well as potentially blocks from other plug-ins (<a href="https://github.com/aramk/crayon-syntax-highlighter" data-wpel-link="external" target="_blank" rel="external noopener">Crayon Syntax Highlighter</a> &amp; <a href="https://wordpress.org/plugins/codecolorer/" data-wpel-link="external" target="_blank" rel="external noopener">CodeColorer</a> are explicitly supported &#8211; unclear if it also supports <a href="https://wordpress.org/plugins/urvanov-syntax-highlighter/" data-wpel-link="external" target="_blank" rel="external noopener">Urvanov Syntax Highlighter</a>, the &#8216;reincarnation&#8217; of the otherwise abandoned Crayon Syntax Highlighter).</li>
</ul>



<h3 class="wp-block-heading">Cons</h3>



<ul class="wp-block-list">
<li>Built-in themes are pretty limited and (IMO) pretty ugly, at least for the light-style ones (which is ten of the thirteen).  The one demonstrated here is the default &#8211; just called &#8220;Enlighter&#8221; &#8211; which is about the best it has to offer. 😕</li>



<li>Puts its settings item at the top level of the WordPress admin menu, rather than under Settings.</li>



<li>Adds its CSS &amp; JavaScript files to <em>every</em> page load, irrespective of whether the page actually uses the Enlighter block or not.  Along with some inline JavaScript in every page header.<br><br>And they&#8217;re not trivial files, either.  The CSS is 80 KB uncompressed &#8211; ~10 KB with Brotli compression, larger with GZip or Zip (Deflate).  That&#8217;s factoring in CSS minification, too.  The JavaScript is 63 KB uncompressed (~19 KB with Brotli).<br><br>It does offer an option to supposedly avoid this &#8211; &#8220;Dynamic Resource Invocation&#8221; &#8211; but it&#8217;s disabled by default, and still requires inclusion of a &#8220;small&#8221; 1 KB JavaScript file with every page load just to determine if the rest of the code &amp; CSS should be loaded.  So, kind of a hack to try to cover up a design flaw.  Alternatively, you can disable automatic inclusion of the CSS &amp; JavaScript files and handle that manually, but I can&#8217;t imagine anyone actually <em>wants</em> to have to deal with that.</li>



<li>Doesn&#8217;t render the syntax highlighting in the Gutenberg editor, so you&#8217;re stuck with the generic <code>pre</code> appearance there.</li>
</ul>



<p>So, overall a pretty poor option, both in terms of how well it understands Swift &#8211; i.e. <em>particularly</em> badly &#8211; and how it looks out of the box.  It does have a lot more options than most of the other plug-ins, and its GUI for theme editing <em>might</em> be a unique selling point for a &#8211; presumably rather limited &#8211; market of people that want to include Swift code on their website but aren&#8217;t comfortable writing CSS.  Even that withstanding for argument&#8217;s sake, I think it falls solidly towards the bottom of the pile.</p>



<h2 class="wp-block-heading" id="highlighting-code-block"><a href="https://wordpress.org/plugins/highlighting-code-block/" data-wpel-link="external" target="_blank" rel="external noopener">Highlighting Code Block</a></h2>



<div class="alignnormal"><div id="metaslider-id-6707" style="max-width: 564px;" class="ml-slider-3-107-0 metaslider metaslider-flex metaslider-6707 ml-slider ms-theme-default nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden" role="region" aria-label="Syntax highlighting: Highlighting Code Block [Light]" data-height="1347" data-width="564">
    <div id="metaslider_container_6707">
        <div id="metaslider_6707" class="flexslider">
            <ul class='slides'>
                <li style="display: block; width: 100%;" class="slide-6710 ms-image " aria-roledescription="slide" data-date="2023-12-14 10:51:28" data-filename="Highlighting-Code-Block-Light-Light.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="1128" height="2694" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Highlighting-Code-Block-Light-Light.webp" class="slider-6707 slide-6710 msDefaultImage" alt="" rel="" title="Highlighting Code Block [Light] (Light)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Highlighting-Code-Block-Light-Light.webp 1128w, https://wadetregaskis.com/wp-content/uploads/2023/12/Highlighting-Code-Block-Light-Light-107x256.webp 107w, https://wadetregaskis.com/wp-content/uploads/2023/12/Highlighting-Code-Block-Light-Light-429x1024.webp 429w, https://wadetregaskis.com/wp-content/uploads/2023/12/Highlighting-Code-Block-Light-Light-858x2048.webp 858w, https://wadetregaskis.com/wp-content/uploads/2023/12/Highlighting-Code-Block-Light-Light-214x512.webp 214w, https://wadetregaskis.com/wp-content/uploads/2023/12/Highlighting-Code-Block-Light-Light-214x512@2x.webp 428w" sizes="auto, (max-width: 1128px) 100vw, 1128px" /><div class="caption-wrap"><div class="caption">Light mode</div></div></li>
                <li style="display: none; width: 100%;" class="slide-6711 ms-image " aria-roledescription="slide" data-date="2023-12-14 10:51:29" data-filename="Highlighting-Code-Block-Light-Dark.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="1128" height="2694" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Highlighting-Code-Block-Light-Dark.webp" class="slider-6707 slide-6711 msDefaultImage" alt="" rel="" title="Highlighting Code Block [Light] (Dark)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Highlighting-Code-Block-Light-Dark.webp 1128w, https://wadetregaskis.com/wp-content/uploads/2023/12/Highlighting-Code-Block-Light-Dark-107x256.webp 107w, https://wadetregaskis.com/wp-content/uploads/2023/12/Highlighting-Code-Block-Light-Dark-429x1024.webp 429w, https://wadetregaskis.com/wp-content/uploads/2023/12/Highlighting-Code-Block-Light-Dark-858x2048.webp 858w, https://wadetregaskis.com/wp-content/uploads/2023/12/Highlighting-Code-Block-Light-Dark-214x512.webp 214w, https://wadetregaskis.com/wp-content/uploads/2023/12/Highlighting-Code-Block-Light-Dark-214x512@2x.webp 428w" sizes="auto, (max-width: 1128px) 100vw, 1128px" /><div class="caption-wrap"><div class="caption">Dark mode</div></div></li>
            </ul>
        </div>
        
    </div>
</div></div>



<p>A relatively simple plug-in based on <a href="https://prismjs.com" data-wpel-link="external" target="_blank" rel="external noopener">Prism.js</a>, with limited customisation options.</p>



<p>It&#8217;s <a href="https://github.com/ddryo/Highlighting-Code-Block" data-wpel-link="external" target="_blank" rel="external noopener">open source</a> and free (as is the <a href="https://github.com/PrismJS/prism" data-wpel-link="external" target="_blank" rel="external noopener">Prism.js</a> engine underneath it).</p>



<h3 class="wp-block-heading">Performance</h3>



<p>Prism.js prides itself on being [relatively] small.  Perhaps because of that goal of being &#8220;lightweight&#8221;, its performance is pretty poor &#8211; and pretty obviously so even at just a glance.</p>



<p>For example, it:</p>



<ul class="wp-block-list">
<li>Doesn&#8217;t understand @-attributes, such as macro and property wrapper invocations.</li>



<li>Has no idea about the difference between function parameter labels and parameter arguments.</li>



<li>Doesn&#8217;t consistently recognise references to properties, such as when they&#8217;re part of KeyPaths.</li>



<li>Doesn&#8217;t understand some important keywords, like <code>async</code> &amp; <code>await</code>.</li>



<li>Doesn&#8217;t recognise method calls consistently (e.g. <code>pack</code> &amp; <code>reduce</code> vs <code>map</code> in the example shown).</li>



<li>Doesn&#8217;t understand multi-line nor raw strings.</li>
</ul>



<p>On the positive side, it actually recognises custom type names (although doesn&#8217;t distinguish them from Swift standard library types, like Xcode &#8211; though it&#8217;s debatable whether that&#8217;s a feature).</p>



<p>It uses italics, not just colour, which goes a long way towards giving it higher fidelity without making it look garish.  Unfortunately, its use of italics is weirdly inconsistent &#8211; e.g. it italicises <em>some</em> keywords but not all (e.g. <code>final</code> vs <code><em>class</em></code>), and italicises <em>some</em> type names but not others (e.g. <code><em>VStack</em></code> vs <code>Image</code> &amp; <code>Text</code>).</p>



<p>It doesn&#8217;t take much effort to understand why &#8211; it&#8217;s using a <em>very</em> simplistic parser that knows virtually nothing about the language (other than a hard-coded list of keywords) and instead is just going off of capitalisation, mostly.  Which is somewhat clever, and gets it a long way for such a simple method, but ultimately results in poor performance.</p>



<p>At least it defaults to Menlo, which is actually a respectable choice and makes it one of the few plug-ins tested that have a decent default for Apple platforms.  In case you&#8217;re unfamiliar, <a href="https://en.wikipedia.org/wiki/Menlo_(typeface)" data-wpel-link="external" target="_blank" rel="external noopener">Menlo</a> was the default monospace font for Snow Leopard through Yosemite (before it was replaced by SF Mono).  You&#8217;d most likely have encountered it in Terminal or Xcode, if you used a Mac in that timeframe (2009 &#8211; 2015).  It&#8217;s still available on every Apple device (as of time of writing, December 2023).</p>



<p>It&#8217;s a bit weird that the performance is significantly different from some other Prism.js-based plug-ins, like <a href="#code-syntax-block">Code Syntax Block</a>.  It&#8217;d be explicable if one plug-in were strictly superior to the other &#8211; suggesting simply use of a newer version of Prism.js by one than the other &#8211; but it&#8217;s actually a weird mix of improvements and regressions.</p>



<h3 class="wp-block-heading">Pros</h3>



<ul class="wp-block-list">
<li>Good bang-for-your-buck configuration options, which is to say that it has relatively few but it includes the essentials and with maximum flexibility (e.g. font customisation is by entering the actual <code>font-family</code> CSS string, rather than being limited to do a predefined short list of options as with most other plug-ins).</li>
</ul>



<h3 class="wp-block-heading">Cons</h3>



<ul class="wp-block-list">
<li>Does everything client-side, so there&#8217;s a noticeable delay before syntax highlighting is actually applied (especially on first load, when the relevant JavaScript &amp; CSS isn&#8217;t cached in the browser).  It&#8217;s a bit visually jarring as the unstyled code is replaced with the styled.</li>



<li>Adds its CSS &amp; JavaScript files to <em>every</em> page load, plus some inline CSS &amp; JavaScript, irrespective of whether the page actually needs it or not.  This includes the entire Prism.js library with grammar parsers for every supported language, irrespective of which ones are actually used.<br><br>And they&#8217;re not entirely trivial files, either &#8211; mainly because of Prism.js at 35 KB alone.  Overall they&#8217;re 41 KB before compression (~18 KB with Brotli).</li>



<li>Limited theming control &#8211; it has an unnamed built-in default, which you can override by specifying a server-side path to a custom CSS file (although functionally this isn&#8217;t much different from just putting your custom CSS in your website&#8217;s general custom CSS file, because of the aforementioned flaw whereby this plug-in inserts its CSS into <em>every</em> page load).</li>



<li>Theming is controlled globally with no ability to override it for specific uses.<br><br>This is (IMO) better than not having any global controls at all, as with some plug-ins, but it can be problematic if you use more than one language in these code blocks across your website, as you might prefer different themes for different languages.<br><br>You can technically work around this limitation using custom CSS, since the language is included as a class on the relevant <code>pre</code> and <code>code</code> HTML elements.</li>



<li>Includes support for a relatively small number of languages (by default), although that does include Swift and Objective-C, among many other popular languages.  I list this as &#8216;con&#8217; only in a relative sense &#8211; for most users its built-in shortlist is likely quite sufficient.<br><br>You can provide a custom build of Prism.js if you need others, although it&#8217;s left as an exercise to the user to figure out how to do that (and to then maintain it).</li>



<li>Doesn&#8217;t render the syntax highlighting in the Gutenberg editor, so you&#8217;re stuck with the generic <code>pre</code> appearance there.</li>



<li>Uses a custom Gutenberg block type, rather than just extending the standard Code block.  So you can&#8217;t just upgrade your whole existing site &#8211; you have to manually go through and find every existing Code block, and manually migrate each one.<br><br>Inversely it&#8217;ll also be more difficult to migrate away from, if you choose to do that some day, as you&#8217;ll likely have to repeat that whole process no matter what replacement plug-in you choose.</li>
</ul>



<h2 class="wp-block-heading"><a href="https://wordpress.org/plugins/prismatic/" data-wpel-link="external" target="_blank" rel="external noopener">Prismatic</a></h2>



<p>A uniquely versatile plug-in that supports both the <a href="https://prismjs.com" data-wpel-link="external" target="_blank" rel="external noopener">Prism.js</a> and <a href="https://highlightjs.org" data-wpel-link="external" target="_blank" rel="external noopener">highlight.js</a> engines.</p>



<p>It&#8217;s <a href="https://plugins.svn.wordpress.org/prismatic/" data-wpel-link="external" target="_blank" rel="external noopener">open source</a> and free (as are the <a href="https://github.com/PrismJS/prism" data-wpel-link="external" target="_blank" rel="external noopener">Prism.js</a> and <a href="https://github.com/highlightjs/highlight.js" data-wpel-link="external" target="_blank" rel="external noopener">highlight.js</a> engines underneath it).</p>



<p>Unfortunately, it immediately disqualified itself by simply not working.  After installing &amp; activating it in WordPress, nothing happens.  The built-in Code block doesn&#8217;t change, there is no new Gutenberg block (contrary to its documentation which claims it adds a &#8220;Prismatic&#8221; block), and nothing appears anywhere in the WordPress Admin menu, such as a global settings page.</p>



<p>I checked the PHP logs and found no mention of the plug-in nor any relevant log messages.</p>



<p>It&#8217;s unusual &#8211; in my experience &#8211; for a WordPress plug-in to just silently fail like this.  While it might be possible to enable WordPress debug logging and ultimately figure out what&#8217;s going on, in my experience first impressions are indicative when it comes to WordPress plug-ins, so I&#8217;m not going to spend time trying to get a plug-in to work at all when it&#8217;s probable it&#8217;ll have numerous other problems anyway.</p>



<h2 class="wp-block-heading"><a href="https://wordpress.org/plugins/syntax-highlighting-code-block/" data-wpel-link="external" target="_blank" rel="external noopener">Syntax-highlighting Code Block (with Server-side Rendering)</a></h2>



<div class="alignnormal"><div id="metaslider-id-6719" style="max-width: 412px;" class="ml-slider-3-107-0 metaslider metaslider-flex metaslider-6719 ml-slider ms-theme-default nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden" role="region" aria-label="Syntax highlighting: Syntax-highlighting Code Block (with Server-side Rendering) [Default]" data-height="1155" data-width="412">
    <div id="metaslider_container_6719">
        <div id="metaslider_6719" class="flexslider">
            <ul class='slides'>
                <li style="display: block; width: 100%;" class="slide-6722 ms-image " aria-roledescription="slide" data-date="2023-12-14 21:22:33" data-filename="Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Light.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="824" height="2310" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Light.webp" class="slider-6719 slide-6722 msDefaultImage" alt="" rel="" title="Syntax-highlighting Code Block (with Server-side Rendering) [Default] (Light)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Light.webp 824w, https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Light-365x1024.webp 365w, https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Light-731x2048.webp 731w, https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Light-91x256.webp 91w, https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Light-183x512.webp 183w, https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Light-365x1024@2x.webp 730w, https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Light-91x256@2x.webp 182w, https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Light-183x512@2x.webp 366w" sizes="auto, (max-width: 824px) 100vw, 824px" /><div class="caption-wrap"><div class="caption">Light mode</div></div></li>
                <li style="display: none; width: 100%;" class="slide-6723 ms-image " aria-roledescription="slide" data-date="2023-12-14 21:22:34" data-filename="Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Dark.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="824" height="2310" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Dark.webp" class="slider-6719 slide-6723 msDefaultImage" alt="" rel="" title="Syntax-highlighting Code Block (with Server-side Rendering) [Default] (Dark)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Dark.webp 824w, https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Dark-365x1024.webp 365w, https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Dark-731x2048.webp 731w, https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Dark-91x256.webp 91w, https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Dark-183x512.webp 183w, https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Dark-365x1024@2x.webp 730w, https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Dark-91x256@2x.webp 182w, https://wadetregaskis.com/wp-content/uploads/2023/12/Syntax-highlighting-Code-Block-with-Server-side-Rendering-Default-Dark-183x512@2x.webp 366w" sizes="auto, (max-width: 824px) 100vw, 824px" /><div class="caption-wrap"><div class="caption">Dark mode</div></div></li>
            </ul>
        </div>
        
    </div>
</div></div>



<p>Nominally a fork of <a href="#code-syntax-block">Code Syntax Block</a> that renders server-side instead of client-side, although it uses a different engine &#8211; <a href="https://github.com/scrivo/highlight.php" data-wpel-link="external" target="_blank" rel="external noopener">Highlight.php</a> instead of <a href="https://prismjs.com" data-wpel-link="external" target="_blank" rel="external noopener">Prism.js</a>.</p>



<p><a href="https://github.com/scrivo/highlight.php" data-wpel-link="external" target="_blank" rel="external noopener">highlight.php</a> is a PHP port of <a href="https://highlightjs.org" data-wpel-link="external" target="_blank" rel="external noopener">Highlight.js</a>.  It&#8217;s unclear to me how closely or promptly that tracks changes to the original JavaScript library.</p>



<p>It&#8217;s <a href="https://github.com/westonruter/syntax-highlighting-code-block" data-wpel-link="external" target="_blank" rel="external noopener">open source</a> and free (as is the highlight.php engine underneath it).</p>



<h3 class="wp-block-heading">Performance</h3>



<p>The default theme is particularly bland.  It&#8217;s actually hard to judge its understanding of Swift purely from its appearance since so much of it looks the same.</p>



<p>It&#8217;s noteworthy as a <em>particularly</em> hostile plug-in (with its default theme) for colourblind viewers, due to its use of <em>very</em> similar shades for almost everything, and in particular its use of red vs grey in a way which makes them virtually indistinguishable to a significant portion of the population.  It&#8217;s not the only plug-in to be thoughtless in this way, but it is the worst.</p>



<p>It does come with a lot of other themes &#8211; nearly ninety at time of writing &#8211; but you&#8217;d be forgiven for thinking it does not, as it puts the theme selection setting in a surprising location &#8211; the &#8216;Customize&#8217; section of WordPress&#8217;s Appearance settings.  While this actually makes tremendous sense, <em>no</em> other syntax-highlighting plug-ins put their settings there.  It&#8217;s hard to hold that against this plug-in, for being the <em>one</em> plug-in which (arguably) does the right thing, but I almost overlooked this critical functionality &#8211; I only discovered it by chance because I happened upon its <a href="https://github.com/westonruter/syntax-highlighting-code-block/wiki/Advanced-Usage" data-wpel-link="external" target="_blank" rel="external noopener">Advanced Usage</a> documentation.</p>



<p>That all said, one thing the bland default does have going for it is that the visual sameness helps to slightly obscure how poorly the plug-in understands Swift.</p>



<p>For example, it:</p>



<ul class="wp-block-list">
<li>Doesn&#8217;t understand @-attributes, such as macro and property wrapper invocations.</li>



<li>Has no idea about the difference between function parameter labels and parameter arguments.</li>



<li>Doesn&#8217;t consistently recognise references to properties, such as when they&#8217;re part of KeyPaths.</li>



<li>Doesn&#8217;t understand some important keywords, like <code>async</code> &amp; <code>await</code>.</li>



<li>Doesn&#8217;t recognise method calls consistently (e.g. <code>pack</code> vs <code>reduce</code> &amp; <code>map</code> in the example shown).</li>



<li>Doesn&#8217;t understand raw strings (though it does handle multi-line strings correctly).</li>



<li>Is fooled by the use of keyword-looking names in places where they aren&#8217;t keywords, e.g. the <code>default</code> static property of <code>HomeItem</code>.</li>
</ul>



<p>It&#8217;s pretty apparent, especially once you look at the HTML itself, that it&#8217;s doing only a rudimentary analysis mainly based on a hard-coded list of keywords and heuristics like whether words start with capital letters.  That&#8217;s why it confuses literals (strings &amp; numbers) with type names, function names with property names, and so forth.  It&#8217;s not the only plug-in to try to fake it with such a simplistic algorithm, but it does the worst job of pulling it off.</p>



<p>It renders keywords in bold (like Xcode), which greatly aids readability.</p>



<p>Since it uses the built-in WordPress Code block as its basis, and doesn&#8217;t muck with the fonts, it defaults to whatever the active WordPress theme uses.  As shown in this example, with <a href="https://generatepress.com" data-wpel-link="external" target="_blank" rel="external noopener">GeneratePress</a>, that&#8217;s not even necessarily a monospaced font!  Worst, the plug-in has no built-in configuration option for font (although you can use custom CSS to override it).</p>



<h3 class="wp-block-heading">Pros</h3>



<ul class="wp-block-list">
<li>Extends the built-in, standard Code block.  This makes it comparatively trivial to adopt if you&#8217;ve already got Code blocks on your website (although you may still need to go through and customise some things, such as the language in case auto-detection doesn&#8217;t work correctly).<br><br>This also makes it easier to switch syntax-highlighting plug-ins, <em>provided</em> that the one you switch from or to also supports the standard Code block, which is sadly a minority of them.</li>
</ul>



<h3 class="wp-block-heading">Cons</h3>



<ul class="wp-block-list">
<li>No official theming support.<br><br>You can use custom CSS to re-theme it, thanks to its use of sensible class names for its <code>span</code>s, but other than fixing its bland default colours you can&#8217;t really improve it much, since a <em>lot</em> of the code is emitted as runs of plain text because of the plug-in&#8217;s very poor understanding of Swift.</li>



<li>No global settings &#8211; if you decide to change <em>any</em> settings, at any point, you have to manually find and adjust every existing code snippet manually.<br><br>This might be considered a positive by some users, where they want existing content to remain as-is.  However, some plug-ins offer both a global setting <em>and</em> the ability to override that on a per-case basis, providing more flexibility.</li>



<li>Very limited settings &#8211; just the language (if you don&#8217;t want to rely on auto-detection), which line(s) to highlight, whether to soft wrap, and whether to show line numbers.</li>
</ul>



<h2 class="wp-block-heading" id="syntaxhighlighter-evolved"><a href="https://alex.blog/wordpress-plugins/syntaxhighlighter/" data-wpel-link="external" target="_blank" rel="external noopener">SyntaxHighlighter Evolved</a></h2>



<div class="alignnormal"><div id="metaslider-id-7132" style="max-width: 590px;" class="ml-slider-3-107-0 metaslider metaslider-flex metaslider-7132 ml-slider ms-theme-default nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden" role="region" aria-label="Syntax highlighting: SyntaxHighlighter Evolved [Default theme]" data-height="1030" data-width="590">
    <div id="metaslider_container_7132">
        <div id="metaslider_7132" class="flexslider">
            <ul class='slides'>
                <li style="display: block; width: 100%;" class="slide-7133 ms-image " aria-roledescription="slide" data-date="2023-12-29 18:25:40" data-filename="SyntaxHighlighter-Evolved-Default-theme-Light.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="1180" height="2060" src="https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Light.webp" class="slider-7132 slide-7133 msDefaultImage" alt="" rel="" title="SyntaxHighlighter Evolved [Default theme] (Light)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Light.webp 1180w, https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Light-147x256.webp 147w, https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Light-587x1024.webp 587w, https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Light-1173x2048.webp 1173w, https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Light-293x512.webp 293w, https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Light-147x256@2x.webp 294w, https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Light-587x1024@2x.webp 1174w, https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Light-293x512@2x.webp 586w" sizes="auto, (max-width: 1180px) 100vw, 1180px" /><div class="caption-wrap"><div class="caption">Light mode</div></div></li>
                <li style="display: none; width: 100%;" class="slide-7134 ms-image " aria-roledescription="slide" data-date="2023-12-29 18:25:40" data-filename="SyntaxHighlighter-Evolved-Default-theme-Dark.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="1180" height="2060" src="https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Dark.webp" class="slider-7132 slide-7134 msDefaultImage" alt="" rel="" title="SyntaxHighlighter Evolved [Default theme] (Dark)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Dark.webp 1180w, https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Dark-147x256.webp 147w, https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Dark-587x1024.webp 587w, https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Dark-1173x2048.webp 1173w, https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Dark-293x512.webp 293w, https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Dark-147x256@2x.webp 294w, https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Dark-587x1024@2x.webp 1174w, https://wadetregaskis.com/wp-content/uploads/2023/12/SyntaxHighlighter-Evolved-Default-theme-Dark-293x512@2x.webp 586w" sizes="auto, (max-width: 1180px) 100vw, 1180px" /><div class="caption-wrap"><div class="caption">Dark mode</div></div></li>
            </ul>
        </div>
        
    </div>
</div></div>



<p>This is what I was using for years.  It&#8217;s completely free and <a href="https://github.com/Automattic/syntaxhighlighter" data-wpel-link="external" target="_blank" rel="external noopener">open source</a>.  It uses a proprietary syntax parsing system based on regular expressions.</p>



<h3 class="wp-block-heading">Performance</h3>



<p>It&#8217;s an interesting one, because it actually understands so <em>little</em> Swift syntax that most of it is bucketed together as &#8216;plain&#8217; text.  However, because it renders &#8216;plain&#8217; text in a colour other than black, it gives the surprisingly convincing (at a glance) illusion that it understands much more than it really does.</p>



<p>Overall its rendering is close to Xcode&#8217;s, which is very surprising given its highly rudimentary grammar parser.</p>



<p>It is actually pretty good about identifying keywords &#8211; it actually gets <code>async</code> which many do not &#8211; but it doesn&#8217;t understand them with context, e.g. it mistakes the <code>default</code> static property of <code>HomeItem</code> with the <code>default</code> keyword.</p>



<p>It renders keywords in bold (like Xcode) which greatly aids readability, although note how (unlike Xcode) it messes up the letter spacing as a result (this is a result of the font used &#8211; Monaco &#8211; and thus can be fixed by overriding that with a better font, e.g. SF Mono).</p>



<p>While it covers up a lot of its ignorance with its clever colour choices, there&#8217;s still a few important things that it gets visibly wrong.  For example, it:</p>



<ul class="wp-block-list">
<li>Doesn&#8217;t understand @-attributes, such as macro and property wrapper invocations.</li>



<li>Has no idea about the difference between function parameter labels and parameter arguments.</li>



<li>Doesn&#8217;t understand raw strings.</li>
</ul>



<p>Its choice of Monaco as its font is… interesting, although modern versions of Monaco are thankfully a little smoother than their 1980s ancestor.  That&#8217;s easy to override, however, via custom CSS in a suitable WordPress-generic stylesheet (the plug-in doesn&#8217;t provide any direct way to manipulate styling, beyond choosing from a short list of built-in themes).</p>



<h3 class="wp-block-heading">Pros</h3>



<ul class="wp-block-list">
<li>Most of its settings are global.  So changing themes for a whole site is trivial.</li>



<li>Uses sensible HTML structure and class names, so it&#8217;s easy to unofficially re-theme (although it has a very limited vocabulary of grammar, so you can&#8217;t greatly improve what you see here).</li>



<li>Supports end-user editing of the code (with the syntax highlighting updating appropriately).  This is purely superficial text editing &#8211; there&#8217;s no support for interpreting, compiling, or executing the code.  So I&#8217;m not really sure what the point of this feature is, but I list it here since it is unique to this plug-in (amongst all those I tested).</li>
</ul>



<h3 class="wp-block-heading">Cons</h3>



<ul class="wp-block-list">
<li>Doesn&#8217;t formally support light/dark mode (as do <em>none</em> of the plug-ins tested).  Colours are fixed (to whatever theme you choose) irrespective of the end-user&#8217;s light/dark setting (again, same as all the other plug-ins).  However, one difference versus all the other plug-ins is that this one doesn&#8217;t work properly with <a href="https://wordpress.org/plugins/wp-dark-mode/" data-wpel-link="external" target="_blank" rel="external noopener">WP Dark Mode</a> &#8211; it remains in light mode even while the rest of the page renders correctly in dark mode.<br><br>I strongly suspect the fault lies in WP Dark Mode, not SyntaxHighlighter Evolved, but irrespective it is there and might be a deal-breaker if you&#8217;re particularly attached to WP Dark Mode.</li>



<li>Doesn&#8217;t render the syntax highlighting in the Gutenberg editor, so you&#8217;re stuck with the generic <code>pre</code> appearance there.</li>



<li>Uses a custom Gutenberg block type, rather than just extending the standard Code block.  So you can&#8217;t just upgrade your whole existing site &#8211; you have to manually go through and find every existing Code block, and manually migrate each one.</li>



<li>Doesn&#8217;t get updated super often, although it has been around for years and has generally kept up with new WordPress versions, eventually.</li>
</ul>



<h2 class="wp-block-heading"><a href="https://wordpress.org/plugins/urvanov-syntax-highlighter/" data-wpel-link="external" target="_blank" rel="external noopener">Urvanov Syntax Highlighter</a></h2>



<div class="alignnormal"><div id="metaslider-id-7034" style="max-width: 1140px;" class="ml-slider-3-107-0 metaslider metaslider-flex metaslider-7034 ml-slider ms-theme-default nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden" role="region" aria-label="Syntax highlighting: Urvanov Syntax Highlighter [Classic]" data-height="962" data-width="1140">
    <div id="metaslider_container_7034">
        <div id="metaslider_7034" class="flexslider">
            <ul class='slides'>
                <li style="display: block; width: 100%;" class="slide-7040 ms-image " aria-roledescription="slide" data-date="2023-12-29 09:36:07" data-filename="Urvanov-Syntax-Highlighter-Classic-Light.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="2280" height="1924" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Urvanov-Syntax-Highlighter-Classic-Light.webp" class="slider-7034 slide-7040 msDefaultImage" alt="" rel="" title="Urvanov Syntax Highlighter [Classic] (Light)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Urvanov-Syntax-Highlighter-Classic-Light.webp 2280w, https://wadetregaskis.com/wp-content/uploads/2023/12/Urvanov-Syntax-Highlighter-Classic-Light-256x216.webp 256w, https://wadetregaskis.com/wp-content/uploads/2023/12/Urvanov-Syntax-Highlighter-Classic-Light-512x432@2x.webp 1024w, https://wadetregaskis.com/wp-content/uploads/2023/12/Urvanov-Syntax-Highlighter-Classic-Light-2048x1728.webp 2048w, https://wadetregaskis.com/wp-content/uploads/2023/12/Urvanov-Syntax-Highlighter-Classic-Light-512x432.webp 512w" sizes="auto, (max-width: 2280px) 100vw, 2280px" /><div class="caption-wrap"><div class="caption">Light mode</div></div></li>
                <li style="display: none; width: 100%;" class="slide-7039 ms-image " aria-roledescription="slide" data-date="2023-12-29 09:36:06" data-filename="Urvanov-Syntax-Highlighter-Classic-Dark.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="2280" height="1924" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Urvanov-Syntax-Highlighter-Classic-Dark.webp" class="slider-7034 slide-7039 msDefaultImage" alt="" rel="" title="Urvanov Syntax Highlighter [Classic] (Dark)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Urvanov-Syntax-Highlighter-Classic-Dark.webp 2280w, https://wadetregaskis.com/wp-content/uploads/2023/12/Urvanov-Syntax-Highlighter-Classic-Dark-256x216.webp 256w, https://wadetregaskis.com/wp-content/uploads/2023/12/Urvanov-Syntax-Highlighter-Classic-Dark-512x432@2x.webp 1024w, https://wadetregaskis.com/wp-content/uploads/2023/12/Urvanov-Syntax-Highlighter-Classic-Dark-2048x1728.webp 2048w, https://wadetregaskis.com/wp-content/uploads/2023/12/Urvanov-Syntax-Highlighter-Classic-Dark-512x432.webp 512w" sizes="auto, (max-width: 2280px) 100vw, 2280px" /><div class="caption-wrap"><div class="caption">Dark mode</div></div></li>
            </ul>
        </div>
        
    </div>
</div></div>



<p>A fork of the abandoned <a href="https://wordpress.org/plugins/crayon-syntax-highlighter/" data-wpel-link="external" target="_blank" rel="external noopener">Crayon Syntax Highlighter</a> that uses its own syntax-highlighting engine.</p>



<p>It&#8217;s <a href="https://github.com/urvanov-ru/crayon-syntax-highlighter" data-wpel-link="external" target="_blank" rel="external noopener">open source</a> and free.</p>



<p>I almost didn&#8217;t include this because (a) it&#8217;s really very broken and (b) it doesn&#8217;t really support Swift at all.  I strongly recommend against using it, for numerous reasons.</p>



<h3 class="wp-block-heading">Performance</h3>



<p>Pretty terrible, in a nutshell.  I&#8217;m not going to go into full detail here because the plug-in is largely broken anyway (details shortly, in the Cons section).</p>



<p>Ironically it works better out of the box than if you actually configure it &#8220;correctly&#8221;; it doesn&#8217;t recognise this example as any specific language and falls back to some generic &#8220;Default&#8221; grammar parser.  If you explicitly set it to Swift, the syntax highlighting actually gets markedly worse, and it&#8217;s no surprise why &#8211; <a href="https://github.com/urvanov-ru/crayon-syntax-highlighter/tree/master/langs/swift" data-wpel-link="external" target="_blank" rel="external noopener">its Swift grammar definition</a> is nearly a decade old, dating back to Swift 1.0 in 2014!</p>



<p>One of its most egregious rendering problems is that it translates various special characters &#8211; <code>[</code>, <code>&lt;</code>, <code>&gt;</code>, etc &#8211; to their escaped HTML entities.  This can be &#8216;corrected&#8217; in its settings &#8211; it has a &#8220;Decode HTML entities in code&#8221; option &#8211; but that&#8217;s a hacky bandaid over the bug, that precludes you from <em>actually</em> using HTML entities in your code example (so you can&#8217;t use this plug-in for the HTML language itself).</p>



<p>Another rendering annoyance is that it makes the code block&#8217;s width 100%, irrespective of the actual width of the code.  Most of the plug-ins do that, actually, but it&#8217;s much more apparent with this one because of its use of a visual border and alternating line background colours.  You can configure a maximum width in its global settings, but (as with most of these plug-ins) there&#8217;s no (built-in) way to make it size to fit.</p>



<p>On syntax understanding itself, it basically has none.  It simply recognises some fairly general syntax patterns, such as strings, literals, and parenthesis-indicated function calls.  It doesn&#8217;t recognise most keywords, even.</p>



<h3 class="wp-block-heading">Pros</h3>



<ul class="wp-block-list">
<li>Very configurable &#8211; perhaps the <em>most</em> configurable plug-in tested.  Beyond just theming options &#8211; including the ability to easily change the font from its default of Monaco &#8211; it includes options rarely covered by other plug-ins such as margin customisations.</li>
</ul>



<h3 class="wp-block-heading">Cons</h3>



<ul class="wp-block-list">
<li>Nominally offers a Gutenberg block, but it doesn&#8217;t work &#8211; you cannot actually edit the textual contents, in the Gutenberg editor, and it doesn&#8217;t render at all on the actual published page.  Thus you can <em>only</em> use the plug-in by having it take over existing <code>&lt;code</code>&gt; and/or <code>&lt;pre&gt;</code> blocks…</li>



<li>Takes over all existing <code>&lt;code</code>&gt; and <code>&lt;pre&gt;</code> blocks by default, even those by other plug-ins, and those that don&#8217;t contain code at all (e.g. where you were simply presenting monospaced text such as Terminal output).  You can configure this in the settings, including turning it off, but given the Gutenberg block doesn&#8217;t work, this is the <em>only</em> way to actually use the plug-in.<br><br><img loading="lazy" decoding="async" width="391" height="225" class="wp-image-7042" style="width: 391px;" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Urvanov-Syntax-Highlighter-22Tag22-settings.webp" alt="Screenshot of the 'Tag' settings for the Urvanov Syntax Highlighter WordPress plug-in" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Urvanov-Syntax-Highlighter-22Tag22-settings.webp 782w, https://wadetregaskis.com/wp-content/uploads/2023/12/Urvanov-Syntax-Highlighter-22Tag22-settings-256x147.webp 256w, https://wadetregaskis.com/wp-content/uploads/2023/12/Urvanov-Syntax-Highlighter-22Tag22-settings-512x295.webp 512w" sizes="auto, (max-width: 391px) 100vw, 391px" /><br><br>I spent some time playing with different combinations of these settings, but many combinations are inexplicably unusable &#8211; they just result in broken rendering &#8211; and I couldn&#8217;t find anything that improved on the default behaviour.<br><br>As such, this is an especially all-or-nothing syntax highlighter.  It <em>really</em> doesn&#8217;t play well with others.</li>



<li>Since it just takes over existing <code>&lt;code</code>&gt; and/or <code>&lt;pre&gt;</code> blocks, there&#8217;s no per-use customisation possible &#8211; everything is exclusively controlled through global settings, including the code language.</li>



<li>By default adds its CSS &amp; JavaScript files to <em>every</em> page load, plus some inline CSS &amp; JavaScript, irrespective of whether the page actually needs it or not.  This can nominally be corrected in the settings, via the &#8220;Attempt to load Crayon&#8217;s CSS and JavaScript only when needed&#8221; option, but I didn&#8217;t test it (and it&#8217;s not encouraging that it&#8217;s both disabled by default and uses the word <em>attempt</em>, both suggesting this feature doesn&#8217;t work reliably).<br><br>And they&#8217;re not entirely trivial files, either, even though rendering is done server-side &#8211; its JavaScript is 65 KB alone!  Its CSS is another 28 KB.  With Brotli compression they&#8217;re ~18 KB.  They compress well in part for the same reason they&#8217;re so egregiously large &#8211; the use of &#8220;urvanov-syntax-highlighter&#8221; / &#8220;urvanov_syntax_highlighter&#8221; prefixes on so many of the names.  This bloats up the page source as well, with oversized HTML class names for every snippet of styled code.</li>



<li>Doesn&#8217;t render the syntax highlighting in the Gutenberg editor, so you&#8217;re stuck with the generic <code>pre</code> appearance there.</li>
</ul>



<h1 class="wp-block-heading">The winner</h1>



<p>…is hard to pick unilaterally.  Each plug-in has significant limitations or trade-offs.  Which is best may depend on your personal preferences and specific needs.</p>



<p>Most of the plug-ins do a pretty atrocious job at actually understanding Swift, and at best for them it&#8217;s a question of how well they can fake it through clever heuristics and styling choices.  <a href="#syntaxhighlighter-evolved">SyntaxHighlighter Evolved</a> warrants an honourable mention in this regard for doing a particularly impressive job despite its very limited brains.  There&#8217;s a reason I used it for years with relatively few complaints, and if it hadn&#8217;t had issues with WP Dark Mode &#8211; before I realised WP Dark Mode was buggy anyway and had to be replaced &#8211; I probably wouldn&#8217;t have bothered doing all this competitive research, and wouldn&#8217;t be switching away from it.</p>



<p>The most common engines used by syntax-highlighting plug-ins are <a href="https://prismjs.com" data-wpel-link="external" target="_blank" rel="external noopener">Prism.js</a> and <a href="https://highlightjs.org" data-wpel-link="external" target="_blank" rel="external noopener">Highlight.js</a> / <a href="https://github.com/scrivo/highlight.php" data-wpel-link="external" target="_blank" rel="external noopener">Highlight.php</a>, but frankly they&#8217;re bad at Swift &#8211; a situation that&#8217;s unlikely to change given Swift is such a niche language for them; they&#8217;re clearly focused on browser languages like JavaScript, HTML, and CSS.  Even that aside, they tend to use client-side rendering which is slower and buggier.</p>



<figure class="wp-block-pullquote"><blockquote><p>Ultimately, I tentatively believe that <a href="#code-block-pro">Code Block Pro</a> is the best option.</p></blockquote></figure>



<p>It <em>currently</em> does a somewhat average job in understanding Swift and rendering it pleasingly &#8211; just like all the plug-ins tested &#8211; but it seems to have the most promising foundation, being based on the same grammar &amp; theme files as are used by Visual Studio Code (and <a href="https://github.com/github-linguist/linguist/tree/master/vendor/grammars" data-wpel-link="external" target="_blank" rel="external noopener">GitHub</a>).  So it has the possibility of significant improvements in future; at the very least it would make sense for the Swift community to focus on it since the benefits will be applicable not just to WordPress websites but also Visual Studio Code and GitHub.</p>



<h4 class="wp-block-heading">Refinements to Code Block Pro</h4>



<div class="alignnormal"><div id="metaslider-id-7116" style="max-width: 570px;" class="ml-slider-3-107-0 metaslider metaslider-flex metaslider-7116 ml-slider ms-theme-default nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden nav-hidden" role="region" aria-label="Syntax highlighting: Code Block Pro [Light Plus w/ modifications]" data-height="1280" data-width="570">
    <div id="metaslider_container_7116">
        <div id="metaslider_7116" class="flexslider">
            <ul class='slides'>
                <li style="display: block; width: 100%;" class="slide-7117 ms-image " aria-roledescription="slide" data-date="2023-12-29 16:29:49" data-filename="Code-Block-Pro-Light-Plus-w-customisations-Light.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="1140" height="2560" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-w-customisations-Light.webp" class="slider-7116 slide-7117 msDefaultImage" alt="" rel="" title="Code Block Pro [Light Plus w: customisations] (Light)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-w-customisations-Light.webp 1140w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-w-customisations-Light-114x256.webp 114w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-w-customisations-Light-228x512@2x.webp 456w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-w-customisations-Light-912x2048.webp 912w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-w-customisations-Light-228x512.webp 228w" sizes="auto, (max-width: 1140px) 100vw, 1140px" /><div class="caption-wrap"><div class="caption">Light mode</div></div></li>
                <li style="display: none; width: 100%;" class="slide-7118 ms-image " aria-roledescription="slide" data-date="2023-12-29 16:29:49" data-filename="Code-Block-Pro-Light-Plus-w-customisations-Dark.webp" data-slide-type="image"><img loading="lazy" decoding="async" width="1140" height="2560" src="https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-w-customisations-Dark.webp" class="slider-7116 slide-7118 msDefaultImage" alt="" rel="" title="Code Block Pro [Light Plus w: customisations] (Dark)" srcset="https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-w-customisations-Dark.webp 1140w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-w-customisations-Dark-228x512@2x.webp 456w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-w-customisations-Dark-912x2048.webp 912w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-w-customisations-Dark-114x256.webp 114w, https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-w-customisations-Dark-228x512.webp 228w" sizes="auto, (max-width: 1140px) 100vw, 1140px" /><div class="caption-wrap"><div class="caption">Dark mode</div></div></li>
            </ul>
        </div>
        
    </div>
</div></div>



<p>Every light-style theme available with Code Block Pro &#8211; including the paid expansion pack &#8211; has significant rendering errors for Swift, but after spending an egregious amount of time exploring the themes and experimenting with fixes for them, I&#8217;ve concluded that Light Plus is the least bad option.  With some crude but simple CSS I&#8217;m able to adjust its appearance as shown here, which is loosely styled after Xcode&#8217;s default (light mode) theme.</p>



<p>I didn&#8217;t do much to accomodate Dark mode, limiting my modifications there to merely using SF Pro (&#8220;system-ui&#8221;) for comments.  I don&#8217;t use Dark mode myself, so I might not have a good eye for what looks good there, but the default colours (from the simple inversion by the Dracula Dark Mode plug-in) seem alright to me.  And pragmatically, I&#8217;d have to overwrite <em>every</em> colour used in the theme in order to ensure no rendering issues, and that&#8217;s a whole lot of CSS I don&#8217;t want to write nor bloat my page loads with.</p>



<p>I also turn on &#8220;Disable padding&#8221; in its &#8220;Extra Settings&#8221;, as by default it uses (a) hard-coded padding dimensions, in pixels and (b) padding, not margins.  A strange choice, but at least it has the option to disable it.</p>



<div class="wp-block-kevinbatdorf-code-block-pro padding-disabled" data-code-block-pro-font-family="" style="font-size:.875rem;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><pre class="shiki light-plus" style="background-color: #FFFFFF" tabindex="0"><code><span class="line"><span style="color: #800000">div.wp-block-kevinbatdorf-code-block-pro</span><span style="color: #000000"> {</span></span>
<span class="line"><span style="color: #000000">	</span><span style="color: #E50000">font-family</span><span style="color: #000000">: </span><span style="color: #A31515">&quot;SF Mono&quot;</span><span style="color: #000000">, SFMono-Regular, </span><span style="color: #0451A5">ui-monospace</span><span style="color: #000000">, </span><span style="color: #0451A5">monospace</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">	</span><span style="color: #E50000">width</span><span style="color: #000000">: </span><span style="color: #0451A5">fit-content</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">	</span><span style="color: #E50000">margin</span><span style="color: #000000">: </span><span style="color: #098658">1em</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">	</span></span>
<span class="line"><span style="color: #000000">	&amp; </span><span style="color: #E50000">span</span><span style="color: #000000">[</span><span style="color: #E50000">style</span><span style="color: #000000">*=</span><span style="color: #EE0000">\#</span><span style="color: #000000">0000FF], </span><span style="color: #E50000">span</span><span style="color: #000000">[</span><span style="color: #E50000">style</span><span style="color: #000000">*=</span><span style="color: #EE0000">\#</span><span style="color: #000000">AF00DB] { </span><span style="color: #008000">/* Keywords */</span></span>
<span class="line"><span style="color: #000000">		</span><span style="color: #E50000">font-weight</span><span style="color: #000000">: </span><span style="color: #098658">675</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">		</span><span style="color: #E50000">color</span><span style="color: #000000">: </span><span style="color: #0451A5">#9B2393</span><span style="color: #000000"> </span><span style="color: #0000FF">!important</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">	}</span></span>
<span class="line"><span style="color: #000000">	</span></span>
<span class="line"><span style="color: #000000">	&amp; </span><span style="color: #800000">span</span><span style="color: #000000">[</span><span style="color: #E50000">style</span><span style="color: #000000">*=</span><span style="color: #EE0000">\#</span><span style="color: #A31515">008000</span><span style="color: #000000">], </span><span style="color: #800000">span</span><span style="color: #000000">[</span><span style="color: #E50000">style</span><span style="color: #000000">*=</span><span style="color: #EE0000">\#</span><span style="color: #A31515">81f179</span><span style="color: #000000">] { </span><span style="color: #008000">/* Comments */</span></span>
<span class="line"><span style="color: #000000">		</span><span style="color: #E50000">font-family</span><span style="color: #000000">: </span><span style="color: #0451A5">system-ui</span><span style="color: #000000"> </span><span style="color: #0000FF">!important</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">		</span><span style="color: #E50000">font-style</span><span style="color: #000000">: </span><span style="color: #0451A5">italic</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">	}</span></span>
<span class="line"><span style="color: #000000">	</span></span>
<span class="line"><span style="color: #000000">	&amp; </span><span style="color: #800000">span</span><span style="color: #000000">[</span><span style="color: #E50000">style</span><span style="color: #000000">*=</span><span style="color: #EE0000">\#</span><span style="color: #A31515">008000</span><span style="color: #000000">] { </span><span style="color: #008000">/* Comments */</span></span>
<span class="line"><span style="color: #000000">		</span><span style="color: #E50000">color</span><span style="color: #000000">: </span><span style="color: #0451A5">#5D6C79</span><span style="color: #000000"> </span><span style="color: #0000FF">!important</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">	}</span></span>
<span class="line"><span style="color: #000000">	</span></span>
<span class="line"><span style="color: #000000">	&amp; </span><span style="color: #800000">span</span><span style="color: #000000">[</span><span style="color: #E50000">style</span><span style="color: #000000">*=</span><span style="color: #EE0000">\#</span><span style="color: #A31515">001080</span><span style="color: #000000">] { </span><span style="color: #008000">/* Properties */</span></span>
<span class="line"><span style="color: #000000">		</span><span style="color: #E50000">color</span><span style="color: #000000">: </span><span style="color: #0451A5">#3E8087</span><span style="color: #000000"> </span><span style="color: #0000FF">!important</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">	}</span></span>
<span class="line"><span style="color: #000000">	</span></span>
<span class="line"><span style="color: #000000">	&amp; </span><span style="color: #800000">span</span><span style="color: #000000">[</span><span style="color: #E50000">style</span><span style="color: #000000">*=</span><span style="color: #EE0000">\#</span><span style="color: #A31515">795E26</span><span style="color: #000000">] { </span><span style="color: #008000">/* Function names and argument labels */</span></span>
<span class="line"><span style="color: #000000">		</span><span style="color: #E50000">color</span><span style="color: #000000">: </span><span style="color: #0451A5">#804FB8</span><span style="color: #000000"> </span><span style="color: #0000FF">!important</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">	}</span></span>
<span class="line"><span style="color: #000000">	</span></span>
<span class="line"><span style="color: #000000">	&amp; </span><span style="color: #800000">span</span><span style="color: #000000">[</span><span style="color: #E50000">style</span><span style="color: #000000">*=</span><span style="color: #EE0000">\#</span><span style="color: #A31515">267F99</span><span style="color: #000000">] { </span><span style="color: #008000">/* Type names */</span></span>
<span class="line"><span style="color: #000000">		</span><span style="color: #E50000">color</span><span style="color: #000000">: </span><span style="color: #0451A5">#4B22B0</span><span style="color: #000000"> </span><span style="color: #0000FF">!important</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">	}</span></span>
<span class="line"><span style="color: #000000">	</span></span>
<span class="line"><span style="color: #000000">	&amp; </span><span style="color: #800000">span</span><span style="color: #000000">[</span><span style="color: #E50000">style</span><span style="color: #000000">*=</span><span style="color: #EE0000">\#</span><span style="color: #A31515">A31515</span><span style="color: #000000">] { </span><span style="color: #008000">/* String literals */</span></span>
<span class="line"><span style="color: #000000">		</span><span style="color: #E50000">font-weight</span><span style="color: #000000">: </span><span style="color: #098658">500</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">		</span><span style="color: #E50000">color</span><span style="color: #000000">: </span><span style="color: #0451A5">#D12F1B</span><span style="color: #000000"> </span><span style="color: #0000FF">!important</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">	}</span></span>
<span class="line"><span style="color: #000000">	</span></span>
<span class="line"><span style="color: #000000">	&amp; </span><span style="color: #800000">span</span><span style="color: #000000">[</span><span style="color: #E50000">style</span><span style="color: #000000">*=</span><span style="color: #EE0000">\#</span><span style="color: #A31515">098658</span><span style="color: #000000">] { </span><span style="color: #008000">/* Numeric literals */</span></span>
<span class="line"><span style="color: #000000">		</span><span style="color: #E50000">font-weight</span><span style="color: #000000">: </span><span style="color: #098658">500</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">		</span><span style="color: #E50000">color</span><span style="color: #000000">: </span><span style="color: #0451A5">#272AD8</span><span style="color: #000000"> </span><span style="color: #0000FF">!important</span><span style="color: #000000">;</span></span>
<span class="line"><span style="color: #000000">	}</span></span>
<span class="line"><span style="color: #000000">}</span></span></code></pre></div>



<h1 class="wp-block-heading">What are other websites using?</h1>



<p>I figured it might be helpful to look at what other Swift-code-rendering websites use, to see if there&#8217;s any I missed (there wasn&#8217;t) and which the community seems to believe is best.</p>



<ul class="wp-block-list">
<li><a href="https://www.swiftbysundell.com" data-type="link" data-id="https://www.swiftbysundell.com" data-wpel-link="external" target="_blank" rel="external noopener">Swift by Sundell</a> is using <a href="https://github.com/johnsundell/publish" data-type="link" data-id="https://github.com/johnsundell/publish" data-wpel-link="external" target="_blank" rel="external noopener">Publish</a> and the <a href="https://github.com/johnsundell/splash" data-type="link" data-id="https://github.com/johnsundell/splash" data-wpel-link="external" target="_blank" rel="external noopener">Splash</a> plug-in.  Splash seems to do a pretty good job &#8211; clearly better than any JavaScript or PHP syntax highlighters.</li>



<li><a href="https://www.hackingwithswift.com" data-type="link" data-id="https://www.hackingwithswift.com" data-wpel-link="external" target="_blank" rel="external noopener">Hacking with Swift</a> is using <a href="https://wordpress.org" data-type="link" data-id="https://wordpress.org" data-wpel-link="external" target="_blank" rel="external noopener">WordPress</a> and ultimately <a href="https://prismjs.com" data-wpel-link="external" target="_blank" rel="external noopener">Prism.js</a>, although I&#8217;m not sure through which plug-in (possibly <a href="https://github.com/mkaz/code-syntax-block" data-type="link" data-id="https://github.com/mkaz/code-syntax-block" data-wpel-link="external" target="_blank" rel="external noopener">Code Syntax Block</a>).</li>



<li><a href="https://www.cocoawithlove.com" data-type="link" data-id="https://www.cocoawithlove.com" data-wpel-link="external" target="_blank" rel="external noopener">Cocoa with Love</a> might be using some Ruby-based platform or static generator, but it&#8217;s clear it&#8217;s using <a href="https://github.com/rouge-ruby/rouge" data-type="link" data-id="https://github.com/rouge-ruby/rouge" data-wpel-link="external" target="_blank" rel="external noopener">Rouge</a> for syntax highlighting.<br><br>Sidenote: Rouge seems to do a decent job of correctly identifying tokens and their types, although its underlying model looks pretty simplistic (it tends to default to the &#8220;n&#8221; class by default, meaning &#8220;name&#8221;, meaning it doesn&#8217;t really know if it&#8217;s a parameter label, parameter name, type name, etc).</li>



<li><a href="https://www.donnywals.com" data-type="link" data-id="https://www.donnywals.com" data-wpel-link="external" target="_blank" rel="external noopener">Donny Wals</a> is using <a href="https://wordpress.org" data-type="link" data-id="https://wordpress.org" data-wpel-link="external" target="_blank" rel="external noopener">WordPress</a> with the <a href="https://github.com/westonruter/syntax-highlighting-code-block" data-type="link" data-id="https://github.com/westonruter/syntax-highlighting-code-block" data-wpel-link="external" target="_blank" rel="external noopener">Syntax-highlighting Code Block</a> plug-in, which uses <a href="https://github.com/scrivo/highlight.php" data-type="link" data-id="https://github.com/scrivo/highlight.php" data-wpel-link="external" target="_blank" rel="external noopener">Highlight.php</a> (based on <a href="https://highlightjs.org" data-wpel-link="external" target="_blank" rel="external noopener">Highlight.js</a>).</li>



<li><a href="https://matteomanferdini.com" data-type="link" data-id="https://matteomanferdini.com" data-wpel-link="external" target="_blank" rel="external noopener">Matteo Manferdini</a> is using <a href="https://wordpress.org" data-type="link" data-id="https://wordpress.org" data-wpel-link="external" target="_blank" rel="external noopener">WordPress</a> with the <a href="https://generatepress.com" data-type="link" data-id="https://generatepress.com" data-wpel-link="external" target="_blank" rel="external noopener">GeneratePress</a> theme (same as this site, at time of writing) and ultimately <a href="https://prismjs.com" data-wpel-link="external" target="_blank" rel="external noopener">Prism.js</a>, likely through <a href="https://github.com/mkaz/code-syntax-block" data-type="link" data-id="https://github.com/mkaz/code-syntax-block" data-wpel-link="external" target="_blank" rel="external noopener">Code Syntax Block</a>.</li>



<li><a href="https://nshipster.com" data-type="link" data-id="https://nshipster.com" data-wpel-link="external" target="_blank" rel="external noopener">NSHipster</a> appears to be statically generated with <a href="https://github.com/NSHipster/nshipster.com" data-wpel-link="external" target="_blank" rel="external noopener">a bespoke tool written in Ruby</a> using <a href="https://github.com/NSHipster/rouge" data-type="link" data-id="https://github.com/NSHipster/rouge" data-wpel-link="external" target="_blank" rel="external noopener">a custom fork</a> of <a href="https://github.com/rouge-ruby/rouge" data-wpel-link="external" target="_blank" rel="external noopener">Rouge</a>.</li>



<li><a href="https://developer.apple.com/swift/blog/" data-wpel-link="external" target="_blank" rel="external noopener">The old Swift Blog</a> uses… I don&#8217;t know.  Possibly a proprietary system, for both the platform and the syntax highlighting.  I didn&#8217;t find any identification or indicators otherwise of any particular library.</li>



<li><a href="https://www.swift.org/blog/" type="link" id="https://www.swift.org/blog" data-wpel-link="external" target="_blank" rel="external noopener">The newer Swift Blog</a> uses… possibly the same mystery platform as the old one.  But it does clearly use <a href="https://github.com/rouge-ruby/rouge" data-type="link" data-id="https://github.com/rouge-ruby/rouge" data-wpel-link="external" target="_blank" rel="external noopener">Rouge</a> for syntax highlighting.</li>



<li><a href="https://swiftevolution.substack.com" data-wpel-link="external" target="_blank" rel="external noopener">Swift Evolution Monthly</a> is hosted on <a href="https://substack.com" data-type="link" data-id="https://substack.com" data-wpel-link="external" target="_blank" rel="external noopener">Substack</a> and doesn&#8217;t do any syntax highlighting at all!</li>



<li><a href="https://www.swiftwithvincent.com" data-type="link" data-id="https://www.swiftwithvincent.com" data-wpel-link="external" target="_blank" rel="external noopener">Swift with Vincent</a> is hosted on <a href="https://www.squarespace.com" data-wpel-link="external" target="_blank" rel="external noopener">Squarespace</a>, which ultimately uses <a href="https://prismjs.com" data-wpel-link="external" target="_blank" rel="external noopener">Prism.js</a>.</li>



<li><a href="https://swiftwithmajid.com" data-type="link" data-id="https://swiftwithmajid.com" data-wpel-link="external" target="_blank" rel="external noopener">Swift with Majid</a> is statically generated using <a href="https://jekyllrb.com" data-type="link" data-id="https://jekyllrb.com" data-wpel-link="external" target="_blank" rel="external noopener">Jekyll</a> and uses <a href="https://github.com/rouge-ruby/rouge" data-type="link" data-id="https://github.com/rouge-ruby/rouge" data-wpel-link="external" target="_blank" rel="external noopener">Rouge</a>.</li>



<li><a href="https://swiftinit.org" data-type="link" data-id="https://swiftinit.org" data-wpel-link="external" target="_blank" rel="external noopener">Swiftinit</a> (by Dianna a.k.a. &#8220;<a href="https://forums.swift.org/u/taylorswift" data-type="link" data-id="https://forums.swift.org/u/taylorswift" data-wpel-link="external" target="_blank" rel="external noopener">taylorswift</a>&#8221; / &#8220;<a href="https://github.com/tayloraswift?tab=repositories" data-type="link" data-id="https://github.com/tayloraswift?tab=repositories" data-wpel-link="external" target="_blank" rel="external noopener">tayloraswift</a>&#8220;) uses a proprietary platform (written in Swift).  The syntax highlighting is presumably also proprietary.<br><br>Sidenote:  there&#8217;s not a lot of syntax-highlighted code on Swiftinit (mostly it&#8217;s in some hidden blog posts from 2022), but what&#8217;s there looks pretty similar to what <a href="https://github.com/rouge-ruby/rouge" data-type="link" data-id="https://github.com/rouge-ruby/rouge" data-wpel-link="external" target="_blank" rel="external noopener">Rouge</a> generates.  It does a pretty good job of correctly interpreting the syntax, although there&#8217;s not a great deal of apparent fidelity &#8211; mostly it&#8217;s just dividing things into formal names (types, functions, etc), variables, keywords, and everything else.</li>



<li><a href="https://www.avanderlee.com" data-wpel-link="external" target="_blank" rel="external noopener">SwiftLee</a> is using <a href="https://wordpress.org" data-type="link" data-id="https://wordpress.org" data-wpel-link="external" target="_blank" rel="external noopener">WordPress</a> and the <a href="https://github.com/mkaz/code-syntax-block" data-type="link" data-id="https://github.com/mkaz/code-syntax-block" data-wpel-link="external" target="_blank" rel="external noopener">Code Syntax Block</a> plug-in, which is <a href="https://prismjs.com" data-wpel-link="external" target="_blank" rel="external noopener">Prism.js</a> underneath.</li>



<li><a href="https://swiftrocks.com" data-wpel-link="external" target="_blank" rel="external noopener">SwiftRocks</a> is using <a href="https://getbootstrap.com" data-type="link" data-id="https://getbootstrap.com" data-wpel-link="external" target="_blank" rel="external noopener">Bootstrap</a> and <a href="https://prismjs.com" data-type="link" data-id="https://prismjs.com" data-wpel-link="external" target="_blank" rel="external noopener">Prism.js</a>.</li>



<li><a href="https://swiftui-lab.com" data-wpel-link="external" target="_blank" rel="external noopener">SwiftUI Lab</a> is using <a href="https://wordpress.org" data-type="link" data-id="https://wordpress.org" data-wpel-link="external" target="_blank" rel="external noopener">WordPress</a> and the <a href="https://wordpress.org/plugins/prismatic/" data-wpel-link="external" target="_blank" rel="external noopener">Prismatic</a> plug-in, which is configurable to either <a href="https://prismjs.com" data-wpel-link="external" target="_blank" rel="external noopener">Prism.js</a> or <a href="https://highlightjs.org" data-type="link" data-id="https://highlightjs.org" data-wpel-link="external" target="_blank" rel="external noopener">Highlight.js</a> underneath; the site has elected to use Prism.js.</li>



<li><a href="https://troz.net" data-wpel-link="external" target="_blank" rel="external noopener">TrozWare</a> is using <a href="https://gohugo.io" data-type="link" data-id="https://gohugo.io" data-wpel-link="external" target="_blank" rel="external noopener">Hugo</a> and <a href="https://prismjs.com" data-type="link" data-id="https://prismjs.com" data-wpel-link="external" target="_blank" rel="external noopener">Prism.js</a>.</li>



<li><a href="https://www.vadimbulavin.com" data-wpel-link="external" target="_blank" rel="external noopener">Yet Another Swift Blog</a> is statically generated using <a href="https://jekyllrb.com" data-type="link" data-id="https://jekyllrb.com" data-wpel-link="external" target="_blank" rel="external noopener">Jekyll</a> and uses <a href="https://github.com/rouge-ruby/rouge" data-type="link" data-id="https://github.com/rouge-ruby/rouge" data-wpel-link="external" target="_blank" rel="external noopener">Rouge</a> (though oddly I also see fragments of <a href="https://prismjs.com" data-wpel-link="external" target="_blank" rel="external noopener">Prism.js</a> and <a href="https://highlightjs.org" data-type="link" data-id="https://highlightjs.org" data-wpel-link="external" target="_blank" rel="external noopener">Highlight.js</a> on the site, although I didn&#8217;t see any actual use of them to render code).</li>
</ul>



<p>If you&#8217;re keeping score, that&#8217;s (syntax-highlighter-wise):</p>



<ul class="narrow-line-spacing wp-block-list">
<li>Prism.js: 7</li>



<li>Rouge: 5</li>



<li>Unknown: 2</li>



<li>Highlight.js: 1</li>



<li>Splash: 1</li>
</ul>



<p>And platform-wise:</p>



<ul class="narrow-line-spacing wp-block-list">
<li>WordPress: 5</li>



<li>Unknown: 3</li>



<li>Jekyll: 2</li>



<li>Proprietary: 2</li>



<li>Bootstrap: 1</li>



<li>Hugo: 1</li>



<li>Substack: 1</li>



<li>Squarespace: 1</li>



<li>Publish: 1</li>
</ul>



<p>It&#8217;s notable that <em>not one</em> is using Code Block Pro nor the underlying Shiki engine, even though (with the serious caveats mentioned earlier) they do the best job of actually understanding Swift.</p>


<ol class="wp-block-footnotes"><li id="f5cd2d93-b8e5-4773-8838-26add7d33f48">Strictly-speaking not for any technical reason, as the plug-ins could run more advanced tooling on the server (as some bespoke CMS&#8217;s do), but I have not encountered any WordPress plug-in which does so. <a href="#f5cd2d93-b8e5-4773-8838-26add7d33f48-link" aria-label="Jump to footnote reference 1">↩︎</a></li><li id="395a26f7-0a74-4647-ae97-e770481a032a">Technically you can do it with just custom CSS, by overriding your theme&#8217;s defaults inside a <code>@media (prefers-color-scheme: dark)</code> block, but this is likely impractical for all but the most simplistic and static WordPress installations &#8211; you have to be <em>sure</em> you catch <em>every</em> GUI element and colour.  A good plug-in will dynamically rewrite the CSS client-side, ensuring everything is covered. <a href="#395a26f7-0a74-4647-ae97-e770481a032a-link" aria-label="Jump to footnote reference 2">↩︎</a></li></ol>]]></content:encoded>
					
					<wfw:commentRss>https://wadetregaskis.com/swift-code-syntax-highlighting-in-wordpress/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			<media:content url="https://wadetregaskis.com/wp-content/uploads/2023/12/Code-Block-Pro-Light-Plus-w-customisations-Light-feature-image.webp" medium="image" />
<post-id xmlns="com-wordpress:feed-additions:1">5561</post-id>	</item>
	</channel>
</rss>
