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.

heading-atx.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 markdownSpace = require('../character/markdown-space.js')
  5. var chunkedSplice = require('../util/chunked-splice.js')
  6. var factorySpace = require('./factory-space.js')
  7. var headingAtx = {
  8. name: 'headingAtx',
  9. tokenize: tokenizeHeadingAtx,
  10. resolve: resolveHeadingAtx
  11. }
  12. function resolveHeadingAtx(events, context) {
  13. var contentEnd = events.length - 2
  14. var contentStart = 3
  15. var content
  16. var text // Prefix whitespace, part of the opening.
  17. if (events[contentStart][1].type === 'whitespace') {
  18. contentStart += 2
  19. } // Suffix whitespace, part of the closing.
  20. if (
  21. contentEnd - 2 > contentStart &&
  22. events[contentEnd][1].type === 'whitespace'
  23. ) {
  24. contentEnd -= 2
  25. }
  26. if (
  27. events[contentEnd][1].type === 'atxHeadingSequence' &&
  28. (contentStart === contentEnd - 1 ||
  29. (contentEnd - 4 > contentStart &&
  30. events[contentEnd - 2][1].type === 'whitespace'))
  31. ) {
  32. contentEnd -= contentStart + 1 === contentEnd ? 2 : 4
  33. }
  34. if (contentEnd > contentStart) {
  35. content = {
  36. type: 'atxHeadingText',
  37. start: events[contentStart][1].start,
  38. end: events[contentEnd][1].end
  39. }
  40. text = {
  41. type: 'chunkText',
  42. start: events[contentStart][1].start,
  43. end: events[contentEnd][1].end,
  44. contentType: 'text'
  45. }
  46. chunkedSplice(events, contentStart, contentEnd - contentStart + 1, [
  47. ['enter', content, context],
  48. ['enter', text, context],
  49. ['exit', text, context],
  50. ['exit', content, context]
  51. ])
  52. }
  53. return events
  54. }
  55. function tokenizeHeadingAtx(effects, ok, nok) {
  56. var self = this
  57. var size = 0
  58. return start
  59. function start(code) {
  60. effects.enter('atxHeading')
  61. effects.enter('atxHeadingSequence')
  62. return fenceOpenInside(code)
  63. }
  64. function fenceOpenInside(code) {
  65. if (code === 35 && size++ < 6) {
  66. effects.consume(code)
  67. return fenceOpenInside
  68. }
  69. if (code === null || markdownLineEndingOrSpace(code)) {
  70. effects.exit('atxHeadingSequence')
  71. return self.interrupt ? ok(code) : headingBreak(code)
  72. }
  73. return nok(code)
  74. }
  75. function headingBreak(code) {
  76. if (code === 35) {
  77. effects.enter('atxHeadingSequence')
  78. return sequence(code)
  79. }
  80. if (code === null || markdownLineEnding(code)) {
  81. effects.exit('atxHeading')
  82. return ok(code)
  83. }
  84. if (markdownSpace(code)) {
  85. return factorySpace(effects, headingBreak, 'whitespace')(code)
  86. }
  87. effects.enter('atxHeadingText')
  88. return data(code)
  89. }
  90. function sequence(code) {
  91. if (code === 35) {
  92. effects.consume(code)
  93. return sequence
  94. }
  95. effects.exit('atxHeadingSequence')
  96. return headingBreak(code)
  97. }
  98. function data(code) {
  99. if (code === null || code === 35 || markdownLineEndingOrSpace(code)) {
  100. effects.exit('atxHeadingText')
  101. return headingBreak(code)
  102. }
  103. effects.consume(code)
  104. return data
  105. }
  106. }
  107. module.exports = headingAtx