line-ending.js 944 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * @typedef {import('micromark-util-types').Construct} Construct
  3. * @typedef {import('micromark-util-types').State} State
  4. * @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
  5. * @typedef {import('micromark-util-types').Tokenizer} Tokenizer
  6. */
  7. import {factorySpace} from 'micromark-factory-space'
  8. import {markdownLineEnding} from 'micromark-util-character'
  9. import {types} from 'micromark-util-symbol'
  10. import {ok as assert} from 'devlop'
  11. /** @type {Construct} */
  12. export const lineEnding = {name: 'lineEnding', tokenize: tokenizeLineEnding}
  13. /**
  14. * @this {TokenizeContext}
  15. * @type {Tokenizer}
  16. */
  17. function tokenizeLineEnding(effects, ok) {
  18. return start
  19. /** @type {State} */
  20. function start(code) {
  21. assert(markdownLineEnding(code), 'expected eol')
  22. effects.enter(types.lineEnding)
  23. effects.consume(code)
  24. effects.exit(types.lineEnding)
  25. return factorySpace(effects, ok, types.linePrefix)
  26. }
  27. }