You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XMLStringWriter.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Generated by CoffeeScript 2.4.1
  2. (function() {
  3. var XMLStringWriter, XMLWriterBase;
  4. XMLWriterBase = require('./XMLWriterBase');
  5. // Prints XML nodes as plain text
  6. module.exports = XMLStringWriter = class XMLStringWriter extends XMLWriterBase {
  7. // Initializes a new instance of `XMLStringWriter`
  8. // `options.pretty` pretty prints the result
  9. // `options.indent` indentation string
  10. // `options.newline` newline sequence
  11. // `options.offset` a fixed number of indentations to add to every line
  12. // `options.allowEmpty` do not self close empty element tags
  13. // 'options.dontPrettyTextNodes' if any text is present in node, don't indent or LF
  14. // `options.spaceBeforeSlash` add a space before the closing slash of empty elements
  15. constructor(options) {
  16. super(options);
  17. }
  18. document(doc, options) {
  19. var child, i, len, r, ref;
  20. options = this.filterOptions(options);
  21. r = '';
  22. ref = doc.children;
  23. for (i = 0, len = ref.length; i < len; i++) {
  24. child = ref[i];
  25. r += this.writeChildNode(child, options, 0);
  26. }
  27. // remove trailing newline
  28. if (options.pretty && r.slice(-options.newline.length) === options.newline) {
  29. r = r.slice(0, -options.newline.length);
  30. }
  31. return r;
  32. }
  33. };
  34. }).call(this);