<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Alexander Harris</title>
    <description>The latest articles on Forem by Alexander Harris (@alexandermlharris).</description>
    <link>https://forem.com/alexandermlharris</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F293369%2F6f317a0f-07d3-4b14-a22b-e63b10bbac9b.png</url>
      <title>Forem: Alexander Harris</title>
      <link>https://forem.com/alexandermlharris</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/alexandermlharris"/>
    <language>en</language>
    <item>
      <title>Technical presentations with Marp and Mermaid</title>
      <dc:creator>Alexander Harris</dc:creator>
      <pubDate>Tue, 22 Aug 2023 09:51:26 +0000</pubDate>
      <link>https://forem.com/alexandermlharris/technical-presentations-with-marp-and-mermaid-2hmp</link>
      <guid>https://forem.com/alexandermlharris/technical-presentations-with-marp-and-mermaid-2hmp</guid>
      <description>&lt;p&gt;I recently started learning to use &lt;a href="https://github.com/marp-team/marp"&gt;Marp&lt;/a&gt; to create presentations / slide decks using Markdown syntax. I've always liked Markdown as a writing format and was curious to try creating a presentation instead of PowerPoint.&lt;/p&gt;

&lt;p&gt;One thing that I found challanging was dealing with diagrams, which I tend to use a lot of. Typically use my diagram tool of choice then take a screen snip, or export the digram as an image and embed in my presentation.&lt;/p&gt;

&lt;p&gt;In PowerPoint, copy+paste support makes this workflow pretty straight forward but for Markdown documents I found organizing a set of images to include a bit annoying.&lt;/p&gt;

&lt;p&gt;Then I was reading this excellent &lt;a href="https://chris-ayers.com/2023/03/31/customizing-marp#:~:text=Marp%20comes%20with%20three%20built,and%20a%20few%20inverted%20examples"&gt;blog post&lt;/a&gt; on customizing Marp where it explained how to integrate &lt;a href="http://mermaid.js.org/"&gt;Mermaid&lt;/a&gt; diagrams.&lt;/p&gt;

&lt;p&gt;Mermaid is another tool that I'd seen recently used for embedded diagrams in github repo readme files and had also been wanting to experiment with.&lt;/p&gt;

&lt;p&gt;I followed the steps outlined and was pretty easily able to integrate Mermaid with Marp and ended up writing my whole presentation with about 15 diagrams in one markdown file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites / Tools
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;I used &lt;a href="https://code.visualstudio.com/"&gt;VS Code&lt;/a&gt; as my editor&lt;/li&gt;
&lt;li&gt;I added the &lt;a href="https://marketplace.visualstudio.com/items?itemName=marp-team.marp-vscode"&gt;Marp for VS Code&lt;/a&gt; plugin to enable Marp features.

&lt;ul&gt;
&lt;li&gt;Checked the &lt;code&gt;Markdown -&amp;gt; Marp: Enable Html&lt;/code&gt; from the extension settings. This allows &lt;code&gt;html&lt;/code&gt; elements / blocks in the source document. Without this they will be encoded and output as text and not treated as Html blocks.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;I added the &lt;a href="https://marketplace.visualstudio.com/items?itemName=bierner.markdown-mermaid"&gt;Markdown Preview Mermaid Support&lt;/a&gt; plugin to enable Mermaid diagram previews in the Marp preview.&lt;/li&gt;
&lt;li&gt;I also installed the &lt;a href="https://github.com/marp-team/marp-cli"&gt;Marp-Cli&lt;/a&gt; so I could script document generation etc. if I wanted to, though this isn't required.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create a new mardown file for your presentation.&lt;/li&gt;
&lt;li&gt;Add the Marp frontmatter block
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---
marp: true
theme: default
---
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add the following script block anywere in your presentation to pull in and initilize Mermaid:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;module&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;mermaid&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;mermaid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;startOnLoad&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add a diagram to a slide
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# My Slide
&amp;lt;div class="mermaid"&amp;gt;
  graph LR;
  a --&amp;gt; b;
  b --&amp;gt; c;
  c --&amp;gt; a;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Use the &lt;code&gt;Markdown: Open Locked Preview to the Side&lt;/code&gt; command from the &lt;code&gt;CTRL + SHIFT + P&lt;/code&gt; actions menu to open the live preview of the document.

