label-start-image.mjs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import labelEnd from './label-end.mjs'
  2. var labelStartImage = {
  3. name: 'labelStartImage',
  4. tokenize: tokenizeLabelStartImage,
  5. resolveAll: labelEnd.resolveAll
  6. }
  7. export default labelStartImage
  8. import assert from 'assert'
  9. import codes from '../character/codes.mjs'
  10. import types from '../constant/types.mjs'
  11. function tokenizeLabelStartImage(effects, ok, nok) {
  12. var self = this
  13. return start
  14. function start(code) {
  15. assert(code === codes.exclamationMark, 'expected `!`')
  16. effects.enter(types.labelImage)
  17. effects.enter(types.labelImageMarker)
  18. effects.consume(code)
  19. effects.exit(types.labelImageMarker)
  20. return open
  21. }
  22. function open(code) {
  23. if (code === codes.leftSquareBracket) {
  24. effects.enter(types.labelMarker)
  25. effects.consume(code)
  26. effects.exit(types.labelMarker)
  27. effects.exit(types.labelImage)
  28. return after
  29. }
  30. return nok(code)
  31. }
  32. function after(code) {
  33. /* c8 ignore next */
  34. return code === codes.caret &&
  35. /* c8 ignore next */
  36. '_hiddenFootnoteSupport' in self.parser.constructs
  37. ? /* c8 ignore next */ nok(code)
  38. : ok(code)
  39. }
  40. }