label-start-image.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict'
  2. var labelEnd = require('./label-end.js')
  3. var assert = require('assert')
  4. var codes = require('../character/codes.js')
  5. var types = require('../constant/types.js')
  6. function _interopDefaultLegacy(e) {
  7. return e && typeof e === 'object' && 'default' in e ? e : {default: e}
  8. }
  9. var assert__default = /*#__PURE__*/ _interopDefaultLegacy(assert)
  10. var labelStartImage = {
  11. name: 'labelStartImage',
  12. tokenize: tokenizeLabelStartImage,
  13. resolveAll: labelEnd.resolveAll
  14. }
  15. function tokenizeLabelStartImage(effects, ok, nok) {
  16. var self = this
  17. return start
  18. function start(code) {
  19. assert__default['default'](code === codes.exclamationMark, 'expected `!`')
  20. effects.enter(types.labelImage)
  21. effects.enter(types.labelImageMarker)
  22. effects.consume(code)
  23. effects.exit(types.labelImageMarker)
  24. return open
  25. }
  26. function open(code) {
  27. if (code === codes.leftSquareBracket) {
  28. effects.enter(types.labelMarker)
  29. effects.consume(code)
  30. effects.exit(types.labelMarker)
  31. effects.exit(types.labelImage)
  32. return after
  33. }
  34. return nok(code)
  35. }
  36. function after(code) {
  37. /* c8 ignore next */
  38. return code === codes.caret &&
  39. /* c8 ignore next */
  40. '_hiddenFootnoteSupport' in self.parser.constructs
  41. ? /* c8 ignore next */ nok(code)
  42. : ok(code)
  43. }
  44. }
  45. module.exports = labelStartImage