linkedomAdaptor.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. Object.defineProperty(exports, "__esModule", { value: true });
  18. exports.linkedomAdaptor = exports.LinkedomAdaptor = void 0;
  19. var HTMLAdaptor_js_1 = require("./HTMLAdaptor.js");
  20. var NodeMixin_js_1 = require("./NodeMixin.js");
  21. var LinkedomAdaptor = (function (_super) {
  22. __extends(LinkedomAdaptor, _super);
  23. function LinkedomAdaptor() {
  24. return _super !== null && _super.apply(this, arguments) || this;
  25. }
  26. LinkedomAdaptor.prototype.parse = function (text, format) {
  27. if (format === void 0) { format = 'text/html'; }
  28. if (!text.match(/^(?:\s|\n)*</))
  29. text = '<html>' + text + '</html>';
  30. return this.parser.parseFromString(text, format);
  31. };
  32. LinkedomAdaptor.prototype.serializeXML = function (node) {
  33. return this.outerHTML(node);
  34. };
  35. return LinkedomAdaptor;
  36. }((0, NodeMixin_js_1.NodeMixin)(HTMLAdaptor_js_1.HTMLAdaptor)));
  37. exports.LinkedomAdaptor = LinkedomAdaptor;
  38. function linkedomAdaptor(parseHTML, options) {
  39. if (options === void 0) { options = null; }
  40. var window = parseHTML('<html></html>');
  41. window.constructor.prototype.HTMLCollection = (function () {
  42. function HTMLCollection() {
  43. }
  44. return HTMLCollection;
  45. }());
  46. return new LinkedomAdaptor(window, options);
  47. }
  48. exports.linkedomAdaptor = linkedomAdaptor;
  49. //# sourceMappingURL=linkedomAdaptor.js.map