blank-line.js 1.1 KB

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