parse.js 946 B

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict'
  2. var content = require('./initialize/content.js')
  3. var document = require('./initialize/document.js')
  4. var flow = require('./initialize/flow.js')
  5. var text = require('./initialize/text.js')
  6. var combineExtensions = require('./util/combine-extensions.js')
  7. var createTokenizer = require('./util/create-tokenizer.js')
  8. var miniflat = require('./util/miniflat.js')
  9. var constructs = require('./constructs.js')
  10. function parse(options) {
  11. var settings = options || {}
  12. var parser = {
  13. defined: [],
  14. constructs: combineExtensions(
  15. [constructs].concat(miniflat(settings.extensions))
  16. ),
  17. content: create(content),
  18. document: create(document),
  19. flow: create(flow),
  20. string: create(text.string),
  21. text: create(text.text)
  22. }
  23. return parser
  24. function create(initializer) {
  25. return creator
  26. function creator(from) {
  27. return createTokenizer(parser, initializer, from)
  28. }
  29. }
  30. }
  31. module.exports = parse