<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -189,22 +189,45 @@ static Line *
 htmlblock(Paragraph *p, char *tag)
 {
     Line *t = p-&gt;text, *ret;
-    int closesize;
+    int closesize, tagsize;
     char close[MAXTAG+4];
 
-    if ( selfclose(t, tag) || (strlen(tag) &gt;= MAXTAG) ) {
+    char *ps, *pse;
+    int depth;
+
+    tagsize = strlen(tag);
+
+    if ( selfclose(t, tag) || (tagsize &gt;= MAXTAG) ) {
 	ret = t-&gt;next;
 	t-&gt;next = 0;
 	return ret;
     }
 
     closesize = sprintf(close, &quot;&lt;/%s&gt;&quot;, tag);
+    depth = 0;
 
     for ( ; t ; t = t-&gt;next) {
-	if ( T(t-&gt;text)[0] == '&lt;' &amp;&amp; strcasestr(T(t-&gt;text), close) != NULL ) {
-	    ret = t-&gt;next;
-	    t-&gt;next = 0;
-	    return ret;
+	ps = T(t-&gt;text);
+	pse = ps + (S(t-&gt;text) - (tagsize + 1));
+	for ( ; ps &lt; pse; ps++ ) {
+	    if ( *ps == '&lt;' ) {
+	        /* check for close tag */
+	        if ( strncasecmp(ps, close, closesize) == 0 ) {
+	            depth--;
+	            if ( depth == 0 ) {
+	                ret = t-&gt;next;
+	                t-&gt;next = 0;
+	                return ret;
+	            }
+	            continue;
+	        }
+
+	        /* check for nested open tag */
+	        if ( (strncasecmp(ps + 1, tag, tagsize) == 0) &amp;&amp;
+	             (ps[tagsize + 1] == '&gt;' || ps[tagsize + 1] == ' ') ) {
+	            depth++;
+	        }
+	    }
 	}
     }
     return 0;</diff>
      <filename>ext/markdown.c</filename>
    </modified>
    <modified>
      <diff>@@ -82,6 +82,12 @@ class MarkdownTest &lt; Test::Unit::TestCase
     assert_equal &quot;&lt;p&gt;&lt;a href=\&quot;/search?query=Markdown+Test&amp;amp;page=2\&quot;&gt;Page 2&lt;/a&gt;&lt;/p&gt;\n&quot;, markdown.to_html
   end
 
+  def test_simple_inline_html
+    markdown = Markdown.new(&quot;before\n\n&lt;div&gt;\n  foo\n&lt;/div&gt;\nafter&quot;)
+    assert_equal &quot;&lt;p&gt;before&lt;/p&gt;\n\n&lt;div&gt;\n  foo\n&lt;/div&gt;\n\n\n&lt;p&gt;after&lt;/p&gt;\n&quot;,
+      markdown.to_html
+  end
+
   def test_that_html_blocks_do_not_require_their_own_end_tag_line
     markdown = Markdown.new(&quot;Para 1\n\n&lt;div&gt;&lt;pre&gt;HTML block\n&lt;/pre&gt;&lt;/div&gt;\n\nPara 2 [Link](#anchor)&quot;)
     assert_equal &quot;&lt;p&gt;Para 1&lt;/p&gt;\n\n&lt;div&gt;&lt;pre&gt;HTML block\n&lt;/pre&gt;&lt;/div&gt;\n\n\n&lt;p&gt;Para 2 &lt;a href=\&quot;#anchor\&quot;&gt;Link&lt;/a&gt;&lt;/p&gt;\n&quot;,</diff>
      <filename>test/markdown_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ce243b65f072b5f141c60b69db5cf4df01ed93b1</id>
    </parent>
  </parents>
  <author>
    <name>Ryan Tomayko</name>
    <email>rtomayko@gmail.com</email>
  </author>
  <url>http://github.com/rtomayko/rdiscount/commit/5d452caeff8373a1983e60d790a3dc406275ba18</url>
  <id>5d452caeff8373a1983e60d790a3dc406275ba18</id>
  <committed-date>2009-03-18T05:53:57-07:00</committed-date>
  <authored-date>2009-03-18T05:53:56-07:00</authored-date>
  <message>Detect end tags anywhere on a line; account for nesting</message>
  <tree>2285bf9ce197b52b168b3a1c6770c1eabf216d91</tree>
  <committer>
    <name>Ryan Tomayko</name>
    <email>rtomayko@gmail.com</email>
  </committer>
</commit>
