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.

code-indented.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. 'use strict'
  2. var codes = require('../character/codes.js')
  3. var markdownLineEnding = require('../character/markdown-line-ending.js')
  4. var constants = require('../constant/constants.js')
  5. var types = require('../constant/types.js')
  6. var chunkedSplice = require('../util/chunked-splice.js')
  7. var prefixSize = require('../util/prefix-size.js')
  8. var factorySpace = require('./factory-space.js')
  9. var codeIndented = {
  10. name: 'codeIndented',
  11. tokenize: tokenizeCodeIndented,
  12. resolve: resolveCodeIndented
  13. }
  14. var indentedContentConstruct = {
  15. tokenize: tokenizeIndentedContent,
  16. partial: true
  17. }
  18. function resolveCodeIndented(events, context) {
  19. var code = {
  20. type: types.codeIndented,
  21. start: events[0][1].start,
  22. end: events[events.length - 1][1].end
  23. }
  24. chunkedSplice(events, 0, 0, [['enter', code, context]])
  25. chunkedSplice(events, events.length, 0, [['exit', code, context]])
  26. return events
  27. }
  28. function tokenizeCodeIndented(effects, ok, nok) {
  29. return effects.attempt(indentedContentConstruct, afterPrefix, nok)
  30. function afterPrefix(code) {
  31. if (code === codes.eof) {
  32. return ok(code)
  33. }
  34. if (markdownLineEnding(code)) {
  35. return effects.attempt(indentedContentConstruct, afterPrefix, ok)(code)
  36. }
  37. effects.enter(types.codeFlowValue)
  38. return content(code)
  39. }
  40. function content(code) {
  41. if (code === codes.eof || markdownLineEnding(code)) {
  42. effects.exit(types.codeFlowValue)
  43. return afterPrefix(code)
  44. }
  45. effects.consume(code)
  46. return content
  47. }
  48. }
  49. function tokenizeIndentedContent(effects, ok, nok) {
  50. var self = this
  51. return factorySpace(
  52. effects,
  53. afterPrefix,
  54. types.linePrefix,
  55. constants.tabSize + 1
  56. )
  57. function afterPrefix(code) {
  58. if (markdownLineEnding(code)) {
  59. effects.enter(types.lineEnding)
  60. effects.consume(code)
  61. effects.exit(types.lineEnding)
  62. return factorySpace(
  63. effects,
  64. afterPrefix,
  65. types.linePrefix,
  66. constants.tabSize + 1
  67. )
  68. }
  69. return prefixSize(self.events, types.linePrefix) < constants.tabSize
  70. ? nok(code)
  71. : ok(code)
  72. }
  73. }
  74. module.exports = codeIndented