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.

autolink.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. 'use strict'
  2. var asciiAlpha = require('../character/ascii-alpha.js')
  3. var asciiAlphanumeric = require('../character/ascii-alphanumeric.js')
  4. var asciiAtext = require('../character/ascii-atext.js')
  5. var asciiControl = require('../character/ascii-control.js')
  6. var autolink = {
  7. name: 'autolink',
  8. tokenize: tokenizeAutolink
  9. }
  10. function tokenizeAutolink(effects, ok, nok) {
  11. var size = 1
  12. return start
  13. function start(code) {
  14. effects.enter('autolink')
  15. effects.enter('autolinkMarker')
  16. effects.consume(code)
  17. effects.exit('autolinkMarker')
  18. effects.enter('autolinkProtocol')
  19. return open
  20. }
  21. function open(code) {
  22. if (asciiAlpha(code)) {
  23. effects.consume(code)
  24. return schemeOrEmailAtext
  25. }
  26. return asciiAtext(code) ? emailAtext(code) : nok(code)
  27. }
  28. function schemeOrEmailAtext(code) {
  29. return code === 43 || code === 45 || code === 46 || asciiAlphanumeric(code)
  30. ? schemeInsideOrEmailAtext(code)
  31. : emailAtext(code)
  32. }
  33. function schemeInsideOrEmailAtext(code) {
  34. if (code === 58) {
  35. effects.consume(code)
  36. return urlInside
  37. }
  38. if (
  39. (code === 43 || code === 45 || code === 46 || asciiAlphanumeric(code)) &&
  40. size++ < 32
  41. ) {
  42. effects.consume(code)
  43. return schemeInsideOrEmailAtext
  44. }
  45. return emailAtext(code)
  46. }
  47. function urlInside(code) {
  48. if (code === 62) {
  49. effects.exit('autolinkProtocol')
  50. return end(code)
  51. }
  52. if (code === 32 || code === 60 || asciiControl(code)) {
  53. return nok(code)
  54. }
  55. effects.consume(code)
  56. return urlInside
  57. }
  58. function emailAtext(code) {
  59. if (code === 64) {
  60. effects.consume(code)
  61. size = 0
  62. return emailAtSignOrDot
  63. }
  64. if (asciiAtext(code)) {
  65. effects.consume(code)
  66. return emailAtext
  67. }
  68. return nok(code)
  69. }
  70. function emailAtSignOrDot(code) {
  71. return asciiAlphanumeric(code) ? emailLabel(code) : nok(code)
  72. }
  73. function emailLabel(code) {
  74. if (code === 46) {
  75. effects.consume(code)
  76. size = 0
  77. return emailAtSignOrDot
  78. }
  79. if (code === 62) {
  80. // Exit, then change the type.
  81. effects.exit('autolinkProtocol').type = 'autolinkEmail'
  82. return end(code)
  83. }
  84. return emailValue(code)
  85. }
  86. function emailValue(code) {
  87. if ((code === 45 || asciiAlphanumeric(code)) && size++ < 63) {
  88. effects.consume(code)
  89. return code === 45 ? emailValue : emailLabel
  90. }
  91. return nok(code)
  92. }
  93. function end(code) {
  94. effects.enter('autolinkMarker')
  95. effects.consume(code)
  96. effects.exit('autolinkMarker')
  97. effects.exit('autolink')
  98. return ok
  99. }
  100. }
  101. module.exports = autolink