1
0

Scopes.swift 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. //
  2. // HttpHandlers+Scopes.swift
  3. // Swifter
  4. //
  5. // Copyright © 2014-2016 Damian Kołakowski. All rights reserved.
  6. //
  7. // swiftlint:disable file_length
  8. import Foundation
  9. public func scopes(_ scope: @escaping Closure) -> ((HttpRequest) -> HttpResponse) {
  10. return { _ in
  11. scopesBuffer[Process.tid] = ""
  12. scope()
  13. return .raw(200, "OK", ["Content-Type": "text/html"], {
  14. try? $0.write([UInt8](("<!DOCTYPE html>" + (scopesBuffer[Process.tid] ?? "")).utf8))
  15. })
  16. }
  17. }
  18. public typealias Closure = () -> Void
  19. public var idd: String?
  20. public var dir: String?
  21. public var rel: String?
  22. public var rev: String?
  23. public var alt: String?
  24. public var forr: String?
  25. public var src: String?
  26. public var type: String?
  27. public var href: String?
  28. public var text: String?
  29. public var abbr: String?
  30. public var size: String?
  31. public var face: String?
  32. public var char: String?
  33. public var cite: String?
  34. public var span: String?
  35. public var data: String?
  36. public var axis: String?
  37. public var Name: String?
  38. public var name: String?
  39. public var code: String?
  40. public var link: String?
  41. public var lang: String?
  42. public var cols: String?
  43. public var rows: String?
  44. public var ismap: String?
  45. public var shape: String?
  46. public var style: String?
  47. public var alink: String?
  48. public var width: String?
  49. public var rules: String?
  50. public var align: String?
  51. public var frame: String?
  52. public var vlink: String?
  53. public var deferr: String?
  54. public var color: String?
  55. public var media: String?
  56. public var title: String?
  57. public var scope: String?
  58. public var classs: String?
  59. public var value: String?
  60. public var clear: String?
  61. public var start: String?
  62. public var label: String?
  63. public var action: String?
  64. public var height: String?
  65. public var method: String?
  66. public var acceptt: String?
  67. public var object: String?
  68. public var scheme: String?
  69. public var coords: String?
  70. public var usemap: String?
  71. public var onblur: String?
  72. public var nohref: String?
  73. public var nowrap: String?
  74. public var hspace: String?
  75. public var border: String?
  76. public var valign: String?
  77. public var vspace: String?
  78. public var onload: String?
  79. public var target: String?
  80. public var prompt: String?
  81. public var onfocus: String?
  82. public var enctype: String?
  83. public var onclick: String?
  84. public var onkeyup: String?
  85. public var profile: String?
  86. public var version: String?
  87. public var onreset: String?
  88. public var charset: String?
  89. public var standby: String?
  90. public var colspan: String?
  91. public var charoff: String?
  92. public var classid: String?
  93. public var compact: String?
  94. public var declare: String?
  95. public var rowspan: String?
  96. public var checked: String?
  97. public var archive: String?
  98. public var bgcolor: String?
  99. public var content: String?
  100. public var noshade: String?
  101. public var summary: String?
  102. public var headers: String?
  103. public var onselect: String?
  104. public var readonly: String?
  105. public var tabindex: String?
  106. public var onchange: String?
  107. public var noresize: String?
  108. public var disabled: String?
  109. public var longdesc: String?
  110. public var codebase: String?
  111. public var language: String?
  112. public var datetime: String?
  113. public var selected: String?
  114. public var hreflang: String?
  115. public var onsubmit: String?
  116. public var multiple: String?
  117. public var onunload: String?
  118. public var codetype: String?
  119. public var scrolling: String?
  120. public var onkeydown: String?
  121. public var maxlength: String?
  122. public var valuetype: String?
  123. public var accesskey: String?
  124. public var onmouseup: String?
  125. public var autofocus: String?
  126. public var onkeypress: String?
  127. public var ondblclick: String?
  128. public var onmouseout: String?
  129. public var httpEquiv: String?
  130. public var background: String?
  131. public var onmousemove: String?
  132. public var onmouseover: String?
  133. public var cellpadding: String?
  134. public var onmousedown: String?
  135. public var frameborder: String?
  136. public var marginwidth: String?
  137. public var cellspacing: String?
  138. public var placeholder: String?
  139. public var marginheight: String?
  140. public var acceptCharset: String?
  141. public var inner: String?
  142. public func a(_ closure: Closure) { element("a", closure) }
  143. public func b(_ closure: Closure) { element("b", closure) }
  144. public func i(_ closure: Closure) { element("i", closure) }
  145. public func p(_ closure: Closure) { element("p", closure) }
  146. public func q(_ closure: Closure) { element("q", closure) }
  147. public func s(_ closure: Closure) { element("s", closure) }
  148. public func u(_ closure: Closure) { element("u", closure) }
  149. public func br(_ closure: Closure) { element("br", closure) }
  150. public func dd(_ closure: Closure) { element("dd", closure) }
  151. public func dl(_ closure: Closure) { element("dl", closure) }
  152. public func dt(_ closure: Closure) { element("dt", closure) }
  153. public func em(_ closure: Closure) { element("em", closure) }
  154. public func hr(_ closure: Closure) { element("hr", closure) }
  155. public func li(_ closure: Closure) { element("li", closure) }
  156. public func ol(_ closure: Closure) { element("ol", closure) }
  157. public func rp(_ closure: Closure) { element("rp", closure) }
  158. public func rt(_ closure: Closure) { element("rt", closure) }
  159. public func td(_ closure: Closure) { element("td", closure) }
  160. public func th(_ closure: Closure) { element("th", closure) }
  161. public func tr(_ closure: Closure) { element("tr", closure) }
  162. public func tt(_ closure: Closure) { element("tt", closure) }
  163. public func ul(_ closure: Closure) { element("ul", closure) }
  164. public func ul<T: Sequence>(_ collection: T, _ closure: @escaping (T.Iterator.Element) -> Void) {
  165. element("ul", {
  166. for item in collection {
  167. closure(item)
  168. }
  169. })
  170. }
  171. public func h1(_ closure: Closure) { element("h1", closure) }
  172. public func h2(_ closure: Closure) { element("h2", closure) }
  173. public func h3(_ closure: Closure) { element("h3", closure) }
  174. public func h4(_ closure: Closure) { element("h4", closure) }
  175. public func h5(_ closure: Closure) { element("h5", closure) }
  176. public func h6(_ closure: Closure) { element("h6", closure) }
  177. public func bdi(_ closure: Closure) { element("bdi", closure) }
  178. public func bdo(_ closure: Closure) { element("bdo", closure) }
  179. public func big(_ closure: Closure) { element("big", closure) }
  180. public func col(_ closure: Closure) { element("col", closure) }
  181. public func del(_ closure: Closure) { element("del", closure) }
  182. public func dfn(_ closure: Closure) { element("dfn", closure) }
  183. public func dir(_ closure: Closure) { element("dir", closure) }
  184. public func div(_ closure: Closure) { element("div", closure) }
  185. public func img(_ closure: Closure) { element("img", closure) }
  186. public func ins(_ closure: Closure) { element("ins", closure) }
  187. public func kbd(_ closure: Closure) { element("kbd", closure) }
  188. public func map(_ closure: Closure) { element("map", closure) }
  189. public func nav(_ closure: Closure) { element("nav", closure) }
  190. public func pre(_ closure: Closure) { element("pre", closure) }
  191. public func rtc(_ closure: Closure) { element("rtc", closure) }
  192. public func sub(_ closure: Closure) { element("sub", closure) }
  193. public func sup(_ closure: Closure) { element("sup", closure) }
  194. public func varr(_ closure: Closure) { element("var", closure) }
  195. public func wbr(_ closure: Closure) { element("wbr", closure) }
  196. public func xmp(_ closure: Closure) { element("xmp", closure) }
  197. public func abbr(_ closure: Closure) { element("abbr", closure) }
  198. public func area(_ closure: Closure) { element("area", closure) }
  199. public func base(_ closure: Closure) { element("base", closure) }
  200. public func body(_ closure: Closure) { element("body", closure) }
  201. public func cite(_ closure: Closure) { element("cite", closure) }
  202. public func code(_ closure: Closure) { element("code", closure) }
  203. public func data(_ closure: Closure) { element("data", closure) }
  204. public func font(_ closure: Closure) { element("font", closure) }
  205. public func form(_ closure: Closure) { element("form", closure) }
  206. public func head(_ closure: Closure) { element("head", closure) }
  207. public func html(_ closure: Closure) { element("html", closure) }
  208. public func link(_ closure: Closure) { element("link", closure) }
  209. public func main(_ closure: Closure) { element("main", closure) }
  210. public func mark(_ closure: Closure) { element("mark", closure) }
  211. public func menu(_ closure: Closure) { element("menu", closure) }
  212. public func meta(_ closure: Closure) { element("meta", closure) }
  213. public func nobr(_ closure: Closure) { element("nobr", closure) }
  214. public func ruby(_ closure: Closure) { element("ruby", closure) }
  215. public func samp(_ closure: Closure) { element("samp", closure) }
  216. public func span(_ closure: Closure) { element("span", closure) }
  217. public func time(_ closure: Closure) { element("time", closure) }
  218. public func aside(_ closure: Closure) { element("aside", closure) }
  219. public func audio(_ closure: Closure) { element("audio", closure) }
  220. public func blink(_ closure: Closure) { element("blink", closure) }
  221. public func embed(_ closure: Closure) { element("embed", closure) }
  222. public func frame(_ closure: Closure) { element("frame", closure) }
  223. public func image(_ closure: Closure) { element("image", closure) }
  224. public func input(_ closure: Closure) { element("input", closure) }
  225. public func label(_ closure: Closure) { element("label", closure) }
  226. public func meter(_ closure: Closure) { element("meter", closure) }
  227. public func param(_ closure: Closure) { element("param", closure) }
  228. public func small(_ closure: Closure) { element("small", closure) }
  229. public func style(_ closure: Closure) { element("style", closure) }
  230. public func table(_ closure: Closure) { element("table", closure) }
  231. public func table<T: Sequence>(_ collection: T, closure: @escaping (T.Iterator.Element) -> Void) {
  232. element("table", {
  233. for item in collection {
  234. closure(item)
  235. }
  236. })
  237. }
  238. public func tbody(_ closure: Closure) { element("tbody", closure) }
  239. public func tbody<T: Sequence>(_ collection: T, closure: @escaping (T.Iterator.Element) -> Void) {
  240. element("tbody", {
  241. for item in collection {
  242. closure(item)
  243. }
  244. })
  245. }
  246. public func tfoot(_ closure: Closure) { element("tfoot", closure) }
  247. public func thead(_ closure: Closure) { element("thead", closure) }
  248. public func title(_ closure: Closure) { element("title", closure) }
  249. public func track(_ closure: Closure) { element("track", closure) }
  250. public func video(_ closure: Closure) { element("video", closure) }
  251. public func applet(_ closure: Closure) { element("applet", closure) }
  252. public func button(_ closure: Closure) { element("button", closure) }
  253. public func canvas(_ closure: Closure) { element("canvas", closure) }
  254. public func center(_ closure: Closure) { element("center", closure) }
  255. public func dialog(_ closure: Closure) { element("dialog", closure) }
  256. public func figure(_ closure: Closure) { element("figure", closure) }
  257. public func footer(_ closure: Closure) { element("footer", closure) }
  258. public func header(_ closure: Closure) { element("header", closure) }
  259. public func hgroup(_ closure: Closure) { element("hgroup", closure) }
  260. public func iframe(_ closure: Closure) { element("iframe", closure) }
  261. public func keygen(_ closure: Closure) { element("keygen", closure) }
  262. public func legend(_ closure: Closure) { element("legend", closure) }
  263. public func object(_ closure: Closure) { element("object", closure) }
  264. public func option(_ closure: Closure) { element("option", closure) }
  265. public func output(_ closure: Closure) { element("output", closure) }
  266. public func script(_ closure: Closure) { element("script", closure) }
  267. public func select(_ closure: Closure) { element("select", closure) }
  268. public func shadow(_ closure: Closure) { element("shadow", closure) }
  269. public func source(_ closure: Closure) { element("source", closure) }
  270. public func spacer(_ closure: Closure) { element("spacer", closure) }
  271. public func strike(_ closure: Closure) { element("strike", closure) }
  272. public func strong(_ closure: Closure) { element("strong", closure) }
  273. public func acronym(_ closure: Closure) { element("acronym", closure) }
  274. public func address(_ closure: Closure) { element("address", closure) }
  275. public func article(_ closure: Closure) { element("article", closure) }
  276. public func bgsound(_ closure: Closure) { element("bgsound", closure) }
  277. public func caption(_ closure: Closure) { element("caption", closure) }
  278. public func command(_ closure: Closure) { element("command", closure) }
  279. public func content(_ closure: Closure) { element("content", closure) }
  280. public func details(_ closure: Closure) { element("details", closure) }
  281. public func elementt(_ closure: Closure) { element("element", closure) }
  282. public func isindex(_ closure: Closure) { element("isindex", closure) }
  283. public func listing(_ closure: Closure) { element("listing", closure) }
  284. public func marquee(_ closure: Closure) { element("marquee", closure) }
  285. public func noembed(_ closure: Closure) { element("noembed", closure) }
  286. public func picture(_ closure: Closure) { element("picture", closure) }
  287. public func section(_ closure: Closure) { element("section", closure) }
  288. public func summary(_ closure: Closure) { element("summary", closure) }
  289. public func basefont(_ closure: Closure) { element("basefont", closure) }
  290. public func colgroup(_ closure: Closure) { element("colgroup", closure) }
  291. public func datalist(_ closure: Closure) { element("datalist", closure) }
  292. public func fieldset(_ closure: Closure) { element("fieldset", closure) }
  293. public func frameset(_ closure: Closure) { element("frameset", closure) }
  294. public func menuitem(_ closure: Closure) { element("menuitem", closure) }
  295. public func multicol(_ closure: Closure) { element("multicol", closure) }
  296. public func noframes(_ closure: Closure) { element("noframes", closure) }
  297. public func noscript(_ closure: Closure) { element("noscript", closure) }
  298. public func optgroup(_ closure: Closure) { element("optgroup", closure) }
  299. public func progress(_ closure: Closure) { element("progress", closure) }
  300. public func template(_ closure: Closure) { element("template", closure) }
  301. public func textarea(_ closure: Closure) { element("textarea", closure) }
  302. public func plaintext(_ closure: Closure) { element("plaintext", closure) }
  303. public func javascript(_ closure: Closure) { element("script", ["type": "text/javascript"], closure) }
  304. public func blockquote(_ closure: Closure) { element("blockquote", closure) }
  305. public func figcaption(_ closure: Closure) { element("figcaption", closure) }
  306. public func stylesheet(_ closure: Closure) { element("link", ["rel": "stylesheet", "type": "text/css"], closure) }
  307. public func element(_ node: String, _ closure: Closure) { evaluate(node, [:], closure) }
  308. public func element(_ node: String, _ attrs: [String: String?] = [:], _ closure: Closure) { evaluate(node, attrs, closure) }
  309. var scopesBuffer = [UInt64: String]()
  310. // swiftlint:disable cyclomatic_complexity function_body_length
  311. private func evaluate(_ node: String, _ attrs: [String: String?] = [:], _ closure: Closure) {
  312. // Push the attributes.
  313. let stackid = idd
  314. let stackdir = dir
  315. let stackrel = rel
  316. let stackrev = rev
  317. let stackalt = alt
  318. let stackfor = forr
  319. let stacksrc = src
  320. let stacktype = type
  321. let stackhref = href
  322. let stacktext = text
  323. let stackabbr = abbr
  324. let stacksize = size
  325. let stackface = face
  326. let stackchar = char
  327. let stackcite = cite
  328. let stackspan = span
  329. let stackdata = data
  330. let stackaxis = axis
  331. let stackName = Name
  332. let stackname = name
  333. let stackcode = code
  334. let stacklink = link
  335. let stacklang = lang
  336. let stackcols = cols
  337. let stackrows = rows
  338. let stackismap = ismap
  339. let stackshape = shape
  340. let stackstyle = style
  341. let stackalink = alink
  342. let stackwidth = width
  343. let stackrules = rules
  344. let stackalign = align
  345. let stackframe = frame
  346. let stackvlink = vlink
  347. let stackdefer = deferr
  348. let stackcolor = color
  349. let stackmedia = media
  350. let stacktitle = title
  351. let stackscope = scope
  352. let stackclass = classs
  353. let stackvalue = value
  354. let stackclear = clear
  355. let stackstart = start
  356. let stacklabel = label
  357. let stackaction = action
  358. let stackheight = height
  359. let stackmethod = method
  360. let stackaccept = acceptt
  361. let stackobject = object
  362. let stackscheme = scheme
  363. let stackcoords = coords
  364. let stackusemap = usemap
  365. let stackonblur = onblur
  366. let stacknohref = nohref
  367. let stacknowrap = nowrap
  368. let stackhspace = hspace
  369. let stackborder = border
  370. let stackvalign = valign
  371. let stackvspace = vspace
  372. let stackonload = onload
  373. let stacktarget = target
  374. let stackprompt = prompt
  375. let stackonfocus = onfocus
  376. let stackenctype = enctype
  377. let stackonclick = onclick
  378. let stackonkeyup = onkeyup
  379. let stackprofile = profile
  380. let stackversion = version
  381. let stackonreset = onreset
  382. let stackcharset = charset
  383. let stackstandby = standby
  384. let stackcolspan = colspan
  385. let stackcharoff = charoff
  386. let stackclassid = classid
  387. let stackcompact = compact
  388. let stackdeclare = declare
  389. let stackrowspan = rowspan
  390. let stackchecked = checked
  391. let stackarchive = archive
  392. let stackbgcolor = bgcolor
  393. let stackcontent = content
  394. let stacknoshade = noshade
  395. let stacksummary = summary
  396. let stackheaders = headers
  397. let stackonselect = onselect
  398. let stackreadonly = readonly
  399. let stacktabindex = tabindex
  400. let stackonchange = onchange
  401. let stacknoresize = noresize
  402. let stackdisabled = disabled
  403. let stacklongdesc = longdesc
  404. let stackcodebase = codebase
  405. let stacklanguage = language
  406. let stackdatetime = datetime
  407. let stackselected = selected
  408. let stackhreflang = hreflang
  409. let stackonsubmit = onsubmit
  410. let stackmultiple = multiple
  411. let stackonunload = onunload
  412. let stackcodetype = codetype
  413. let stackscrolling = scrolling
  414. let stackonkeydown = onkeydown
  415. let stackmaxlength = maxlength
  416. let stackvaluetype = valuetype
  417. let stackaccesskey = accesskey
  418. let stackonmouseup = onmouseup
  419. let stackonkeypress = onkeypress
  420. let stackondblclick = ondblclick
  421. let stackonmouseout = onmouseout
  422. let stackhttpEquiv = httpEquiv
  423. let stackbackground = background
  424. let stackonmousemove = onmousemove
  425. let stackonmouseover = onmouseover
  426. let stackcellpadding = cellpadding
  427. let stackonmousedown = onmousedown
  428. let stackframeborder = frameborder
  429. let stackmarginwidth = marginwidth
  430. let stackcellspacing = cellspacing
  431. let stackplaceholder = placeholder
  432. let stackmarginheight = marginheight
  433. let stackacceptCharset = acceptCharset
  434. let stackinner = inner
  435. // Reset the values before a nested scope evalutation.
  436. idd = nil
  437. dir = nil
  438. rel = nil
  439. rev = nil
  440. alt = nil
  441. forr = nil
  442. src = nil
  443. type = nil
  444. href = nil
  445. text = nil
  446. abbr = nil
  447. size = nil
  448. face = nil
  449. char = nil
  450. cite = nil
  451. span = nil
  452. data = nil
  453. axis = nil
  454. Name = nil
  455. name = nil
  456. code = nil
  457. link = nil
  458. lang = nil
  459. cols = nil
  460. rows = nil
  461. ismap = nil
  462. shape = nil
  463. style = nil
  464. alink = nil
  465. width = nil
  466. rules = nil
  467. align = nil
  468. frame = nil
  469. vlink = nil
  470. deferr = nil
  471. color = nil
  472. media = nil
  473. title = nil
  474. scope = nil
  475. classs = nil
  476. value = nil
  477. clear = nil
  478. start = nil
  479. label = nil
  480. action = nil
  481. height = nil
  482. method = nil
  483. acceptt = nil
  484. object = nil
  485. scheme = nil
  486. coords = nil
  487. usemap = nil
  488. onblur = nil
  489. nohref = nil
  490. nowrap = nil
  491. hspace = nil
  492. border = nil
  493. valign = nil
  494. vspace = nil
  495. onload = nil
  496. target = nil
  497. prompt = nil
  498. onfocus = nil
  499. enctype = nil
  500. onclick = nil
  501. onkeyup = nil
  502. profile = nil
  503. version = nil
  504. onreset = nil
  505. charset = nil
  506. standby = nil
  507. colspan = nil
  508. charoff = nil
  509. classid = nil
  510. compact = nil
  511. declare = nil
  512. rowspan = nil
  513. checked = nil
  514. archive = nil
  515. bgcolor = nil
  516. content = nil
  517. noshade = nil
  518. summary = nil
  519. headers = nil
  520. onselect = nil
  521. readonly = nil
  522. tabindex = nil
  523. onchange = nil
  524. noresize = nil
  525. disabled = nil
  526. longdesc = nil
  527. codebase = nil
  528. language = nil
  529. datetime = nil
  530. selected = nil
  531. hreflang = nil
  532. onsubmit = nil
  533. multiple = nil
  534. onunload = nil
  535. codetype = nil
  536. scrolling = nil
  537. onkeydown = nil
  538. maxlength = nil
  539. valuetype = nil
  540. accesskey = nil
  541. onmouseup = nil
  542. onkeypress = nil
  543. ondblclick = nil
  544. onmouseout = nil
  545. httpEquiv = nil
  546. background = nil
  547. onmousemove = nil
  548. onmouseover = nil
  549. cellpadding = nil
  550. onmousedown = nil
  551. frameborder = nil
  552. placeholder = nil
  553. marginwidth = nil
  554. cellspacing = nil
  555. marginheight = nil
  556. acceptCharset = nil
  557. inner = nil
  558. scopesBuffer[Process.tid] = (scopesBuffer[Process.tid] ?? "") + "<" + node
  559. // Save the current output before the nested scope evalutation.
  560. var output = scopesBuffer[Process.tid] ?? ""
  561. // Clear the output buffer for the evalutation.
  562. scopesBuffer[Process.tid] = ""
  563. // Evaluate the nested scope.
  564. closure()
  565. // Render attributes set by the evalutation.
  566. var mergedAttributes = [String: String?]()
  567. if let idd = idd { mergedAttributes["id"] = idd }
  568. if let dir = dir { mergedAttributes["dir"] = dir }
  569. if let rel = rel { mergedAttributes["rel"] = rel }
  570. if let rev = rev { mergedAttributes["rev"] = rev }
  571. if let alt = alt { mergedAttributes["alt"] = alt }
  572. if let forr = forr { mergedAttributes["for"] = forr }
  573. if let src = src { mergedAttributes["src"] = src }
  574. if let type = type { mergedAttributes["type"] = type }
  575. if let href = href { mergedAttributes["href"] = href }
  576. if let text = text { mergedAttributes["text"] = text }
  577. if let abbr = abbr { mergedAttributes["abbr"] = abbr }
  578. if let size = size { mergedAttributes["size"] = size }
  579. if let face = face { mergedAttributes["face"] = face }
  580. if let char = char { mergedAttributes["char"] = char }
  581. if let cite = cite { mergedAttributes["cite"] = cite }
  582. if let span = span { mergedAttributes["span"] = span }
  583. if let data = data { mergedAttributes["data"] = data }
  584. if let axis = axis { mergedAttributes["axis"] = axis }
  585. if let Name = Name { mergedAttributes["Name"] = Name }
  586. if let name = name { mergedAttributes["name"] = name }
  587. if let code = code { mergedAttributes["code"] = code }
  588. if let link = link { mergedAttributes["link"] = link }
  589. if let lang = lang { mergedAttributes["lang"] = lang }
  590. if let cols = cols { mergedAttributes["cols"] = cols }
  591. if let rows = rows { mergedAttributes["rows"] = rows }
  592. if let ismap = ismap { mergedAttributes["ismap"] = ismap }
  593. if let shape = shape { mergedAttributes["shape"] = shape }
  594. if let style = style { mergedAttributes["style"] = style }
  595. if let alink = alink { mergedAttributes["alink"] = alink }
  596. if let width = width { mergedAttributes["width"] = width }
  597. if let rules = rules { mergedAttributes["rules"] = rules }
  598. if let align = align { mergedAttributes["align"] = align }
  599. if let frame = frame { mergedAttributes["frame"] = frame }
  600. if let vlink = vlink { mergedAttributes["vlink"] = vlink }
  601. if let deferr = deferr { mergedAttributes["defer"] = deferr }
  602. if let color = color { mergedAttributes["color"] = color }
  603. if let media = media { mergedAttributes["media"] = media }
  604. if let title = title { mergedAttributes["title"] = title }
  605. if let scope = scope { mergedAttributes["scope"] = scope }
  606. if let classs = classs { mergedAttributes["class"] = classs }
  607. if let value = value { mergedAttributes["value"] = value }
  608. if let clear = clear { mergedAttributes["clear"] = clear }
  609. if let start = start { mergedAttributes["start"] = start }
  610. if let label = label { mergedAttributes["label"] = label }
  611. if let action = action { mergedAttributes["action"] = action }
  612. if let height = height { mergedAttributes["height"] = height }
  613. if let method = method { mergedAttributes["method"] = method }
  614. if let acceptt = acceptt { mergedAttributes["accept"] = acceptt }
  615. if let object = object { mergedAttributes["object"] = object }
  616. if let scheme = scheme { mergedAttributes["scheme"] = scheme }
  617. if let coords = coords { mergedAttributes["coords"] = coords }
  618. if let usemap = usemap { mergedAttributes["usemap"] = usemap }
  619. if let onblur = onblur { mergedAttributes["onblur"] = onblur }
  620. if let nohref = nohref { mergedAttributes["nohref"] = nohref }
  621. if let nowrap = nowrap { mergedAttributes["nowrap"] = nowrap }
  622. if let hspace = hspace { mergedAttributes["hspace"] = hspace }
  623. if let border = border { mergedAttributes["border"] = border }
  624. if let valign = valign { mergedAttributes["valign"] = valign }
  625. if let vspace = vspace { mergedAttributes["vspace"] = vspace }
  626. if let onload = onload { mergedAttributes["onload"] = onload }
  627. if let target = target { mergedAttributes["target"] = target }
  628. if let prompt = prompt { mergedAttributes["prompt"] = prompt }
  629. if let onfocus = onfocus { mergedAttributes["onfocus"] = onfocus }
  630. if let enctype = enctype { mergedAttributes["enctype"] = enctype }
  631. if let onclick = onclick { mergedAttributes["onclick"] = onclick }
  632. if let onkeyup = onkeyup { mergedAttributes["onkeyup"] = onkeyup }
  633. if let profile = profile { mergedAttributes["profile"] = profile }
  634. if let version = version { mergedAttributes["version"] = version }
  635. if let onreset = onreset { mergedAttributes["onreset"] = onreset }
  636. if let charset = charset { mergedAttributes["charset"] = charset }
  637. if let standby = standby { mergedAttributes["standby"] = standby }
  638. if let colspan = colspan { mergedAttributes["colspan"] = colspan }
  639. if let charoff = charoff { mergedAttributes["charoff"] = charoff }
  640. if let classid = classid { mergedAttributes["classid"] = classid }
  641. if let compact = compact { mergedAttributes["compact"] = compact }
  642. if let declare = declare { mergedAttributes["declare"] = declare }
  643. if let rowspan = rowspan { mergedAttributes["rowspan"] = rowspan }
  644. if let checked = checked { mergedAttributes["checked"] = checked }
  645. if let archive = archive { mergedAttributes["archive"] = archive }
  646. if let bgcolor = bgcolor { mergedAttributes["bgcolor"] = bgcolor }
  647. if let content = content { mergedAttributes["content"] = content }
  648. if let noshade = noshade { mergedAttributes["noshade"] = noshade }
  649. if let summary = summary { mergedAttributes["summary"] = summary }
  650. if let headers = headers { mergedAttributes["headers"] = headers }
  651. if let onselect = onselect { mergedAttributes["onselect"] = onselect }
  652. if let readonly = readonly { mergedAttributes["readonly"] = readonly }
  653. if let tabindex = tabindex { mergedAttributes["tabindex"] = tabindex }
  654. if let onchange = onchange { mergedAttributes["onchange"] = onchange }
  655. if let noresize = noresize { mergedAttributes["noresize"] = noresize }
  656. if let disabled = disabled { mergedAttributes["disabled"] = disabled }
  657. if let longdesc = longdesc { mergedAttributes["longdesc"] = longdesc }
  658. if let codebase = codebase { mergedAttributes["codebase"] = codebase }
  659. if let language = language { mergedAttributes["language"] = language }
  660. if let datetime = datetime { mergedAttributes["datetime"] = datetime }
  661. if let selected = selected { mergedAttributes["selected"] = selected }
  662. if let hreflang = hreflang { mergedAttributes["hreflang"] = hreflang }
  663. if let onsubmit = onsubmit { mergedAttributes["onsubmit"] = onsubmit }
  664. if let multiple = multiple { mergedAttributes["multiple"] = multiple }
  665. if let onunload = onunload { mergedAttributes["onunload"] = onunload }
  666. if let codetype = codetype { mergedAttributes["codetype"] = codetype }
  667. if let scrolling = scrolling { mergedAttributes["scrolling"] = scrolling }
  668. if let onkeydown = onkeydown { mergedAttributes["onkeydown"] = onkeydown }
  669. if let maxlength = maxlength { mergedAttributes["maxlength"] = maxlength }
  670. if let valuetype = valuetype { mergedAttributes["valuetype"] = valuetype }
  671. if let accesskey = accesskey { mergedAttributes["accesskey"] = accesskey }
  672. if let onmouseup = onmouseup { mergedAttributes["onmouseup"] = onmouseup }
  673. if let onkeypress = onkeypress { mergedAttributes["onkeypress"] = onkeypress }
  674. if let ondblclick = ondblclick { mergedAttributes["ondblclick"] = ondblclick }
  675. if let onmouseout = onmouseout { mergedAttributes["onmouseout"] = onmouseout }
  676. if let httpEquiv = httpEquiv { mergedAttributes["http-equiv"] = httpEquiv }
  677. if let background = background { mergedAttributes["background"] = background }
  678. if let onmousemove = onmousemove { mergedAttributes["onmousemove"] = onmousemove }
  679. if let onmouseover = onmouseover { mergedAttributes["onmouseover"] = onmouseover }
  680. if let cellpadding = cellpadding { mergedAttributes["cellpadding"] = cellpadding }
  681. if let onmousedown = onmousedown { mergedAttributes["onmousedown"] = onmousedown }
  682. if let frameborder = frameborder { mergedAttributes["frameborder"] = frameborder }
  683. if let marginwidth = marginwidth { mergedAttributes["marginwidth"] = marginwidth }
  684. if let cellspacing = cellspacing { mergedAttributes["cellspacing"] = cellspacing }
  685. if let placeholder = placeholder { mergedAttributes["placeholder"] = placeholder }
  686. if let marginheight = marginheight { mergedAttributes["marginheight"] = marginheight }
  687. if let acceptCharset = acceptCharset { mergedAttributes["accept-charset"] = acceptCharset }
  688. for item in attrs.enumerated() {
  689. mergedAttributes.updateValue(item.element.1, forKey: item.element.0)
  690. }
  691. output += mergedAttributes.reduce("") { result, item in
  692. if let value = item.value {
  693. return result + " \(item.key)=\"\(value)\""
  694. } else {
  695. return result
  696. }
  697. }
  698. if let inner = inner {
  699. scopesBuffer[Process.tid] = output + ">" + (inner) + "</" + node + ">"
  700. } else {
  701. let current = scopesBuffer[Process.tid] ?? ""
  702. scopesBuffer[Process.tid] = output + ">" + current + "</" + node + ">"
  703. }
  704. // Pop the attributes.
  705. idd = stackid
  706. dir = stackdir
  707. rel = stackrel
  708. rev = stackrev
  709. alt = stackalt
  710. forr = stackfor
  711. src = stacksrc
  712. type = stacktype
  713. href = stackhref
  714. text = stacktext
  715. abbr = stackabbr
  716. size = stacksize
  717. face = stackface
  718. char = stackchar
  719. cite = stackcite
  720. span = stackspan
  721. data = stackdata
  722. axis = stackaxis
  723. Name = stackName
  724. name = stackname
  725. code = stackcode
  726. link = stacklink
  727. lang = stacklang
  728. cols = stackcols
  729. rows = stackrows
  730. ismap = stackismap
  731. shape = stackshape
  732. style = stackstyle
  733. alink = stackalink
  734. width = stackwidth
  735. rules = stackrules
  736. align = stackalign
  737. frame = stackframe
  738. vlink = stackvlink
  739. deferr = stackdefer
  740. color = stackcolor
  741. media = stackmedia
  742. title = stacktitle
  743. scope = stackscope
  744. classs = stackclass
  745. value = stackvalue
  746. clear = stackclear
  747. start = stackstart
  748. label = stacklabel
  749. action = stackaction
  750. height = stackheight
  751. method = stackmethod
  752. acceptt = stackaccept
  753. object = stackobject
  754. scheme = stackscheme
  755. coords = stackcoords
  756. usemap = stackusemap
  757. onblur = stackonblur
  758. nohref = stacknohref
  759. nowrap = stacknowrap
  760. hspace = stackhspace
  761. border = stackborder
  762. valign = stackvalign
  763. vspace = stackvspace
  764. onload = stackonload
  765. target = stacktarget
  766. prompt = stackprompt
  767. onfocus = stackonfocus
  768. enctype = stackenctype
  769. onclick = stackonclick
  770. onkeyup = stackonkeyup
  771. profile = stackprofile
  772. version = stackversion
  773. onreset = stackonreset
  774. charset = stackcharset
  775. standby = stackstandby
  776. colspan = stackcolspan
  777. charoff = stackcharoff
  778. classid = stackclassid
  779. compact = stackcompact
  780. declare = stackdeclare
  781. rowspan = stackrowspan
  782. checked = stackchecked
  783. archive = stackarchive
  784. bgcolor = stackbgcolor
  785. content = stackcontent
  786. noshade = stacknoshade
  787. summary = stacksummary
  788. headers = stackheaders
  789. onselect = stackonselect
  790. readonly = stackreadonly
  791. tabindex = stacktabindex
  792. onchange = stackonchange
  793. noresize = stacknoresize
  794. disabled = stackdisabled
  795. longdesc = stacklongdesc
  796. codebase = stackcodebase
  797. language = stacklanguage
  798. datetime = stackdatetime
  799. selected = stackselected
  800. hreflang = stackhreflang
  801. onsubmit = stackonsubmit
  802. multiple = stackmultiple
  803. onunload = stackonunload
  804. codetype = stackcodetype
  805. scrolling = stackscrolling
  806. onkeydown = stackonkeydown
  807. maxlength = stackmaxlength
  808. valuetype = stackvaluetype
  809. accesskey = stackaccesskey
  810. onmouseup = stackonmouseup
  811. onkeypress = stackonkeypress
  812. ondblclick = stackondblclick
  813. onmouseout = stackonmouseout
  814. httpEquiv = stackhttpEquiv
  815. background = stackbackground
  816. onmousemove = stackonmousemove
  817. onmouseover = stackonmouseover
  818. cellpadding = stackcellpadding
  819. onmousedown = stackonmousedown
  820. frameborder = stackframeborder
  821. placeholder = stackplaceholder
  822. marginwidth = stackmarginwidth
  823. cellspacing = stackcellspacing
  824. marginheight = stackmarginheight
  825. acceptCharset = stackacceptCharset
  826. inner = stackinner
  827. }