Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

factory-label.mjs 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. export default labelFactory
  2. import assert from 'assert'
  3. import codes from '../character/codes.mjs'
  4. import markdownLineEnding from '../character/markdown-line-ending.mjs'
  5. import markdownSpace from '../character/markdown-space.mjs'
  6. import constants from '../constant/constants.mjs'
  7. import types from '../constant/types.mjs'
  8. // eslint-disable-next-line max-params
  9. function labelFactory(effects, ok, nok, type, markerType, stringType) {
  10. var self = this
  11. var size = 0
  12. var data
  13. return start
  14. function start(code) {
  15. assert(code === codes.leftSquareBracket, 'expected `[`')
  16. effects.enter(type)
  17. effects.enter(markerType)
  18. effects.consume(code)
  19. effects.exit(markerType)
  20. effects.enter(stringType)
  21. return atBreak
  22. }
  23. function atBreak(code) {
  24. if (
  25. code === codes.eof ||
  26. code === codes.leftSquareBracket ||
  27. (code === codes.rightSquareBracket && !data) ||
  28. /* c8 ignore next */
  29. (code === codes.caret &&
  30. /* c8 ignore next */
  31. !size &&
  32. /* c8 ignore next */
  33. '_hiddenFootnoteSupport' in self.parser.constructs) ||
  34. size > constants.linkReferenceSizeMax
  35. ) {
  36. return nok(code)
  37. }
  38. if (code === codes.rightSquareBracket) {
  39. effects.exit(stringType)
  40. effects.enter(markerType)
  41. effects.consume(code)
  42. effects.exit(markerType)
  43. effects.exit(type)
  44. return ok
  45. }
  46. if (markdownLineEnding(code)) {
  47. effects.enter(types.lineEnding)
  48. effects.consume(code)
  49. effects.exit(types.lineEnding)
  50. return atBreak
  51. }
  52. effects.enter(types.chunkString, {contentType: constants.contentTypeString})
  53. return label(code)
  54. }
  55. function label(code) {
  56. if (
  57. code === codes.eof ||
  58. code === codes.leftSquareBracket ||
  59. code === codes.rightSquareBracket ||
  60. markdownLineEnding(code) ||
  61. size++ > constants.linkReferenceSizeMax
  62. ) {
  63. effects.exit(types.chunkString)
  64. return atBreak(code)
  65. }
  66. effects.consume(code)
  67. data = data || !markdownSpace(code)
  68. return code === codes.backslash ? labelEscape : label
  69. }
  70. function labelEscape(code) {
  71. if (
  72. code === codes.leftSquareBracket ||
  73. code === codes.backslash ||
  74. code === codes.rightSquareBracket
  75. ) {
  76. effects.consume(code)
  77. size++
  78. return label
  79. }
  80. return label(code)
  81. }
  82. }