blank-line.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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, markdownSpace} from 'micromark-util-character'
  9. import {codes, types} from 'micromark-util-symbol'
  10. /** @type {Construct} */
  11. export const blankLine = {tokenize: tokenizeBlankLine, partial: true}
  12. /**
  13. * @this {TokenizeContext}
  14. * @type {Tokenizer}
  15. */
  16. function tokenizeBlankLine(effects, ok, nok) {
  17. return start
  18. /**
  19. * Start of blank line.
  20. *
  21. * > 👉 **Note**: `␠` represents a space character.
  22. *
  23. * ```markdown
  24. * > | ␠␠␊
  25. * ^
  26. * > | ␊
  27. * ^
  28. * ```
  29. *
  30. * @type {State}
  31. */
  32. function start(code) {
  33. return markdownSpace(code)
  34. ? factorySpace(effects, after, types.linePrefix)(code)
  35. : after(code)
  36. }
  37. /**
  38. * At eof/eol, after optional whitespace.
  39. *
  40. * > 👉 **Note**: `␠` represents a space character.
  41. *
  42. * ```markdown
  43. * > | ␠␠␊
  44. * ^
  45. * > | ␊
  46. * ^
  47. * ```
  48. *
  49. * @type {State}
  50. */
  51. function after(code) {
  52. return code === codes.eof || markdownLineEnding(code) ? ok(code) : nok(code)
  53. }
  54. }