blank-line.js 1.3 KB

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