line-ending.js 804 B

123456789101112131415161718192021222324252627282930
  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. /** @type {Construct} */
  10. export const lineEnding = {
  11. name: 'lineEnding',
  12. tokenize: tokenizeLineEnding
  13. }
  14. /**
  15. * @this {TokenizeContext}
  16. * @type {Tokenizer}
  17. */
  18. function tokenizeLineEnding(effects, ok) {
  19. return start
  20. /** @type {State} */
  21. function start(code) {
  22. effects.enter('lineEnding')
  23. effects.consume(code)
  24. effects.exit('lineEnding')
  25. return factorySpace(effects, ok, 'linePrefix')
  26. }
  27. }