Ignore:
Timestamp:
2012-01-09T11:20:24+13:00 (12 years ago)
Author:
davidb
Message:

Shift from generating string to JSON tree for output

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/html-to-expeditee/trunk/src/src/js/html-to-expeditee.js

    r24917 r24925  
    8989    depth = (depth) ? depth : 0;
    9090
    91     var expSyntax = "";
     91    //var expSyntax = "";
     92    var jsonNode = {};
    9293
    9394    if (node.nodeType == 3) { /* text node */
     
    9596
    9697        if (text.match(/\S/)) {
    97         for (var i=0; i<depth; i++) { expSyntax += "  "; }
    98         expSyntax += "Text item: " + node.nodeValue + "\n";
     98        //for (var i=0; i<depth; i++) { expSyntax += "  "; }
     99        //expSyntax += "Text item: " + node.nodeValue + "\n";
     100
     101        jsonNode.type = "text";
     102        jsonNode.text = node.nodeValue;
    99103    }
    100104    }
     
    114118        var yb = nodePos.yb;
    115119
     120/*
    116121        var rectSyntax = "";
     122
    117123        for (var i=0; i<depth; i++) { rectSyntax += "  "; }
     124
    118125        rectSyntax += "Rect item " + node.nodeName + ": ";
    119126        rectSyntax += xl + " " + yt + " " + xr + " " + yb + "\n";
    120127
    121128        expSyntax += rectSyntax;
     129*/
     130
     131        var rect = { "xl":xl, "yt":yt, "xr":xr, "yb":yb };
     132
     133        jsonNode.type = "rect";
     134            jsonNode.elem = node.nodeName;
     135        jsonNode.rect = rect;
     136   
     137            var jsonChildNodes = [];
    122138
    123139        var cnode = node.firstChild;
    124140        while (cnode != null) {
    125         expSyntax += htmlToExpeditee(cnode,depth+1); 
     141        //expSyntax += htmlToExpeditee(cnode,depth+1); 
     142
     143            var jsonChildNode = htmlToExpeditee(cnode,depth+1);
     144        jsonChildNodes.push(jsonChildNode); 
    126145       
    127         cnode = cnode.nextSibling ;
     146        cnode = cnode.nextSibling;
    128147        }
    129148
     149        jsonNode.childNodes = jsonChildNodes;
    130150    }
    131151
     
    133153    /* currently do nothing for the other node types */
    134154
    135     return expSyntax;
     155    return jsonNode;
     156    //return expSyntax;
    136157}
    137158
Note: See TracChangeset for help on using the changeset viewer.