parse.mjs 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. export default parse
  2. import * as initializeContent from './initialize/content.mjs'
  3. import * as initializeDocument from './initialize/document.mjs'
  4. import * as initializeFlow from './initialize/flow.mjs'
  5. import * as initializeText from './initialize/text.mjs'
  6. import combineExtensions from './util/combine-extensions.mjs'
  7. import createTokenizer from './util/create-tokenizer.mjs'
  8. import miniflat from './util/miniflat.mjs'
  9. import * as constructs from './constructs.mjs'
  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(initializeContent),
  18. document: create(initializeDocument),
  19. flow: create(initializeFlow),
  20. string: create(initializeText.string),
  21. text: create(initializeText.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. }