label-start-link.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 {labelEnd} from './label-end.js'
  8. /** @type {Construct} */
  9. export const labelStartLink = {
  10. name: 'labelStartLink',
  11. tokenize: tokenizeLabelStartLink,
  12. resolveAll: labelEnd.resolveAll
  13. }
  14. /**
  15. * @this {TokenizeContext}
  16. * @type {Tokenizer}
  17. */
  18. function tokenizeLabelStartLink(effects, ok, nok) {
  19. const self = this
  20. return start
  21. /**
  22. * Start of label (link) start.
  23. *
  24. * ```markdown
  25. * > | a [b] c
  26. * ^
  27. * ```
  28. *
  29. * @type {State}
  30. */
  31. function start(code) {
  32. effects.enter('labelLink')
  33. effects.enter('labelMarker')
  34. effects.consume(code)
  35. effects.exit('labelMarker')
  36. effects.exit('labelLink')
  37. return after
  38. }
  39. /** @type {State} */
  40. function after(code) {
  41. // To do: this isn’t needed in `micromark-extension-gfm-footnote`,
  42. // remove.
  43. // Hidden footnotes hook.
  44. /* c8 ignore next 3 */
  45. return code === 94 && '_hiddenFootnoteSupport' in self.parser.constructs
  46. ? nok(code)
  47. : ok(code)
  48. }
  49. }