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.

character-reference.mjs 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. var characterReference = {
  2. name: 'characterReference',
  3. tokenize: tokenizeCharacterReference
  4. }
  5. export default characterReference
  6. import assert from 'assert'
  7. import decode from 'parse-entities/decode-entity.js'
  8. import asciiAlphanumeric from '../character/ascii-alphanumeric.mjs'
  9. import asciiDigit from '../character/ascii-digit.mjs'
  10. import asciiHexDigit from '../character/ascii-hex-digit.mjs'
  11. import codes from '../character/codes.mjs'
  12. import constants from '../constant/constants.mjs'
  13. import types from '../constant/types.mjs'
  14. function tokenizeCharacterReference(effects, ok, nok) {
  15. var self = this
  16. var size = 0
  17. var max
  18. var test
  19. return start
  20. function start(code) {
  21. assert(code === codes.ampersand, 'expected `&`')
  22. effects.enter(types.characterReference)
  23. effects.enter(types.characterReferenceMarker)
  24. effects.consume(code)
  25. effects.exit(types.characterReferenceMarker)
  26. return open
  27. }
  28. function open(code) {
  29. if (code === codes.numberSign) {
  30. effects.enter(types.characterReferenceMarkerNumeric)
  31. effects.consume(code)
  32. effects.exit(types.characterReferenceMarkerNumeric)
  33. return numeric
  34. }
  35. effects.enter(types.characterReferenceValue)
  36. max = constants.characterReferenceNamedSizeMax
  37. test = asciiAlphanumeric
  38. return value(code)
  39. }
  40. function numeric(code) {
  41. if (code === codes.uppercaseX || code === codes.lowercaseX) {
  42. effects.enter(types.characterReferenceMarkerHexadecimal)
  43. effects.consume(code)
  44. effects.exit(types.characterReferenceMarkerHexadecimal)
  45. effects.enter(types.characterReferenceValue)
  46. max = constants.characterReferenceHexadecimalSizeMax
  47. test = asciiHexDigit
  48. return value
  49. }
  50. effects.enter(types.characterReferenceValue)
  51. max = constants.characterReferenceDecimalSizeMax
  52. test = asciiDigit
  53. return value(code)
  54. }
  55. function value(code) {
  56. var token
  57. if (code === codes.semicolon && size) {
  58. token = effects.exit(types.characterReferenceValue)
  59. if (test === asciiAlphanumeric && !decode(self.sliceSerialize(token))) {
  60. return nok(code)
  61. }
  62. effects.enter(types.characterReferenceMarker)
  63. effects.consume(code)
  64. effects.exit(types.characterReferenceMarker)
  65. effects.exit(types.characterReference)
  66. return ok
  67. }
  68. if (test(code) && size++ < max) {
  69. effects.consume(code)
  70. return value
  71. }
  72. return nok(code)
  73. }
  74. }