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.

definition.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. 'use strict'
  2. var markdownLineEnding = require('../character/markdown-line-ending.js')
  3. var markdownLineEndingOrSpace = require('../character/markdown-line-ending-or-space.js')
  4. var normalizeIdentifier = require('../util/normalize-identifier.js')
  5. var factoryDestination = require('./factory-destination.js')
  6. var factoryLabel = require('./factory-label.js')
  7. var factorySpace = require('./factory-space.js')
  8. var factoryWhitespace = require('./factory-whitespace.js')
  9. var factoryTitle = require('./factory-title.js')
  10. var definition = {
  11. name: 'definition',
  12. tokenize: tokenizeDefinition
  13. }
  14. var titleConstruct = {
  15. tokenize: tokenizeTitle,
  16. partial: true
  17. }
  18. function tokenizeDefinition(effects, ok, nok) {
  19. var self = this
  20. var identifier
  21. return start
  22. function start(code) {
  23. effects.enter('definition')
  24. return factoryLabel.call(
  25. self,
  26. effects,
  27. labelAfter,
  28. nok,
  29. 'definitionLabel',
  30. 'definitionLabelMarker',
  31. 'definitionLabelString'
  32. )(code)
  33. }
  34. function labelAfter(code) {
  35. identifier = normalizeIdentifier(
  36. self.sliceSerialize(self.events[self.events.length - 1][1]).slice(1, -1)
  37. )
  38. if (code === 58) {
  39. effects.enter('definitionMarker')
  40. effects.consume(code)
  41. effects.exit('definitionMarker') // Note: blank lines can’t exist in content.
  42. return factoryWhitespace(
  43. effects,
  44. factoryDestination(
  45. effects,
  46. effects.attempt(
  47. titleConstruct,
  48. factorySpace(effects, after, 'whitespace'),
  49. factorySpace(effects, after, 'whitespace')
  50. ),
  51. nok,
  52. 'definitionDestination',
  53. 'definitionDestinationLiteral',
  54. 'definitionDestinationLiteralMarker',
  55. 'definitionDestinationRaw',
  56. 'definitionDestinationString'
  57. )
  58. )
  59. }
  60. return nok(code)
  61. }
  62. function after(code) {
  63. if (code === null || markdownLineEnding(code)) {
  64. effects.exit('definition')
  65. if (self.parser.defined.indexOf(identifier) < 0) {
  66. self.parser.defined.push(identifier)
  67. }
  68. return ok(code)
  69. }
  70. return nok(code)
  71. }
  72. }
  73. function tokenizeTitle(effects, ok, nok) {
  74. return start
  75. function start(code) {
  76. return markdownLineEndingOrSpace(code)
  77. ? factoryWhitespace(effects, before)(code)
  78. : nok(code)
  79. }
  80. function before(code) {
  81. if (code === 34 || code === 39 || code === 40) {
  82. return factoryTitle(
  83. effects,
  84. factorySpace(effects, after, 'whitespace'),
  85. nok,
  86. 'definitionTitle',
  87. 'definitionTitleMarker',
  88. 'definitionTitleString'
  89. )(code)
  90. }
  91. return nok(code)
  92. }
  93. function after(code) {
  94. return code === null || markdownLineEnding(code) ? ok(code) : nok(code)
  95. }
  96. }
  97. module.exports = definition