<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="https://shazwazza.com/rss/xslt"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Shazwazza</title>
    <link>https://shazwazza.com/</link>
    <description>My blog which is pretty much just all about coding</description>
    <generator>Articulate, blogging built on Umbraco</generator>
    <image>
      <url>/media/0libq25y/frog.png?rmode=max&amp;v=1da0e911f4e6890</url>
      <title>Shazwazza</title>
      <link>https://shazwazza.com/</link>
    </image>
    <item>
      <guid isPermaLink="false">1290</guid>
      <link>https://shazwazza.com/post/articulate-430-with-support-for-markdown-code-snippets-and-syntax-highlighting/</link>
      <category>Articulate</category>
      <title>Articulate 4.3.0 with support for markdown code snippets and syntax highlighting</title>
      <description>&lt;p&gt;I'm happy to announce that &lt;a href="https://github.com/Shazwazza/Articulate/releases/tag/v4.3.0"&gt;Articulate 4.3.0 is shipped&lt;/a&gt; and includes a great new feature that I've been wanting/needing:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The ability to create markdown based posts with support for GitHub style code fences/snippets and syntax highlighting for (almost) any coding language.&lt;/strong&gt; &lt;a href="https://github.com/Shazwazza/Articulate/issues/341"&gt;See #341&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Now I can finally do away with using Live Writer for my blog and having to manually add css classes to the html for syntax highlighting... yes that's what I've been doing ‍♂️&lt;/p&gt;
&lt;h2 id="upgrading"&gt;Upgrading&lt;/h2&gt;
&lt;p&gt;Once you've updated to the 4.3.0 release, you'll probably need to change the Property Editor of the &lt;code&gt;Articulate Markdown&lt;/code&gt; Data Type to be &lt;code&gt;Articulate Markdown editor&lt;/code&gt; since it's most likely currently configured to the default/basic Umbraco markdown editor.&lt;/p&gt;
&lt;p&gt;You'll then need to update your Post.cshtml theme file to include the correct Prism dependencies. For example, here's the &lt;a href="https://github.com/Shazwazza/Articulate/commit/40ada4e5cfa65bc6e9eae73c35dfae057453bda7#diff-0227666dd80b3592a91378b549d779105eeb896db0c56bd84f5ec2c0ae6c2d46"&gt;update/diff to the VAPOR theme&lt;/a&gt; which adds these dependencies. It's just ensuring that the Prism stylesheet is added to the header and the Prism.js dependencies are appended to the Post.cshtml file.&lt;/p&gt;
&lt;p&gt;Once that's all done, your set!&lt;/p&gt;
&lt;h2 id="creating-markdown-posts"&gt;Creating markdown posts&lt;/h2&gt;
&lt;p&gt;If you didn't already know, Articulate has always had a &lt;a href="https://github.com/Shazwazza/Articulate/wiki/Creating-a-blog-post#using-markdown-from-your-browser-works-great-with-mobile-phones-too"&gt;browser based markdown editor to create posts&lt;/a&gt;. You can simply go to your Articulate root URL and go to the path: &lt;code&gt;a-new&lt;/code&gt; to load the markdown editor. Previously this editor would require you to authenticate at the end of writing your post (if you weren't already authenticated) but now it requires authentication up-front.&lt;/p&gt;
&lt;p&gt;Once it's loaded, it's just a text editor and you can use your all the normal markdown syntax. You can even upload or take photos with the editor &lt;/p&gt;
&lt;p&gt;Of course you can just use the back office markdown editor to create or update posts too but I find for quickly getting a post written and published it's faster to use the &lt;code&gt;/a-new&lt;/code&gt; editor... and it works on mobile.&lt;/p&gt;
&lt;h2 id="using-code-fences-with-syntax-highlighting"&gt;Using code fences with syntax highlighting&lt;/h2&gt;
&lt;p&gt;&lt;a href="https://docs.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks"&gt;GitHub's documentation&lt;/a&gt; shows how this works. The typical code fence is 3x back-ticks above and below your code snippet. If you want to add language specific syntax highlighting you can use 3x back-ticks + the language name/alias. For example, c# would be: &lt;code&gt;```cs&lt;/code&gt; (or c# or csharp) and JavaScript would be &lt;code&gt;```js&lt;/code&gt;. &lt;a href="https://docs.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting"&gt;GitHub's implementation&lt;/a&gt; is different from what Articulate uses so it may not be a perfect 1:1 result but should be fairly close. Articulate is using a combination of:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/xoofx/markdig"&gt;Markdig&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/ilich/Markdig.Prism"&gt;Markdig.Prism&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://prismjs.com/"&gt;Prism.js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="rendered-examples"&gt;Rendered Examples&lt;/h3&gt;
&lt;p&gt;There are just rendered examples based on the default prism styles. I wrote this blog post with the Articulate markdown editor so you can see the results.&lt;/p&gt;
&lt;p&gt;Here's an example of a rendered csharp code fence:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-csharp"&gt;/// &amp;lt;summary&amp;gt;
/// This is an example of the ArticulateComposer
/// &amp;lt;/summary&amp;gt;
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class ArticulateComposer : IUserComposer
{
    public void Compose(Composition composition)
    {
        composition.RegisterUnique&amp;lt;ArticulateRoutes&amp;gt;();
        composition.RegisterUnique&amp;lt;ContentUrls&amp;gt;();
        composition.RegisterUnique&amp;lt;ArticulateDataInstaller&amp;gt;();
        composition.RegisterUnique&amp;lt;ArticulateTempFileSystem&amp;gt;(
            x =&amp;gt; new ArticulateTempFileSystem(&amp;quot;~/App_Data/Temp/Articulate&amp;quot;));

        // TODO: Register remaining services....
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here's an example of a rendered js code fence:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-js"&gt;(function () {
    'use strict';

    /**
     * An example of the articulateOptionsManagementController
     * @param {any} $scope
     * @param {any} $element
     * @param {any} $timeout
     */
    function articulateOptionsManagementController($scope, $element, $timeout) {

        var vm = this;
        vm.viewState = &amp;quot;list&amp;quot;;
        vm.selectedGroup = null;
        
        // TODO: Fill in the rest....
    }

    var articulateOptionsMgmtComponent = {
        templateUrl: '../../App_Plugins/Articulate/BackOffice/PackageOptions/articulatemgmt.html',        
        controllerAs: 'vm',
        controller: articulateOptionsManagementController
    };

    angular.module(&amp;quot;umbraco&amp;quot;)
        .component('articulateOptionsMgmt', articulateOptionsMgmtComponent);
})();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here's an example of a rendered ruby code fence:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-ruby"&gt;class Dog  
  def initialize(breed, name)  
    # Instance variables  
    @breed = breed  
    @name = name  
  end  
  
  def bark  
    puts 'Ruff! Ruff!'  
  end  
  
  def display  
    puts &amp;quot;I am of #{@breed} breed and my name is #{@name}&amp;quot;  
  end  
end
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Thu, 23 Mar 2023 15:10:26 Z</pubDate>
      <a10:updated>2023-03-23T15:10:26Z</a10:updated>
    </item>
  </channel>
</rss>