Index: trunk/parsers/wikidom/lib/es/es.ParagraphBlock.js |
— | — | @@ -181,8 +181,8 @@ |
182 | 182 | |
183 | 183 | es.ParagraphBlock.prototype.getWikiDom = function() { |
184 | 184 | return { |
185 | | - lines: this.content.getWikiDomLines(), |
186 | | - type: 'paragraph' |
| 185 | + type: 'paragraph', |
| 186 | + lines: this.content.getWikiDomLines() |
187 | 187 | }; |
188 | 188 | }; |
189 | 189 | |
Index: trunk/parsers/wikidom/lib/FormatJSON.js |
— | — | @@ -0,0 +1,81 @@ |
| 2 | +function RealTypeOf(v) {
|
| 3 | + if (typeof (v) == "object") {
|
| 4 | + if (v === null) return "null";
|
| 5 | + if (v.constructor == (new Array).constructor) return "array";
|
| 6 | + if (v.constructor == (new Date).constructor) return "date";
|
| 7 | + if (v.constructor == (new RegExp).constructor) return "regex";
|
| 8 | + return "object";
|
| 9 | + }
|
| 10 | + return typeof (v);
|
| 11 | +}
|
| 12 | +function FormatJSON(oData, sIndent) {
|
| 13 | + if (arguments.length < 2) {
|
| 14 | + var sIndent = "";
|
| 15 | + }
|
| 16 | + var sIndentStyle = " ";
|
| 17 | + var sDataType = RealTypeOf(oData);
|
| 18 | +
|
| 19 | + // open object
|
| 20 | + if (sDataType == "array") {
|
| 21 | + if (oData.length == 0) {
|
| 22 | + return "[]";
|
| 23 | + }
|
| 24 | + var sHTML = "[";
|
| 25 | + } else {
|
| 26 | + var iCount = 0;
|
| 27 | + $.each(oData, function () {
|
| 28 | + iCount++;
|
| 29 | + return;
|
| 30 | + });
|
| 31 | + if (iCount == 0) { // object is empty
|
| 32 | + return "{}";
|
| 33 | + }
|
| 34 | + var sHTML = "{";
|
| 35 | + }
|
| 36 | +
|
| 37 | + // loop through items
|
| 38 | + var iCount = 0;
|
| 39 | + $.each(oData, function (sKey, vValue) {
|
| 40 | + if (iCount > 0) {
|
| 41 | + sHTML += ",";
|
| 42 | + }
|
| 43 | + if (sDataType == "array") {
|
| 44 | + sHTML += ("\n" + sIndent + sIndentStyle);
|
| 45 | + } else {
|
| 46 | + sHTML += ("\n" + sIndent + sIndentStyle + "\"" + sKey + "\"" + ": ");
|
| 47 | + }
|
| 48 | +
|
| 49 | + // display relevant data type
|
| 50 | + switch (RealTypeOf(vValue)) {
|
| 51 | + case "array":
|
| 52 | + case "object":
|
| 53 | + sHTML += FormatJSON(vValue, (sIndent + sIndentStyle));
|
| 54 | + break;
|
| 55 | + case "boolean":
|
| 56 | + case "number":
|
| 57 | + sHTML += vValue.toString();
|
| 58 | + break;
|
| 59 | + case "null":
|
| 60 | + sHTML += "null";
|
| 61 | + break;
|
| 62 | + case "string":
|
| 63 | + sHTML += ("\"" + vValue + "\"");
|
| 64 | + break;
|
| 65 | + default:
|
| 66 | + sHTML += ("TYPEOF: " + typeof (vValue));
|
| 67 | + }
|
| 68 | +
|
| 69 | + // loop
|
| 70 | + iCount++;
|
| 71 | + });
|
| 72 | +
|
| 73 | + // close object
|
| 74 | + if (sDataType == "array") {
|
| 75 | + sHTML += ("\n" + sIndent + "]");
|
| 76 | + } else {
|
| 77 | + sHTML += ("\n" + sIndent + "}");
|
| 78 | + }
|
| 79 | +
|
| 80 | + // return
|
| 81 | + return sHTML;
|
| 82 | +} |
\ No newline at end of file |
Index: trunk/parsers/wikidom/demos/es/index2.html |
— | — | @@ -39,7 +39,7 @@ |
40 | 40 | width: 95%;
|
41 | 41 | margin: auto;
|
42 | 42 | }
|
43 | | - #wikitext-source {
|
| 43 | + .source {
|
44 | 44 | min-height: 150px;
|
45 | 45 | margin: 0;
|
46 | 46 | padding: 1em;
|
— | — | @@ -69,13 +69,16 @@ |
70 | 70 | <td width="50%">
|
71 | 71 | <div id="source-wrapper">
|
72 | 72 | <h3>Wikitext Source</h3>
|
73 | | - <div id="wikitext-source"></div>
|
| 73 | + <div id="wikitext-source" class="source"></div>
|
| 74 | + <h3>JSON Source</h3>
|
| 75 | + <div id="json-source" class="source"></div>
|
74 | 76 | </div>
|
75 | 77 | </td>
|
76 | 78 | </tr>
|
77 | 79 | </table>
|
78 | 80 |
|
79 | 81 | <script type="text/javascript" src="../../lib/jquery.js"></script>
|
| 82 | + <script type="text/javascript" src="../../lib/jquery.json.js"></script>
|
80 | 83 | <script type="text/javascript" src="../../lib/es/es.js"></script>
|
81 | 84 | <script type="text/javascript" src="../../lib/es/es.EventEmitter.js"></script>
|
82 | 85 | <script type="text/javascript" src="../../lib/es/es.Position.js"></script>
|
— | — | @@ -93,7 +96,7 @@ |
94 | 97 | <script type="text/javascript" src="../../lib/es/es.ListBlockItem.js"></script>
|
95 | 98 | <script type="text/javascript" src="../../lib/es/es.ListBlock.js"></script>
|
96 | 99 | <script type="text/javascript" src="../../lib/es/es.Cursor.js"></script>
|
97 | | -
|
| 100 | + <script type="text/javascript" src="../../lib/FormatJSON.js"></script>
|
98 | 101 | <script src="../../lib/wiki.js" type="text/javascript"></script>
|
99 | 102 | <script src="../../lib/wiki.util.js" type="text/javascript"></script>
|
100 | 103 | <script src="../../lib/wiki.AnnotationRenderer.js" type="text/javascript"></script>
|
— | — | @@ -317,8 +320,9 @@ |
318 | 321 | clearTimeout( previewTimeout );
|
319 | 322 | }
|
320 | 323 | previewTimeout = setTimeout( function () {
|
321 | | - console.log(doc.getWikiDomDocument());
|
322 | | - $( '#wikitext-source' ).text( wikitextRenderer.render( doc.getWikiDomDocument() ) );
|
| 324 | + var data = doc.getWikiDomDocument();
|
| 325 | + $( '#wikitext-source' ).text( wikitextRenderer.render( data ) );
|
| 326 | + $( '#json-source' ).text( FormatJSON( data ) );
|
323 | 327 | }, 100 );
|
324 | 328 | } );
|
325 | 329 |
|