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.mjs 4.5KB

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