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.

document.js 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. 'use strict'
  2. Object.defineProperty(exports, '__esModule', {value: true})
  3. var markdownLineEnding = require('../character/markdown-line-ending.js')
  4. var factorySpace = require('../tokenize/factory-space.js')
  5. var partialBlankLine = require('../tokenize/partial-blank-line.js')
  6. var tokenize = initializeDocument
  7. var containerConstruct = {
  8. tokenize: tokenizeContainer
  9. }
  10. var lazyFlowConstruct = {
  11. tokenize: tokenizeLazyFlow
  12. }
  13. function initializeDocument(effects) {
  14. var self = this
  15. var stack = []
  16. var continued = 0
  17. var inspectConstruct = {
  18. tokenize: tokenizeInspect,
  19. partial: true
  20. }
  21. var inspectResult
  22. var childFlow
  23. var childToken
  24. return start
  25. function start(code) {
  26. if (continued < stack.length) {
  27. self.containerState = stack[continued][1]
  28. return effects.attempt(
  29. stack[continued][0].continuation,
  30. documentContinue,
  31. documentContinued
  32. )(code)
  33. }
  34. return documentContinued(code)
  35. }
  36. function documentContinue(code) {
  37. continued++
  38. return start(code)
  39. }
  40. function documentContinued(code) {
  41. // If we’re in a concrete construct (such as when expecting another line of
  42. // HTML, or we resulted in lazy content), we can immediately start flow.
  43. if (inspectResult && inspectResult.flowContinue) {
  44. return flowStart(code)
  45. }
  46. self.interrupt =
  47. childFlow &&
  48. childFlow.currentConstruct &&
  49. childFlow.currentConstruct.interruptible
  50. self.containerState = {}
  51. return effects.attempt(
  52. containerConstruct,
  53. containerContinue,
  54. flowStart
  55. )(code)
  56. }
  57. function containerContinue(code) {
  58. stack.push([self.currentConstruct, self.containerState])
  59. self.containerState = undefined
  60. return documentContinued(code)
  61. }
  62. function flowStart(code) {
  63. if (code === null) {
  64. exitContainers(0, true)
  65. effects.consume(code)
  66. return
  67. }
  68. childFlow = childFlow || self.parser.flow(self.now())
  69. effects.enter('chunkFlow', {
  70. contentType: 'flow',
  71. previous: childToken,
  72. _tokenizer: childFlow
  73. })
  74. return flowContinue(code)
  75. }
  76. function flowContinue(code) {
  77. if (code === null) {
  78. continueFlow(effects.exit('chunkFlow'))
  79. return flowStart(code)
  80. }
  81. if (markdownLineEnding(code)) {
  82. effects.consume(code)
  83. continueFlow(effects.exit('chunkFlow'))
  84. return effects.check(inspectConstruct, documentAfterPeek)
  85. }
  86. effects.consume(code)
  87. return flowContinue
  88. }
  89. function documentAfterPeek(code) {
  90. exitContainers(
  91. inspectResult.continued,
  92. inspectResult && inspectResult.flowEnd
  93. )
  94. continued = 0
  95. return start(code)
  96. }
  97. function continueFlow(token) {
  98. if (childToken) childToken.next = token
  99. childToken = token
  100. childFlow.lazy = inspectResult && inspectResult.lazy
  101. childFlow.defineSkip(token.start)
  102. childFlow.write(self.sliceStream(token))
  103. }
  104. function exitContainers(size, end) {
  105. var index = stack.length // Close the flow.
  106. if (childFlow && end) {
  107. childFlow.write([null])
  108. childToken = childFlow = undefined
  109. } // Exit open containers.
  110. while (index-- > size) {
  111. self.containerState = stack[index][1]
  112. stack[index][0].exit.call(self, effects)
  113. }
  114. stack.length = size
  115. }
  116. function tokenizeInspect(effects, ok) {
  117. var subcontinued = 0
  118. inspectResult = {}
  119. return inspectStart
  120. function inspectStart(code) {
  121. if (subcontinued < stack.length) {
  122. self.containerState = stack[subcontinued][1]
  123. return effects.attempt(
  124. stack[subcontinued][0].continuation,
  125. inspectContinue,
  126. inspectLess
  127. )(code)
  128. } // If we’re continued but in a concrete flow, we can’t have more
  129. // containers.
  130. if (childFlow.currentConstruct && childFlow.currentConstruct.concrete) {
  131. inspectResult.flowContinue = true
  132. return inspectDone(code)
  133. }
  134. self.interrupt =
  135. childFlow.currentConstruct && childFlow.currentConstruct.interruptible
  136. self.containerState = {}
  137. return effects.attempt(
  138. containerConstruct,
  139. inspectFlowEnd,
  140. inspectDone
  141. )(code)
  142. }
  143. function inspectContinue(code) {
  144. subcontinued++
  145. return self.containerState._closeFlow
  146. ? inspectFlowEnd(code)
  147. : inspectStart(code)
  148. }
  149. function inspectLess(code) {
  150. if (childFlow.currentConstruct && childFlow.currentConstruct.lazy) {
  151. // Maybe another container?
  152. self.containerState = {}
  153. return effects.attempt(
  154. containerConstruct,
  155. inspectFlowEnd, // Maybe flow, or a blank line?
  156. effects.attempt(
  157. lazyFlowConstruct,
  158. inspectFlowEnd,
  159. effects.check(partialBlankLine, inspectFlowEnd, inspectLazy)
  160. )
  161. )(code)
  162. } // Otherwise we’re interrupting.
  163. return inspectFlowEnd(code)
  164. }
  165. function inspectLazy(code) {
  166. // Act as if all containers are continued.
  167. subcontinued = stack.length
  168. inspectResult.lazy = true
  169. inspectResult.flowContinue = true
  170. return inspectDone(code)
  171. } // We’re done with flow if we have more containers, or an interruption.
  172. function inspectFlowEnd(code) {
  173. inspectResult.flowEnd = true
  174. return inspectDone(code)
  175. }
  176. function inspectDone(code) {
  177. inspectResult.continued = subcontinued
  178. self.interrupt = self.containerState = undefined
  179. return ok(code)
  180. }
  181. }
  182. }
  183. function tokenizeContainer(effects, ok, nok) {
  184. return factorySpace(
  185. effects,
  186. effects.attempt(this.parser.constructs.document, ok, nok),
  187. 'linePrefix',
  188. this.parser.constructs.disable.null.indexOf('codeIndented') > -1
  189. ? undefined
  190. : 4
  191. )
  192. }
  193. function tokenizeLazyFlow(effects, ok, nok) {
  194. return factorySpace(
  195. effects,
  196. effects.lazy(this.parser.constructs.flow, ok, nok),
  197. 'linePrefix',
  198. this.parser.constructs.disable.null.indexOf('codeIndented') > -1
  199. ? undefined
  200. : 4
  201. )
  202. }
  203. exports.tokenize = tokenize