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.

html-text.js 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. 'use strict'
  2. var asciiAlpha = require('../character/ascii-alpha.js')
  3. var asciiAlphanumeric = require('../character/ascii-alphanumeric.js')
  4. var markdownLineEnding = require('../character/markdown-line-ending.js')
  5. var markdownLineEndingOrSpace = require('../character/markdown-line-ending-or-space.js')
  6. var markdownSpace = require('../character/markdown-space.js')
  7. var factorySpace = require('./factory-space.js')
  8. var htmlText = {
  9. name: 'htmlText',
  10. tokenize: tokenizeHtmlText
  11. }
  12. function tokenizeHtmlText(effects, ok, nok) {
  13. var self = this
  14. var marker
  15. var buffer
  16. var index
  17. var returnState
  18. return start
  19. function start(code) {
  20. effects.enter('htmlText')
  21. effects.enter('htmlTextData')
  22. effects.consume(code)
  23. return open
  24. }
  25. function open(code) {
  26. if (code === 33) {
  27. effects.consume(code)
  28. return declarationOpen
  29. }
  30. if (code === 47) {
  31. effects.consume(code)
  32. return tagCloseStart
  33. }
  34. if (code === 63) {
  35. effects.consume(code)
  36. return instruction
  37. }
  38. if (asciiAlpha(code)) {
  39. effects.consume(code)
  40. return tagOpen
  41. }
  42. return nok(code)
  43. }
  44. function declarationOpen(code) {
  45. if (code === 45) {
  46. effects.consume(code)
  47. return commentOpen
  48. }
  49. if (code === 91) {
  50. effects.consume(code)
  51. buffer = 'CDATA['
  52. index = 0
  53. return cdataOpen
  54. }
  55. if (asciiAlpha(code)) {
  56. effects.consume(code)
  57. return declaration
  58. }
  59. return nok(code)
  60. }
  61. function commentOpen(code) {
  62. if (code === 45) {
  63. effects.consume(code)
  64. return commentStart
  65. }
  66. return nok(code)
  67. }
  68. function commentStart(code) {
  69. if (code === null || code === 62) {
  70. return nok(code)
  71. }
  72. if (code === 45) {
  73. effects.consume(code)
  74. return commentStartDash
  75. }
  76. return comment(code)
  77. }
  78. function commentStartDash(code) {
  79. if (code === null || code === 62) {
  80. return nok(code)
  81. }
  82. return comment(code)
  83. }
  84. function comment(code) {
  85. if (code === null) {
  86. return nok(code)
  87. }
  88. if (code === 45) {
  89. effects.consume(code)
  90. return commentClose
  91. }
  92. if (markdownLineEnding(code)) {
  93. returnState = comment
  94. return atLineEnding(code)
  95. }
  96. effects.consume(code)
  97. return comment
  98. }
  99. function commentClose(code) {
  100. if (code === 45) {
  101. effects.consume(code)
  102. return end
  103. }
  104. return comment(code)
  105. }
  106. function cdataOpen(code) {
  107. if (code === buffer.charCodeAt(index++)) {
  108. effects.consume(code)
  109. return index === buffer.length ? cdata : cdataOpen
  110. }
  111. return nok(code)
  112. }
  113. function cdata(code) {
  114. if (code === null) {
  115. return nok(code)
  116. }
  117. if (code === 93) {
  118. effects.consume(code)
  119. return cdataClose
  120. }
  121. if (markdownLineEnding(code)) {
  122. returnState = cdata
  123. return atLineEnding(code)
  124. }
  125. effects.consume(code)
  126. return cdata
  127. }
  128. function cdataClose(code) {
  129. if (code === 93) {
  130. effects.consume(code)
  131. return cdataEnd
  132. }
  133. return cdata(code)
  134. }
  135. function cdataEnd(code) {
  136. if (code === 62) {
  137. return end(code)
  138. }
  139. if (code === 93) {
  140. effects.consume(code)
  141. return cdataEnd
  142. }
  143. return cdata(code)
  144. }
  145. function declaration(code) {
  146. if (code === null || code === 62) {
  147. return end(code)
  148. }
  149. if (markdownLineEnding(code)) {
  150. returnState = declaration
  151. return atLineEnding(code)
  152. }
  153. effects.consume(code)
  154. return declaration
  155. }
  156. function instruction(code) {
  157. if (code === null) {
  158. return nok(code)
  159. }
  160. if (code === 63) {
  161. effects.consume(code)
  162. return instructionClose
  163. }
  164. if (markdownLineEnding(code)) {
  165. returnState = instruction
  166. return atLineEnding(code)
  167. }
  168. effects.consume(code)
  169. return instruction
  170. }
  171. function instructionClose(code) {
  172. return code === 62 ? end(code) : instruction(code)
  173. }
  174. function tagCloseStart(code) {
  175. if (asciiAlpha(code)) {
  176. effects.consume(code)
  177. return tagClose
  178. }
  179. return nok(code)
  180. }
  181. function tagClose(code) {
  182. if (code === 45 || asciiAlphanumeric(code)) {
  183. effects.consume(code)
  184. return tagClose
  185. }
  186. return tagCloseBetween(code)
  187. }
  188. function tagCloseBetween(code) {
  189. if (markdownLineEnding(code)) {
  190. returnState = tagCloseBetween
  191. return atLineEnding(code)
  192. }
  193. if (markdownSpace(code)) {
  194. effects.consume(code)
  195. return tagCloseBetween
  196. }
  197. return end(code)
  198. }
  199. function tagOpen(code) {
  200. if (code === 45 || asciiAlphanumeric(code)) {
  201. effects.consume(code)
  202. return tagOpen
  203. }
  204. if (code === 47 || code === 62 || markdownLineEndingOrSpace(code)) {
  205. return tagOpenBetween(code)
  206. }
  207. return nok(code)
  208. }
  209. function tagOpenBetween(code) {
  210. if (code === 47) {
  211. effects.consume(code)
  212. return end
  213. }
  214. if (code === 58 || code === 95 || asciiAlpha(code)) {
  215. effects.consume(code)
  216. return tagOpenAttributeName
  217. }
  218. if (markdownLineEnding(code)) {
  219. returnState = tagOpenBetween
  220. return atLineEnding(code)
  221. }
  222. if (markdownSpace(code)) {
  223. effects.consume(code)
  224. return tagOpenBetween
  225. }
  226. return end(code)
  227. }
  228. function tagOpenAttributeName(code) {
  229. if (
  230. code === 45 ||
  231. code === 46 ||
  232. code === 58 ||
  233. code === 95 ||
  234. asciiAlphanumeric(code)
  235. ) {
  236. effects.consume(code)
  237. return tagOpenAttributeName
  238. }
  239. return tagOpenAttributeNameAfter(code)
  240. }
  241. function tagOpenAttributeNameAfter(code) {
  242. if (code === 61) {
  243. effects.consume(code)
  244. return tagOpenAttributeValueBefore
  245. }
  246. if (markdownLineEnding(code)) {
  247. returnState = tagOpenAttributeNameAfter
  248. return atLineEnding(code)
  249. }
  250. if (markdownSpace(code)) {
  251. effects.consume(code)
  252. return tagOpenAttributeNameAfter
  253. }
  254. return tagOpenBetween(code)
  255. }
  256. function tagOpenAttributeValueBefore(code) {
  257. if (
  258. code === null ||
  259. code === 60 ||
  260. code === 61 ||
  261. code === 62 ||
  262. code === 96
  263. ) {
  264. return nok(code)
  265. }
  266. if (code === 34 || code === 39) {
  267. effects.consume(code)
  268. marker = code
  269. return tagOpenAttributeValueQuoted
  270. }
  271. if (markdownLineEnding(code)) {
  272. returnState = tagOpenAttributeValueBefore
  273. return atLineEnding(code)
  274. }
  275. if (markdownSpace(code)) {
  276. effects.consume(code)
  277. return tagOpenAttributeValueBefore
  278. }
  279. effects.consume(code)
  280. marker = undefined
  281. return tagOpenAttributeValueUnquoted
  282. }
  283. function tagOpenAttributeValueQuoted(code) {
  284. if (code === marker) {
  285. effects.consume(code)
  286. return tagOpenAttributeValueQuotedAfter
  287. }
  288. if (code === null) {
  289. return nok(code)
  290. }
  291. if (markdownLineEnding(code)) {
  292. returnState = tagOpenAttributeValueQuoted
  293. return atLineEnding(code)
  294. }
  295. effects.consume(code)
  296. return tagOpenAttributeValueQuoted
  297. }
  298. function tagOpenAttributeValueQuotedAfter(code) {
  299. if (code === 62 || code === 47 || markdownLineEndingOrSpace(code)) {
  300. return tagOpenBetween(code)
  301. }
  302. return nok(code)
  303. }
  304. function tagOpenAttributeValueUnquoted(code) {
  305. if (
  306. code === null ||
  307. code === 34 ||
  308. code === 39 ||
  309. code === 60 ||
  310. code === 61 ||
  311. code === 96
  312. ) {
  313. return nok(code)
  314. }
  315. if (code === 62 || markdownLineEndingOrSpace(code)) {
  316. return tagOpenBetween(code)
  317. }
  318. effects.consume(code)
  319. return tagOpenAttributeValueUnquoted
  320. } // We can’t have blank lines in content, so no need to worry about empty
  321. // tokens.
  322. function atLineEnding(code) {
  323. effects.exit('htmlTextData')
  324. effects.enter('lineEnding')
  325. effects.consume(code)
  326. effects.exit('lineEnding')
  327. return factorySpace(
  328. effects,
  329. afterPrefix,
  330. 'linePrefix',
  331. self.parser.constructs.disable.null.indexOf('codeIndented') > -1
  332. ? undefined
  333. : 4
  334. )
  335. }
  336. function afterPrefix(code) {
  337. effects.enter('htmlTextData')
  338. return returnState(code)
  339. }
  340. function end(code) {
  341. if (code === 62) {
  342. effects.consume(code)
  343. effects.exit('htmlTextData')
  344. effects.exit('htmlText')
  345. return ok
  346. }
  347. return nok(code)
  348. }
  349. }
  350. module.exports = htmlText