title: Parsing subset of markdown with regex
body: <p>To display comments on my blog, I want to parse just a subset of markdown. Namely, links, inline code, code blocks and paragraphs.</p>
  
  <p>I'm having a hard time with fenced code blocks because the regex collide with both the one for inline code and paragraphs.</p>
  
  <p>Here is my function:</p>
  
  <pre><code>function parseMd(text) {
      const codeblock = /```([^]+?.*?[^]+?[^]+?)```/g
      const code = /`(.*?)`/g
      const link = /\[(.*?)\]\((.*?)\)/g
      const paragraph = /(.+((\r?\n.+)*))/g
  
      return text.replace(codeblock, '&lt;pre&gt;&lt;code&gt;$1&lt;/code&gt;&lt;/pre&gt;')
      .replace(code, '&lt;code&gt;$1&lt;/code&gt;')
      .replace(link, '&lt;a href="$2"&gt;$1&lt;/a&gt;')
      .replace(paragraph, '&lt;p&gt;$1&lt;/p&gt;');
  }
  </code></pre>
  
  <p>Ideally, I'd need <code>code</code> and <code>paragraph</code> regexes to ignore eveyrhing that matches <code>codeblock</code>, but as it's a multi-line one, it's getting tricky!</p>