&lt;ul&gt;
&lt;li&gt;Click the &lt;code&gt;Some content has been disabled in this document&lt;/code&gt; popup in the top right and then select &lt;code&gt;Allow Insecure Content&lt;/code&gt; to enable Mermaid in the preview.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Use the &lt;code&gt;Marp: Export Slide Deck...&lt;/code&gt; command from the &lt;code&gt;CTRL + SHIFT + P&lt;/code&gt; actions menu to export your slide deck.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Gotchas / Limitations
&lt;/h2&gt;

&lt;p&gt;I found a couple of rough edges still:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I needed to add an empty line after the closing &lt;code&gt;&amp;lt;/div&amp;gt;&lt;/code&gt; tag of my mermaid diagrams or the formatting failed.&lt;/li&gt;
&lt;li&gt;I needed to remove any empty lines between elements in my Mermaid diagrams or they didn't render on export (though the preview was fine)&lt;/li&gt;
&lt;li&gt;The Mermaid diagrams in PDF export didn't size nodes correctly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Complete Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="na"&gt;marp&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
&lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;default&lt;/span&gt;
&lt;span class="nn"&gt;---&lt;/span&gt;
&lt;span class="gh"&gt;# Title Page&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"module"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
  mermaid.initialize({ startOnLoad: true });
&lt;span class="gh"&gt;&amp;lt;/script&amp;gt;
---
# Diagram&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mermaid&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  graph LR;
  a --&amp;gt; b;
  b --&amp;gt; c;
  c --&amp;gt; a;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;
---&lt;/span&gt;
&lt;span class="gh"&gt;# Next slide&lt;/span&gt;
&lt;span class="p"&gt;*&lt;/span&gt; Some
&lt;span class="p"&gt;*&lt;/span&gt; text
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PEdZRjc---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/63g8exhpzfwi24lzde7d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PEdZRjc---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/63g8exhpzfwi24lzde7d.png" alt="Image description" width="681" height="1045"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>markdown</category>
      <category>marp</category>
      <category>mermaid</category>
    </item>
    <item>
      <title>Writing to a remote file without vi / nano</title>
      <dc:creator>Alexander Harris</dc:creator>
      <pubDate>Mon, 07 Aug 2023 08:27:00 +0000</pubDate>
      <link>https://forem.com/alexandermlharris/writing-to-a-remote-file-without-vi-nano-imo</link>
      <guid>https://forem.com/alexandermlharris/writing-to-a-remote-file-without-vi-nano-imo</guid>
      <description>&lt;p&gt;If you ever need to quickly paste contents into a file via a shell on linux etc. but don't have a text editor installed (limited distro, jump box etc.) you can use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; myfile.txt &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt;
some test pasted from the cli
pboard including
newlines etc
&lt;/span&gt;&lt;span class="no"&gt;EOF
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cat&lt;/code&gt; - print on std out&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;gt; myfile.txt&lt;/code&gt; - redirect std out to myfile.txt (and overwite the contents)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;&amp;lt; EOF&lt;/code&gt; - Read from the commandline and input will be complete when you see the "EOF" string.&lt;/li&gt;
&lt;li&gt;Paste from clipboard (SHIFT+INSERT if CTRL+V doesn't work), type text as needed&lt;/li&gt;
&lt;li&gt;Add one extra newline&lt;/li&gt;
&lt;li&gt;Type "EOF"&lt;/li&gt;
&lt;li&gt;Hit return&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>shell</category>
      <category>beginners</category>
      <category>bash</category>
    </item>
  </channel>
</rss>
