Index: modules/markdown/markdown.tcl
==================================================================
--- modules/markdown/markdown.tcl
+++ modules/markdown/markdown.tcl
@@ -167,34 +167,31 @@
                     # HORIZONTAL RULES
                     append result "<hr />"
                     incr index
                 }
                 {^[ ]{0,3}#{1,6}} {
-                    # ATX STYLE HEADINGS
+                    # ATX STYLE HEADERS
                     set h_level 0
                     set h_result {}
 
-                    while {$index < $no_lines && ![is_empty_line $line]} {
-                        incr index
+                    if {!$h_level} {
+                        regexp {^\s*#+} $line m
+                        set h_level [string length [string trim $m]]
+                    }
 
-                        if {!$h_level} {
-                            regexp {^\s*#+} $line m
-                            set h_level [string length [string trim $m]]
-                        }
+                    lappend h_result $line
 
-                        lappend h_result $line
-
-                        set line [lindex $lines $index]
-                    }
+                     set line [lindex $lines $index]
 
                     set h_result [\
                         parse_inline [\
                             regsub -all {^\s*#+\s*|\s*#+\s*$} [join $h_result \n] {} \
                         ]\
                     ]
 
                     append result "<h$h_level>$h_result</h$h_level>"
+                    incr index
                 }
                 {^[ ]{0,3}\>} {
                     # BLOCK QUOTES
                     set bq_result {}
 
@@ -570,11 +567,11 @@
                             break
                         }
                     }
                 }
                 default {
-                    # PARAGRAPHS AND SETTEXT STYLE HEADERS
+                    # PARAGRAPHS AND SETEXT STYLE HEADERS
                     set p_type p
                     set p_result {}
 
                     while {($index < $no_lines) && ![is_empty_line $line]} \
                     {

