index.js 697 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const Parser = require('./parser');
  3. const Serializer = require('./serializer');
  4. // Shorthands
  5. exports.parse = function parse(html, options) {
  6. const parser = new Parser(options);
  7. return parser.parse(html);
  8. };
  9. exports.parseFragment = function parseFragment(fragmentContext, html, options) {
  10. if (typeof fragmentContext === 'string') {
  11. options = html;
  12. html = fragmentContext;
  13. fragmentContext = null;
  14. }
  15. const parser = new Parser(options);
  16. return parser.parseFragment(html, fragmentContext);
  17. };
  18. exports.serialize = function(node, options) {
  19. const serializer = new Serializer(node, options);
  20. return serializer.serialize();
  21. };