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.

setext-underline.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. 'use strict'
  2. var markdownLineEnding = require('../character/markdown-line-ending.js')
  3. var shallow = require('../util/shallow.js')
  4. var factorySpace = require('./factory-space.js')
  5. var setextUnderline = {
  6. name: 'setextUnderline',
  7. tokenize: tokenizeSetextUnderline,
  8. resolveTo: resolveToSetextUnderline
  9. }
  10. function resolveToSetextUnderline(events, context) {
  11. var index = events.length
  12. var content
  13. var text
  14. var definition
  15. var heading // Find the opening of the content.
  16. // It’ll always exist: we don’t tokenize if it isn’t there.
  17. while (index--) {
  18. if (events[index][0] === 'enter') {
  19. if (events[index][1].type === 'content') {
  20. content = index
  21. break
  22. }
  23. if (events[index][1].type === 'paragraph') {
  24. text = index
  25. }
  26. } // Exit
  27. else {
  28. if (events[index][1].type === 'content') {
  29. // Remove the content end (if needed we’ll add it later)
  30. events.splice(index, 1)
  31. }
  32. if (!definition && events[index][1].type === 'definition') {
  33. definition = index
  34. }
  35. }
  36. }
  37. heading = {
  38. type: 'setextHeading',
  39. start: shallow(events[text][1].start),
  40. end: shallow(events[events.length - 1][1].end)
  41. } // Change the paragraph to setext heading text.
  42. events[text][1].type = 'setextHeadingText' // If we have definitions in the content, we’ll keep on having content,
  43. // but we need move it.
  44. if (definition) {
  45. events.splice(text, 0, ['enter', heading, context])
  46. events.splice(definition + 1, 0, ['exit', events[content][1], context])
  47. events[content][1].end = shallow(events[definition][1].end)
  48. } else {
  49. events[content][1] = heading
  50. } // Add the heading exit at the end.
  51. events.push(['exit', heading, context])
  52. return events
  53. }
  54. function tokenizeSetextUnderline(effects, ok, nok) {
  55. var self = this
  56. var index = self.events.length
  57. var marker
  58. var paragraph // Find an opening.
  59. while (index--) {
  60. // Skip enter/exit of line ending, line prefix, and content.
  61. // We can now either have a definition or a paragraph.
  62. if (
  63. self.events[index][1].type !== 'lineEnding' &&
  64. self.events[index][1].type !== 'linePrefix' &&
  65. self.events[index][1].type !== 'content'
  66. ) {
  67. paragraph = self.events[index][1].type === 'paragraph'
  68. break
  69. }
  70. }
  71. return start
  72. function start(code) {
  73. if (!self.lazy && (self.interrupt || paragraph)) {
  74. effects.enter('setextHeadingLine')
  75. effects.enter('setextHeadingLineSequence')
  76. marker = code
  77. return closingSequence(code)
  78. }
  79. return nok(code)
  80. }
  81. function closingSequence(code) {
  82. if (code === marker) {
  83. effects.consume(code)
  84. return closingSequence
  85. }
  86. effects.exit('setextHeadingLineSequence')
  87. return factorySpace(effects, closingSequenceEnd, 'lineSuffix')(code)
  88. }
  89. function closingSequenceEnd(code) {
  90. if (code === null || markdownLineEnding(code)) {
  91. effects.exit('setextHeadingLine')
  92. return ok(code)
  93. }
  94. return nok(code)
  95. }
  96. }
  97. module.exports = setextUnderline