<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>middleman on Andrés Álvarez</title>
    <link>https://aalvrz.me/tags/middleman/</link>
    <description>Recent content in middleman on Andrés Álvarez</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 17 Nov 2016 00:00:00 +0000</lastBuildDate>
    
	<atom:link href="https://aalvrz.me/tags/middleman/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Custom Markdown in Middleman</title>
      <link>https://aalvrz.me/posts/custom-markdown-in-middleman/</link>
      <pubDate>Thu, 17 Nov 2016 00:00:00 +0000</pubDate>
      
      <guid>https://aalvrz.me/posts/custom-markdown-in-middleman/</guid>
      <description>&lt;p&gt;&lt;a href=&#34;https://middlemanapp.com/&#34;&gt;Middleman&lt;/a&gt; is an excellent static site generator written in Ruby. It is extremely practical for blogging as well, and it&#39;s the framework I am currently using for this blog.&lt;/p&gt;
&lt;p&gt;Unfortunately Middleman&#39;s &lt;a href=&#34;https://middlemanapp.com/basics/install/&#34;&gt;documentation&lt;/a&gt; is a bit unorganized and incomplete. I often find myself browsing through the &lt;a href=&#34;https://github.com/middleman/middleman&#34;&gt;source code&lt;/a&gt; to understand how to use or implement some custom features.&lt;/p&gt;
&lt;p&gt;For example, using &lt;a href=&#34;https://github.com/vmg/redcarpet&#34;&gt;redcarpet&lt;/a&gt; I wanted to be able to create some re-usable &amp;ldquo;markdown components&amp;rdquo; that I could use in my blog posts. Something like bootstrap alerts, so that I could re-use them without having to add HTML or any code to my markdown.&lt;/p&gt;
&lt;p&gt;And this post I am going to explain how to integrate this functionality into your blog using Middleman.&lt;/p&gt;
&lt;h2 id=&#34;creating-a-custom-renderer&#34;&gt;Creating a Custom Renderer&lt;/h2&gt;
&lt;p&gt;Middleman comes built in with a custom Redcarpet renderer which Middleman uses to parse the links and images (and possibly other things) in your blog&#39;s markdown. To be able to implement our custom markdown we need to create our own custom renderer, which should inherit from &lt;code&gt;Redcarpet::Render::HTML&lt;/code&gt;. However, the &lt;strong&gt;key&lt;/strong&gt; thing here is to actually inherit directly from &lt;a href=&#34;https://github.com/middleman/middleman/blob/master/middleman-core/lib/middleman-core/renderers/redcarpet.rb#L65&#34;&gt;Middleman&#39;s renderer&lt;/a&gt; (which of course, inherits from &lt;code&gt;Redcarpet::Render::HTML&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;To begin, we will create a &lt;code&gt;lib&lt;/code&gt; (if it doesn&#39;t exist) under our blog&#39;s directory and create a file named &lt;code&gt;markdown_helper.rb&lt;/code&gt; inside it. The initial contents of this helper will be:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span style=&#34;color:#00a8c8&#34;&gt;module&lt;/span&gt; &lt;span style=&#34;color:#111&#34;&gt;MarkdownHelper&lt;/span&gt;

  &lt;span style=&#34;color:#111&#34;&gt;require&lt;/span&gt; &lt;span style=&#34;color:#d88200&#34;&gt;&amp;#39;middleman-core/renderers/redcarpet&amp;#39;&lt;/span&gt;

&lt;span style=&#34;color:#00a8c8&#34;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The required file above is what will allow us to inherit from Middleman&#39;s renderer.&lt;/p&gt;</description>
    </item>
    
  </channel>
</rss>