hard-break-escape.js 984 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @import {
  3. * Construct,
  4. * State,
  5. * TokenizeContext,
  6. * Tokenizer
  7. * } from 'micromark-util-types'
  8. */
  9. import { markdownLineEnding } from 'micromark-util-character';
  10. /** @type {Construct} */
  11. export const hardBreakEscape = {
  12. name: 'hardBreakEscape',
  13. tokenize: tokenizeHardBreakEscape
  14. };
  15. /**
  16. * @this {TokenizeContext}
  17. * Context.
  18. * @type {Tokenizer}
  19. */
  20. function tokenizeHardBreakEscape(effects, ok, nok) {
  21. return start;
  22. /**
  23. * Start of a hard break (escape).
  24. *
  25. * ```markdown
  26. * > | a\
  27. * ^
  28. * | b
  29. * ```
  30. *
  31. * @type {State}
  32. */
  33. function start(code) {
  34. effects.enter("hardBreakEscape");
  35. effects.consume(code);
  36. return after;
  37. }
  38. /**
  39. * After `\`, at eol.
  40. *
  41. * ```markdown
  42. * > | a\
  43. * ^
  44. * | b
  45. * ```
  46. *
  47. * @type {State}
  48. */
  49. function after(code) {
  50. if (markdownLineEnding(code)) {
  51. effects.exit("hardBreakEscape");
  52. return ok(code);
  53. }
  54. return nok(code);
  55. }
  56. }