Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added HTMLNode.toHTML(), HTMLNode.toString() [bryan]

  • Loading branch information...
commit 04effbdeda31937976a1af9994bd18140cccba31 1 parent f53551d
George Moschovitis authored
6 README.md
Source Rendered
@@ -23,11 +23,15 @@ Usage
23 23 print(el.innerHTML);
24 24 });
25 25
  26 + print(document.toHTML());
  27 + print(document);
  28 +
26 29
27 30 Credits
28 31 -------
29 32
30 33 * George Moschovitis <george.moschovitis@gmail.com>
  34 +* Bryan Berry <bryan@olenepal.org>
31 35
32 36 Java HTML Parser
33 37
@@ -39,7 +43,7 @@ Java HTML Parser
39 43 License
40 44 -------
41 45
42   -Copyright (c) 2009 George Moschovitis, http://www.gmosx.com
  46 +Copyright (c) 2009-2010 George Moschovitis, [http://www.gmosx.com](http://www.gmosx.com)
43 47
44 48 Permission is hereby granted, free of charge, to any person obtaining a copy
45 49 of this software and associated documentation files (the "Software"), to
33 engines/rhino/lib/htmlparser.js
@@ -25,7 +25,9 @@ var HTMLParser = exports.HTMLParser = function(options) {
25 25 }
26 26
27 27 HTMLParser.prototype.parseRaw = function(html) {
28   - return jparser.parse(new JInputSource(new JStringReader(html)));
  28 + var source = new JInputSource(new JStringReader(html));
  29 +// source.setEncoding("UTF-8");
  30 + return jparser.parse(source);
29 31 }
30 32
31 33 HTMLParser.prototype.parse = function(html) {
@@ -39,6 +41,10 @@ var HTMLNode = function(jnode) {
39 41 this._raw = jnode;
40 42 }
41 43
  44 +HTMLNode.prototype.getChildNodes = function() {
  45 + return _nodelistToArray(this._raw.getChildNodes());
  46 +}
  47 +
42 48 Object.defineProperty(HTMLNode.prototype, "nodeName", {
43 49 get: function() {
44 50 return String(this._raw.getNodeName());
@@ -57,6 +63,23 @@ Object.defineProperty(HTMLNode.prototype, "nodeValue", {
57 63 }
58 64 });
59 65
  66 +HTMLNode.prototype.toString = function() {
  67 + return this.nodeName;
  68 +}
  69 +
  70 +var JDom2Sax = Packages.nu.validator.htmlparser.dom.Dom2Sax,
  71 + JHtmlSerializer = Packages.nu.validator.htmlparser.sax.HtmlSerializer,
  72 + JStringWriter = Packages.java.io.StringWriter;
  73 +
  74 +HTMLNode.prototype.toHTML = function() {
  75 + var w = new JStringWriter(),
  76 + s = new JHtmlSerializer(w);
  77 +
  78 + new JDom2Sax(s, s).parse(this._raw);
  79 +
  80 + return String(w.toString());
  81 +}
  82 +
60 83 /**
61 84 * HTML Document.
62 85 */
@@ -153,6 +176,12 @@ HTMLElement.prototype.hasAttribute = function(name) {
153 176 return this._raw.hasAttribute(name);
154 177 }
155 178
  179 +Object.defineProperty(HTMLElement.prototype, "href", {
  180 + get: function() {
  181 + return String(this.getAttribute("href"));
  182 + }
  183 +});
  184 +
156 185 Object.defineProperty(HTMLElement.prototype, "innerHTML", {
157 186 get: function() {
158 187 return String(this._raw.getTextContent());
@@ -231,5 +260,3 @@ var _nodelistToArray = function(nodelist) {
231 260
232 261 return arr;
233 262 }
234   -
235   -
5 lib/sizzle.js
... ... @@ -1,4 +1,5 @@
1 1 exports.sizzle = function(document) {
  2 + var window = exports;
2 3
3 4
4 5 /*!
@@ -1014,11 +1015,11 @@ var posProcess = function(selector, context){
1014 1015 };
1015 1016
1016 1017 // EXPOSE
1017   -// window.Sizzle = Sizzle;
1018   -exports.Sizzle = Sizzle;
  1018 +window.Sizzle = Sizzle;
1019 1019
1020 1020 })();
1021 1021
1022 1022
  1023 +
1023 1024 return exports.Sizzle;
1024 1025 }

0 comments on commit 04effbd

Please sign in to comment.
Something went wrong with that request. Please try again.