title: How to enable code folding for markdown in TextMate?
body: <p>I would like to enable code folding for markdown in textmate.</p>
  
  <p>Specifically, I would like any headings (text preceded by one or more '#' characters) to be the line that would toggle blocks between it and the next heading and/or horizontal rule. Example:</p>
  
  <pre><code># Level 1 Heading - I'd like the block below to fold
  
  The text I'd like to fold away
  
  ## Level 2 Heading
  
  More text...
  </code></pre>
  
  <p>BBEdit seems to do this just fine for markdown. TextMate supports code folding just fine for languages that denote blocks with paired (and identically indented) curly braces.</p>
  
  <p>I know TextMate offers two variables you can set in the language grammar file, but I'd need more talent with regular expressions than I possess to figure it out. Following is what currently resides in the markdown language grammar for the code folding settings:</p>
  
  <pre><code>foldingStartMarker = '(?x)
      (&lt;(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|form|dl)\b.*?&gt;
      |&lt;!--(?!.*--&gt;)
      |\{\s*($|\?&gt;\s*$|//|/\*(.*\*/\s*$|(?!.*?\*/)))
      )';
  foldingStopMarker = '(?x)
      (&lt;/(?i:head|body|table|thead|tbody|tfoot|tr|div|select|fieldset|style|script|ul|ol|form|dl)&gt;
      |^\s*--&gt;
      |(^|\s)\}
      )';
  </code></pre>
  
  <p><strong>Any help greatly appreciated!</strong> </p>