(function($) {
    $.widget("ouvigna.indexify", {
        $source: null,
        $destination: null,
        mode: null,
        options: {
            source: null,
            destination: null,
            mode: null
        },
    
        _create: function() {
            this._setOptions();
            var items = this._findItems();
            this._buildHTML(items);
        },

        _setOptions: function() {
            this.$destination = this.element;
            this.$source = (this.options.source === null)?
                this.element:
                $(this.options.source);
            this.mode = (this.options.mode === null)?
                "html":
                this.options.mode;
        },

        _findItems: function(level, $from) {
            var _self = this,
                items = [];

            level = level == undefined?1:level;
            if (level == 1)
            {
                $("h" + level, this.$source).each(function() {
                    var $this = $(this);
                    items.push({"$element": $this,
                                "children": _self._findItems(level + 1, $this)});
                });
            }
            else
            {
                $limit = $($from.nextAll("h" + (level-1)).get(0));
                $from.nextUntil($limit, "h" + level).each(function() {
                    var $this = $(this);
                    items.push({"$element": $this,
                                "children": _self._findItems(level + 1, $this)});
                });
            }
            return items;
        },

        _buildHTML: function(items) {
            var $listItems = $("<ul>");
            $.each(items, function() {
                var $item = $("<li>").
                    html(this.$element.html()).
                    appendTo($listItems);
            });

            if (typeof this.$destination[this.mode] === "function")
            {
                this.$destination[this.mode]($listItems);
            }
        }
    });
})(jQuery);

@@ -805,16 +805,42 @@
     var 
+headers,%0D%0A                
 _self = 
@@ -905,16 +905,17 @@
 level ==
+=
  undefin
@@ -986,16 +986,26 @@
         
+ headers =
  $(%22h%22 +
@@ -1029,223 +1029,8 @@
 rce)
-.each(function() %7B%0D%0A                    var $this = $(this);%0D%0A                    items.push(%7B%22$element%22: $this,%0D%0A                                %22children%22: _self._findItems(level + 1, $this)%7D);%0D%0A                %7D)
 ;%0D%0A 
@@ -1159,16 +1159,26 @@
         
+ headers =
  $from.n
@@ -1206,16 +1206,53 @@
 + level)
+;%0D%0A            %7D%0D%0A            headers
 .each(fu
@@ -1255,36 +1255,32 @@
 h(function() %7B%0D%0A
-    
                 
@@ -1313,28 +1313,24 @@
             
-    
 items.push(%7B
@@ -1377,20 +1377,16 @@
         
- 
-   
 %22childre
@@ -1444,30 +1444,13 @@
     
-    
 %7D);%0D%0A
-            %7D
 %0D%0A  

Remove some duplicate code