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.

factory-title.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. 'use strict'
  2. var markdownLineEnding = require('../character/markdown-line-ending.js')
  3. var factorySpace = require('./factory-space.js')
  4. function titleFactory(effects, ok, nok, type, markerType, stringType) {
  5. var marker
  6. return start
  7. function start(code) {
  8. effects.enter(type)
  9. effects.enter(markerType)
  10. effects.consume(code)
  11. effects.exit(markerType)
  12. marker = code === 40 ? 41 : code
  13. return atFirstTitleBreak
  14. }
  15. function atFirstTitleBreak(code) {
  16. if (code === marker) {
  17. effects.enter(markerType)
  18. effects.consume(code)
  19. effects.exit(markerType)
  20. effects.exit(type)
  21. return ok
  22. }
  23. effects.enter(stringType)
  24. return atTitleBreak(code)
  25. }
  26. function atTitleBreak(code) {
  27. if (code === marker) {
  28. effects.exit(stringType)
  29. return atFirstTitleBreak(marker)
  30. }
  31. if (code === null) {
  32. return nok(code)
  33. } // Note: blank lines can’t exist in content.
  34. if (markdownLineEnding(code)) {
  35. effects.enter('lineEnding')
  36. effects.consume(code)
  37. effects.exit('lineEnding')
  38. return factorySpace(effects, atTitleBreak, 'linePrefix')
  39. }
  40. effects.enter('chunkString', {
  41. contentType: 'string'
  42. })
  43. return title(code)
  44. }
  45. function title(code) {
  46. if (code === marker || code === null || markdownLineEnding(code)) {
  47. effects.exit('chunkString')
  48. return atTitleBreak(code)
  49. }
  50. effects.consume(code)
  51. return code === 92 ? titleEscape : title
  52. }
  53. function titleEscape(code) {
  54. if (code === marker || code === 92) {
  55. effects.consume(code)
  56. return title
  57. }
  58. return title(code)
  59. }
  60. }
  61. module.exports = titleFactory