label-start-link.js 1.1 KB

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