XMLText.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Generated by CoffeeScript 2.4.1
  2. (function() {
  3. var NodeType, XMLCharacterData, XMLText;
  4. NodeType = require('./NodeType');
  5. XMLCharacterData = require('./XMLCharacterData');
  6. // Represents a text node
  7. module.exports = XMLText = (function() {
  8. class XMLText extends XMLCharacterData {
  9. // Initializes a new instance of `XMLText`
  10. // `text` element text
  11. constructor(parent, text) {
  12. super(parent);
  13. if (text == null) {
  14. throw new Error("Missing element text. " + this.debugInfo());
  15. }
  16. this.name = "#text";
  17. this.type = NodeType.Text;
  18. this.value = this.stringify.text(text);
  19. }
  20. // Creates and returns a deep clone of `this`
  21. clone() {
  22. return Object.create(this);
  23. }
  24. // Converts the XML fragment to string
  25. // `options.pretty` pretty prints the result
  26. // `options.indent` indentation for pretty print
  27. // `options.offset` how many indentations to add to every line for pretty print
  28. // `options.newline` newline sequence for pretty print
  29. toString(options) {
  30. return this.options.writer.text(this, this.options.writer.filterOptions(options));
  31. }
  32. // DOM level 1 functions to be implemented later
  33. splitText(offset) {
  34. throw new Error("This DOM method is not implemented." + this.debugInfo());
  35. }
  36. // DOM level 3 functions to be implemented later
  37. replaceWholeText(content) {
  38. throw new Error("This DOM method is not implemented." + this.debugInfo());
  39. }
  40. };
  41. // DOM level 3
  42. Object.defineProperty(XMLText.prototype, 'isElementContentWhitespace', {
  43. get: function() {
  44. throw new Error("This DOM method is not implemented." + this.debugInfo());
  45. }
  46. });
  47. Object.defineProperty(XMLText.prototype, 'wholeText', {
  48. get: function() {
  49. var next, prev, str;
  50. str = '';
  51. prev = this.previousSibling;
  52. while (prev) {
  53. str = prev.data + str;
  54. prev = prev.previousSibling;
  55. }
  56. str += this.data;
  57. next = this.nextSibling;
  58. while (next) {
  59. str = str + next.data;
  60. next = next.nextSibling;
  61. }
  62. return str;
  63. }
  64. });
  65. return XMLText;
  66. }).call(this);
  67. }).call(this);