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-fenced.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 prefixSize = require('../util/prefix-size.js')
  5. var factorySpace = require('./factory-space.js')
  6. var codeFenced = {
  7. name: 'codeFenced',
  8. tokenize: tokenizeCodeFenced,
  9. concrete: true
  10. }
  11. function tokenizeCodeFenced(effects, ok, nok) {
  12. var self = this
  13. var closingFenceConstruct = {
  14. tokenize: tokenizeClosingFence,
  15. partial: true
  16. }
  17. var initialPrefix = prefixSize(this.events, 'linePrefix')
  18. var sizeOpen = 0
  19. var marker
  20. return start
  21. function start(code) {
  22. effects.enter('codeFenced')
  23. effects.enter('codeFencedFence')
  24. effects.enter('codeFencedFenceSequence')
  25. marker = code
  26. return sequenceOpen(code)
  27. }
  28. function sequenceOpen(code) {
  29. if (code === marker) {
  30. effects.consume(code)
  31. sizeOpen++
  32. return sequenceOpen
  33. }
  34. effects.exit('codeFencedFenceSequence')
  35. return sizeOpen < 3
  36. ? nok(code)
  37. : factorySpace(effects, infoOpen, 'whitespace')(code)
  38. }
  39. function infoOpen(code) {
  40. if (code === null || markdownLineEnding(code)) {
  41. return openAfter(code)
  42. }
  43. effects.enter('codeFencedFenceInfo')
  44. effects.enter('chunkString', {
  45. contentType: 'string'
  46. })
  47. return info(code)
  48. }
  49. function info(code) {
  50. if (code === null || markdownLineEndingOrSpace(code)) {
  51. effects.exit('chunkString')
  52. effects.exit('codeFencedFenceInfo')
  53. return factorySpace(effects, infoAfter, 'whitespace')(code)
  54. }
  55. if (code === 96 && code === marker) return nok(code)
  56. effects.consume(code)
  57. return info
  58. }
  59. function infoAfter(code) {
  60. if (code === null || markdownLineEnding(code)) {
  61. return openAfter(code)
  62. }
  63. effects.enter('codeFencedFenceMeta')
  64. effects.enter('chunkString', {
  65. contentType: 'string'
  66. })
  67. return meta(code)
  68. }
  69. function meta(code) {
  70. if (code === null || markdownLineEnding(code)) {
  71. effects.exit('chunkString')
  72. effects.exit('codeFencedFenceMeta')
  73. return openAfter(code)
  74. }
  75. if (code === 96 && code === marker) return nok(code)
  76. effects.consume(code)
  77. return meta
  78. }
  79. function openAfter(code) {
  80. effects.exit('codeFencedFence')
  81. return self.interrupt ? ok(code) : content(code)
  82. }
  83. function content(code) {
  84. if (code === null) {
  85. return after(code)
  86. }
  87. if (markdownLineEnding(code)) {
  88. effects.enter('lineEnding')
  89. effects.consume(code)
  90. effects.exit('lineEnding')
  91. return effects.attempt(
  92. closingFenceConstruct,
  93. after,
  94. initialPrefix
  95. ? factorySpace(effects, content, 'linePrefix', initialPrefix + 1)
  96. : content
  97. )
  98. }
  99. effects.enter('codeFlowValue')
  100. return contentContinue(code)
  101. }
  102. function contentContinue(code) {
  103. if (code === null || markdownLineEnding(code)) {
  104. effects.exit('codeFlowValue')
  105. return content(code)
  106. }
  107. effects.consume(code)
  108. return contentContinue
  109. }
  110. function after(code) {
  111. effects.exit('codeFenced')
  112. return ok(code)
  113. }
  114. function tokenizeClosingFence(effects, ok, nok) {
  115. var size = 0
  116. return factorySpace(
  117. effects,
  118. closingSequenceStart,
  119. 'linePrefix',
  120. this.parser.constructs.disable.null.indexOf('codeIndented') > -1
  121. ? undefined
  122. : 4
  123. )
  124. function closingSequenceStart(code) {
  125. effects.enter('codeFencedFence')
  126. effects.enter('codeFencedFenceSequence')
  127. return closingSequence(code)
  128. }
  129. function closingSequence(code) {
  130. if (code === marker) {
  131. effects.consume(code)
  132. size++
  133. return closingSequence
  134. }
  135. if (size < sizeOpen) return nok(code)
  136. effects.exit('codeFencedFenceSequence')
  137. return factorySpace(effects, closingSequenceEnd, 'whitespace')(code)
  138. }
  139. function closingSequenceEnd(code) {
  140. if (code === null || markdownLineEnding(code)) {
  141. effects.exit('codeFencedFence')
  142. return ok(code)
  143. }
  144. return nok(code)
  145. }
  146. }
  147. }
  148. module.exports = codeFenced