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.8KB

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