nokolexbor 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (486) hide show
  1. checksums.yaml +7 -0
  2. data/ext/nokolexbor/config.h +186 -0
  3. data/ext/nokolexbor/extconf.rb +131 -0
  4. data/ext/nokolexbor/libxml/HTMLparser.h +320 -0
  5. data/ext/nokolexbor/libxml/SAX2.h +173 -0
  6. data/ext/nokolexbor/libxml/chvalid.h +230 -0
  7. data/ext/nokolexbor/libxml/debugXML.h +217 -0
  8. data/ext/nokolexbor/libxml/dict.h +81 -0
  9. data/ext/nokolexbor/libxml/encoding.h +232 -0
  10. data/ext/nokolexbor/libxml/entities.h +153 -0
  11. data/ext/nokolexbor/libxml/globals.h +529 -0
  12. data/ext/nokolexbor/libxml/hash.h +236 -0
  13. data/ext/nokolexbor/libxml/list.h +137 -0
  14. data/ext/nokolexbor/libxml/parser.h +1264 -0
  15. data/ext/nokolexbor/libxml/parserInternals.h +641 -0
  16. data/ext/nokolexbor/libxml/pattern.h +100 -0
  17. data/ext/nokolexbor/libxml/threads.h +94 -0
  18. data/ext/nokolexbor/libxml/tree.h +1315 -0
  19. data/ext/nokolexbor/libxml/uri.h +94 -0
  20. data/ext/nokolexbor/libxml/valid.h +448 -0
  21. data/ext/nokolexbor/libxml/xmlIO.h +369 -0
  22. data/ext/nokolexbor/libxml/xmlautomata.h +146 -0
  23. data/ext/nokolexbor/libxml/xmlerror.h +919 -0
  24. data/ext/nokolexbor/libxml/xmlexports.h +79 -0
  25. data/ext/nokolexbor/libxml/xmlmemory.h +226 -0
  26. data/ext/nokolexbor/libxml/xmlregexp.h +222 -0
  27. data/ext/nokolexbor/libxml/xmlstring.h +140 -0
  28. data/ext/nokolexbor/libxml/xmlversion.h +526 -0
  29. data/ext/nokolexbor/libxml/xpath.h +575 -0
  30. data/ext/nokolexbor/libxml/xpathInternals.h +632 -0
  31. data/ext/nokolexbor/libxml/xpointer.h +137 -0
  32. data/ext/nokolexbor/libxml.h +76 -0
  33. data/ext/nokolexbor/memory.c +39 -0
  34. data/ext/nokolexbor/nl_document.c +51 -0
  35. data/ext/nokolexbor/nl_node.c +790 -0
  36. data/ext/nokolexbor/nl_node_set.c +368 -0
  37. data/ext/nokolexbor/nl_xpath_context.c +200 -0
  38. data/ext/nokolexbor/nokolexbor.c +63 -0
  39. data/ext/nokolexbor/nokolexbor.h +37 -0
  40. data/ext/nokolexbor/private/buf.h +70 -0
  41. data/ext/nokolexbor/private/dict.h +11 -0
  42. data/ext/nokolexbor/private/enc.h +17 -0
  43. data/ext/nokolexbor/private/error.h +21 -0
  44. data/ext/nokolexbor/private/globals.h +9 -0
  45. data/ext/nokolexbor/private/memory.h +9 -0
  46. data/ext/nokolexbor/private/parser.h +27 -0
  47. data/ext/nokolexbor/private/string.h +9 -0
  48. data/ext/nokolexbor/private/threads.h +50 -0
  49. data/ext/nokolexbor/private/tree.h +18 -0
  50. data/ext/nokolexbor/private/xpath.h +7 -0
  51. data/ext/nokolexbor/timsort.h +601 -0
  52. data/ext/nokolexbor/xml_SAX2.c +80 -0
  53. data/ext/nokolexbor/xml_buf.c +363 -0
  54. data/ext/nokolexbor/xml_chvalid.c +334 -0
  55. data/ext/nokolexbor/xml_dict.c +1264 -0
  56. data/ext/nokolexbor/xml_encoding.c +124 -0
  57. data/ext/nokolexbor/xml_error.c +134 -0
  58. data/ext/nokolexbor/xml_globals.c +1085 -0
  59. data/ext/nokolexbor/xml_hash.c +1141 -0
  60. data/ext/nokolexbor/xml_memory.c +203 -0
  61. data/ext/nokolexbor/xml_parser.c +127 -0
  62. data/ext/nokolexbor/xml_parserInternals.c +338 -0
  63. data/ext/nokolexbor/xml_pattern.c +2375 -0
  64. data/ext/nokolexbor/xml_string.c +1051 -0
  65. data/ext/nokolexbor/xml_threads.c +881 -0
  66. data/ext/nokolexbor/xml_tree.c +148 -0
  67. data/ext/nokolexbor/xml_xpath.c +14743 -0
  68. data/lib/nokolexbor/attribute.rb +18 -0
  69. data/lib/nokolexbor/document.rb +6 -0
  70. data/lib/nokolexbor/node.rb +264 -0
  71. data/lib/nokolexbor/node_set.rb +124 -0
  72. data/lib/nokolexbor/version.rb +5 -0
  73. data/lib/nokolexbor/xpath_context.rb +14 -0
  74. data/lib/nokolexbor.rb +17 -0
  75. data/patches/0001-lexbor-support-text-pseudo-element.patch +137 -0
  76. data/patches/0002-lexbor-match-id-class-case-sensitive.patch +22 -0
  77. data/patches/0003-lexbor-attach-template-content-to-self.patch +13 -0
  78. data/vendor/lexbor/CMakeLists.txt +331 -0
  79. data/vendor/lexbor/config.cmake +890 -0
  80. data/vendor/lexbor/feature.cmake +134 -0
  81. data/vendor/lexbor/source/lexbor/core/array.c +208 -0
  82. data/vendor/lexbor/source/lexbor/core/array.h +100 -0
  83. data/vendor/lexbor/source/lexbor/core/array_obj.c +216 -0
  84. data/vendor/lexbor/source/lexbor/core/array_obj.h +134 -0
  85. data/vendor/lexbor/source/lexbor/core/avl.c +442 -0
  86. data/vendor/lexbor/source/lexbor/core/avl.h +82 -0
  87. data/vendor/lexbor/source/lexbor/core/base.h +86 -0
  88. data/vendor/lexbor/source/lexbor/core/bst.c +468 -0
  89. data/vendor/lexbor/source/lexbor/core/bst.h +108 -0
  90. data/vendor/lexbor/source/lexbor/core/bst_map.c +238 -0
  91. data/vendor/lexbor/source/lexbor/core/bst_map.h +87 -0
  92. data/vendor/lexbor/source/lexbor/core/config.cmake +12 -0
  93. data/vendor/lexbor/source/lexbor/core/conv.c +203 -0
  94. data/vendor/lexbor/source/lexbor/core/conv.h +53 -0
  95. data/vendor/lexbor/source/lexbor/core/core.h +35 -0
  96. data/vendor/lexbor/source/lexbor/core/def.h +57 -0
  97. data/vendor/lexbor/source/lexbor/core/diyfp.c +153 -0
  98. data/vendor/lexbor/source/lexbor/core/diyfp.h +258 -0
  99. data/vendor/lexbor/source/lexbor/core/dobject.c +187 -0
  100. data/vendor/lexbor/source/lexbor/core/dobject.h +92 -0
  101. data/vendor/lexbor/source/lexbor/core/dtoa.c +404 -0
  102. data/vendor/lexbor/source/lexbor/core/dtoa.h +28 -0
  103. data/vendor/lexbor/source/lexbor/core/fs.h +60 -0
  104. data/vendor/lexbor/source/lexbor/core/hash.c +476 -0
  105. data/vendor/lexbor/source/lexbor/core/hash.h +218 -0
  106. data/vendor/lexbor/source/lexbor/core/in.c +267 -0
  107. data/vendor/lexbor/source/lexbor/core/in.h +172 -0
  108. data/vendor/lexbor/source/lexbor/core/lexbor.h +35 -0
  109. data/vendor/lexbor/source/lexbor/core/mem.c +228 -0
  110. data/vendor/lexbor/source/lexbor/core/mem.h +141 -0
  111. data/vendor/lexbor/source/lexbor/core/mraw.c +428 -0
  112. data/vendor/lexbor/source/lexbor/core/mraw.h +114 -0
  113. data/vendor/lexbor/source/lexbor/core/perf.h +45 -0
  114. data/vendor/lexbor/source/lexbor/core/plog.c +73 -0
  115. data/vendor/lexbor/source/lexbor/core/plog.h +102 -0
  116. data/vendor/lexbor/source/lexbor/core/print.c +168 -0
  117. data/vendor/lexbor/source/lexbor/core/print.h +39 -0
  118. data/vendor/lexbor/source/lexbor/core/sbst.h +59 -0
  119. data/vendor/lexbor/source/lexbor/core/serialize.c +27 -0
  120. data/vendor/lexbor/source/lexbor/core/serialize.h +32 -0
  121. data/vendor/lexbor/source/lexbor/core/shs.c +118 -0
  122. data/vendor/lexbor/source/lexbor/core/shs.h +82 -0
  123. data/vendor/lexbor/source/lexbor/core/str.c +617 -0
  124. data/vendor/lexbor/source/lexbor/core/str.h +247 -0
  125. data/vendor/lexbor/source/lexbor/core/str_res.h +369 -0
  126. data/vendor/lexbor/source/lexbor/core/strtod.c +326 -0
  127. data/vendor/lexbor/source/lexbor/core/strtod.h +28 -0
  128. data/vendor/lexbor/source/lexbor/core/types.h +39 -0
  129. data/vendor/lexbor/source/lexbor/core/utils.c +43 -0
  130. data/vendor/lexbor/source/lexbor/core/utils.h +36 -0
  131. data/vendor/lexbor/source/lexbor/css/base.h +44 -0
  132. data/vendor/lexbor/source/lexbor/css/config.cmake +2 -0
  133. data/vendor/lexbor/source/lexbor/css/css.h +25 -0
  134. data/vendor/lexbor/source/lexbor/css/log.c +336 -0
  135. data/vendor/lexbor/source/lexbor/css/log.h +103 -0
  136. data/vendor/lexbor/source/lexbor/css/node.h +29 -0
  137. data/vendor/lexbor/source/lexbor/css/parser.c +473 -0
  138. data/vendor/lexbor/source/lexbor/css/parser.h +368 -0
  139. data/vendor/lexbor/source/lexbor/css/selectors/base.h +48 -0
  140. data/vendor/lexbor/source/lexbor/css/selectors/pseudo.c +91 -0
  141. data/vendor/lexbor/source/lexbor/css/selectors/pseudo.h +66 -0
  142. data/vendor/lexbor/source/lexbor/css/selectors/pseudo_const.h +109 -0
  143. data/vendor/lexbor/source/lexbor/css/selectors/pseudo_res.h +302 -0
  144. data/vendor/lexbor/source/lexbor/css/selectors/pseudo_state.c +279 -0
  145. data/vendor/lexbor/source/lexbor/css/selectors/pseudo_state.h +85 -0
  146. data/vendor/lexbor/source/lexbor/css/selectors/selector.c +927 -0
  147. data/vendor/lexbor/source/lexbor/css/selectors/selector.h +200 -0
  148. data/vendor/lexbor/source/lexbor/css/selectors/selectors.c +340 -0
  149. data/vendor/lexbor/source/lexbor/css/selectors/selectors.h +137 -0
  150. data/vendor/lexbor/source/lexbor/css/selectors/state.c +1718 -0
  151. data/vendor/lexbor/source/lexbor/css/selectors/state.h +79 -0
  152. data/vendor/lexbor/source/lexbor/css/stylesheet.h +37 -0
  153. data/vendor/lexbor/source/lexbor/css/syntax/anb.c +443 -0
  154. data/vendor/lexbor/source/lexbor/css/syntax/anb.h +45 -0
  155. data/vendor/lexbor/source/lexbor/css/syntax/base.h +33 -0
  156. data/vendor/lexbor/source/lexbor/css/syntax/parser.c +9 -0
  157. data/vendor/lexbor/source/lexbor/css/syntax/parser.h +25 -0
  158. data/vendor/lexbor/source/lexbor/css/syntax/res.h +48 -0
  159. data/vendor/lexbor/source/lexbor/css/syntax/state.c +2603 -0
  160. data/vendor/lexbor/source/lexbor/css/syntax/state.h +140 -0
  161. data/vendor/lexbor/source/lexbor/css/syntax/state_res.h +273 -0
  162. data/vendor/lexbor/source/lexbor/css/syntax/syntax.c +67 -0
  163. data/vendor/lexbor/source/lexbor/css/syntax/token.c +618 -0
  164. data/vendor/lexbor/source/lexbor/css/syntax/token.h +298 -0
  165. data/vendor/lexbor/source/lexbor/css/syntax/token_res.h +68 -0
  166. data/vendor/lexbor/source/lexbor/css/syntax/tokenizer/error.c +30 -0
  167. data/vendor/lexbor/source/lexbor/css/syntax/tokenizer/error.h +58 -0
  168. data/vendor/lexbor/source/lexbor/css/syntax/tokenizer.c +278 -0
  169. data/vendor/lexbor/source/lexbor/css/syntax/tokenizer.h +121 -0
  170. data/vendor/lexbor/source/lexbor/dom/base.h +32 -0
  171. data/vendor/lexbor/source/lexbor/dom/collection.c +97 -0
  172. data/vendor/lexbor/source/lexbor/dom/collection.h +112 -0
  173. data/vendor/lexbor/source/lexbor/dom/config.cmake +3 -0
  174. data/vendor/lexbor/source/lexbor/dom/dom.h +29 -0
  175. data/vendor/lexbor/source/lexbor/dom/exception.c +18 -0
  176. data/vendor/lexbor/source/lexbor/dom/exception.h +73 -0
  177. data/vendor/lexbor/source/lexbor/dom/interface.c +110 -0
  178. data/vendor/lexbor/source/lexbor/dom/interface.h +88 -0
  179. data/vendor/lexbor/source/lexbor/dom/interfaces/attr.c +445 -0
  180. data/vendor/lexbor/source/lexbor/dom/interfaces/attr.h +152 -0
  181. data/vendor/lexbor/source/lexbor/dom/interfaces/attr_const.h +62 -0
  182. data/vendor/lexbor/source/lexbor/dom/interfaces/attr_res.h +143 -0
  183. data/vendor/lexbor/source/lexbor/dom/interfaces/cdata_section.c +55 -0
  184. data/vendor/lexbor/source/lexbor/dom/interfaces/cdata_section.h +38 -0
  185. data/vendor/lexbor/source/lexbor/dom/interfaces/character_data.c +110 -0
  186. data/vendor/lexbor/source/lexbor/dom/interfaces/character_data.h +51 -0
  187. data/vendor/lexbor/source/lexbor/dom/interfaces/comment.c +64 -0
  188. data/vendor/lexbor/source/lexbor/dom/interfaces/comment.h +42 -0
  189. data/vendor/lexbor/source/lexbor/dom/interfaces/document.c +536 -0
  190. data/vendor/lexbor/source/lexbor/dom/interfaces/document.h +243 -0
  191. data/vendor/lexbor/source/lexbor/dom/interfaces/document_fragment.c +36 -0
  192. data/vendor/lexbor/source/lexbor/dom/interfaces/document_fragment.h +36 -0
  193. data/vendor/lexbor/source/lexbor/dom/interfaces/document_type.c +125 -0
  194. data/vendor/lexbor/source/lexbor/dom/interfaces/document_type.h +108 -0
  195. data/vendor/lexbor/source/lexbor/dom/interfaces/element.c +1411 -0
  196. data/vendor/lexbor/source/lexbor/dom/interfaces/element.h +319 -0
  197. data/vendor/lexbor/source/lexbor/dom/interfaces/event_target.c +32 -0
  198. data/vendor/lexbor/source/lexbor/dom/interfaces/event_target.h +34 -0
  199. data/vendor/lexbor/source/lexbor/dom/interfaces/node.c +661 -0
  200. data/vendor/lexbor/source/lexbor/dom/interfaces/node.h +192 -0
  201. data/vendor/lexbor/source/lexbor/dom/interfaces/processing_instruction.c +87 -0
  202. data/vendor/lexbor/source/lexbor/dom/interfaces/processing_instruction.h +66 -0
  203. data/vendor/lexbor/source/lexbor/dom/interfaces/shadow_root.c +36 -0
  204. data/vendor/lexbor/source/lexbor/dom/interfaces/shadow_root.h +44 -0
  205. data/vendor/lexbor/source/lexbor/dom/interfaces/text.c +63 -0
  206. data/vendor/lexbor/source/lexbor/dom/interfaces/text.h +42 -0
  207. data/vendor/lexbor/source/lexbor/encoding/base.h +218 -0
  208. data/vendor/lexbor/source/lexbor/encoding/big5.c +42839 -0
  209. data/vendor/lexbor/source/lexbor/encoding/config.cmake +12 -0
  210. data/vendor/lexbor/source/lexbor/encoding/const.h +65 -0
  211. data/vendor/lexbor/source/lexbor/encoding/decode.c +3193 -0
  212. data/vendor/lexbor/source/lexbor/encoding/decode.h +370 -0
  213. data/vendor/lexbor/source/lexbor/encoding/encode.c +1931 -0
  214. data/vendor/lexbor/source/lexbor/encoding/encode.h +377 -0
  215. data/vendor/lexbor/source/lexbor/encoding/encoding.c +252 -0
  216. data/vendor/lexbor/source/lexbor/encoding/encoding.h +475 -0
  217. data/vendor/lexbor/source/lexbor/encoding/euc_kr.c +53883 -0
  218. data/vendor/lexbor/source/lexbor/encoding/gb18030.c +47905 -0
  219. data/vendor/lexbor/source/lexbor/encoding/iso_2022_jp_katakana.c +159 -0
  220. data/vendor/lexbor/source/lexbor/encoding/jis0208.c +22477 -0
  221. data/vendor/lexbor/source/lexbor/encoding/jis0212.c +15787 -0
  222. data/vendor/lexbor/source/lexbor/encoding/multi.h +53 -0
  223. data/vendor/lexbor/source/lexbor/encoding/range.c +71 -0
  224. data/vendor/lexbor/source/lexbor/encoding/range.h +34 -0
  225. data/vendor/lexbor/source/lexbor/encoding/res.c +222 -0
  226. data/vendor/lexbor/source/lexbor/encoding/res.h +34 -0
  227. data/vendor/lexbor/source/lexbor/encoding/single.c +13748 -0
  228. data/vendor/lexbor/source/lexbor/encoding/single.h +116 -0
  229. data/vendor/lexbor/source/lexbor/html/base.h +44 -0
  230. data/vendor/lexbor/source/lexbor/html/config.cmake +3 -0
  231. data/vendor/lexbor/source/lexbor/html/encoding.c +574 -0
  232. data/vendor/lexbor/source/lexbor/html/encoding.h +106 -0
  233. data/vendor/lexbor/source/lexbor/html/html.h +107 -0
  234. data/vendor/lexbor/source/lexbor/html/interface.c +165 -0
  235. data/vendor/lexbor/source/lexbor/html/interface.h +186 -0
  236. data/vendor/lexbor/source/lexbor/html/interface_res.h +4449 -0
  237. data/vendor/lexbor/source/lexbor/html/interfaces/anchor_element.c +36 -0
  238. data/vendor/lexbor/source/lexbor/html/interfaces/anchor_element.h +34 -0
  239. data/vendor/lexbor/source/lexbor/html/interfaces/area_element.c +36 -0
  240. data/vendor/lexbor/source/lexbor/html/interfaces/area_element.h +34 -0
  241. data/vendor/lexbor/source/lexbor/html/interfaces/audio_element.c +36 -0
  242. data/vendor/lexbor/source/lexbor/html/interfaces/audio_element.h +34 -0
  243. data/vendor/lexbor/source/lexbor/html/interfaces/base_element.c +36 -0
  244. data/vendor/lexbor/source/lexbor/html/interfaces/base_element.h +34 -0
  245. data/vendor/lexbor/source/lexbor/html/interfaces/body_element.c +36 -0
  246. data/vendor/lexbor/source/lexbor/html/interfaces/body_element.h +34 -0
  247. data/vendor/lexbor/source/lexbor/html/interfaces/br_element.c +36 -0
  248. data/vendor/lexbor/source/lexbor/html/interfaces/br_element.h +34 -0
  249. data/vendor/lexbor/source/lexbor/html/interfaces/button_element.c +36 -0
  250. data/vendor/lexbor/source/lexbor/html/interfaces/button_element.h +34 -0
  251. data/vendor/lexbor/source/lexbor/html/interfaces/canvas_element.c +36 -0
  252. data/vendor/lexbor/source/lexbor/html/interfaces/canvas_element.h +34 -0
  253. data/vendor/lexbor/source/lexbor/html/interfaces/d_list_element.c +36 -0
  254. data/vendor/lexbor/source/lexbor/html/interfaces/d_list_element.h +34 -0
  255. data/vendor/lexbor/source/lexbor/html/interfaces/data_element.c +36 -0
  256. data/vendor/lexbor/source/lexbor/html/interfaces/data_element.h +34 -0
  257. data/vendor/lexbor/source/lexbor/html/interfaces/data_list_element.c +36 -0
  258. data/vendor/lexbor/source/lexbor/html/interfaces/data_list_element.h +34 -0
  259. data/vendor/lexbor/source/lexbor/html/interfaces/details_element.c +36 -0
  260. data/vendor/lexbor/source/lexbor/html/interfaces/details_element.h +34 -0
  261. data/vendor/lexbor/source/lexbor/html/interfaces/dialog_element.c +36 -0
  262. data/vendor/lexbor/source/lexbor/html/interfaces/dialog_element.h +34 -0
  263. data/vendor/lexbor/source/lexbor/html/interfaces/directory_element.c +36 -0
  264. data/vendor/lexbor/source/lexbor/html/interfaces/directory_element.h +34 -0
  265. data/vendor/lexbor/source/lexbor/html/interfaces/div_element.c +36 -0
  266. data/vendor/lexbor/source/lexbor/html/interfaces/div_element.h +34 -0
  267. data/vendor/lexbor/source/lexbor/html/interfaces/document.c +444 -0
  268. data/vendor/lexbor/source/lexbor/html/interfaces/document.h +256 -0
  269. data/vendor/lexbor/source/lexbor/html/interfaces/element.c +64 -0
  270. data/vendor/lexbor/source/lexbor/html/interfaces/element.h +54 -0
  271. data/vendor/lexbor/source/lexbor/html/interfaces/embed_element.c +36 -0
  272. data/vendor/lexbor/source/lexbor/html/interfaces/embed_element.h +34 -0
  273. data/vendor/lexbor/source/lexbor/html/interfaces/field_set_element.c +36 -0
  274. data/vendor/lexbor/source/lexbor/html/interfaces/field_set_element.h +34 -0
  275. data/vendor/lexbor/source/lexbor/html/interfaces/font_element.c +36 -0
  276. data/vendor/lexbor/source/lexbor/html/interfaces/font_element.h +34 -0
  277. data/vendor/lexbor/source/lexbor/html/interfaces/form_element.c +36 -0
  278. data/vendor/lexbor/source/lexbor/html/interfaces/form_element.h +34 -0
  279. data/vendor/lexbor/source/lexbor/html/interfaces/frame_element.c +36 -0
  280. data/vendor/lexbor/source/lexbor/html/interfaces/frame_element.h +34 -0
  281. data/vendor/lexbor/source/lexbor/html/interfaces/frame_set_element.c +36 -0
  282. data/vendor/lexbor/source/lexbor/html/interfaces/frame_set_element.h +34 -0
  283. data/vendor/lexbor/source/lexbor/html/interfaces/head_element.c +36 -0
  284. data/vendor/lexbor/source/lexbor/html/interfaces/head_element.h +34 -0
  285. data/vendor/lexbor/source/lexbor/html/interfaces/heading_element.c +36 -0
  286. data/vendor/lexbor/source/lexbor/html/interfaces/heading_element.h +34 -0
  287. data/vendor/lexbor/source/lexbor/html/interfaces/hr_element.c +36 -0
  288. data/vendor/lexbor/source/lexbor/html/interfaces/hr_element.h +34 -0
  289. data/vendor/lexbor/source/lexbor/html/interfaces/html_element.c +36 -0
  290. data/vendor/lexbor/source/lexbor/html/interfaces/html_element.h +34 -0
  291. data/vendor/lexbor/source/lexbor/html/interfaces/iframe_element.c +36 -0
  292. data/vendor/lexbor/source/lexbor/html/interfaces/iframe_element.h +34 -0
  293. data/vendor/lexbor/source/lexbor/html/interfaces/image_element.c +36 -0
  294. data/vendor/lexbor/source/lexbor/html/interfaces/image_element.h +34 -0
  295. data/vendor/lexbor/source/lexbor/html/interfaces/input_element.c +36 -0
  296. data/vendor/lexbor/source/lexbor/html/interfaces/input_element.h +34 -0
  297. data/vendor/lexbor/source/lexbor/html/interfaces/label_element.c +36 -0
  298. data/vendor/lexbor/source/lexbor/html/interfaces/label_element.h +34 -0
  299. data/vendor/lexbor/source/lexbor/html/interfaces/legend_element.c +36 -0
  300. data/vendor/lexbor/source/lexbor/html/interfaces/legend_element.h +34 -0
  301. data/vendor/lexbor/source/lexbor/html/interfaces/li_element.c +36 -0
  302. data/vendor/lexbor/source/lexbor/html/interfaces/li_element.h +34 -0
  303. data/vendor/lexbor/source/lexbor/html/interfaces/link_element.c +36 -0
  304. data/vendor/lexbor/source/lexbor/html/interfaces/link_element.h +34 -0
  305. data/vendor/lexbor/source/lexbor/html/interfaces/map_element.c +36 -0
  306. data/vendor/lexbor/source/lexbor/html/interfaces/map_element.h +34 -0
  307. data/vendor/lexbor/source/lexbor/html/interfaces/marquee_element.c +36 -0
  308. data/vendor/lexbor/source/lexbor/html/interfaces/marquee_element.h +34 -0
  309. data/vendor/lexbor/source/lexbor/html/interfaces/media_element.c +36 -0
  310. data/vendor/lexbor/source/lexbor/html/interfaces/media_element.h +34 -0
  311. data/vendor/lexbor/source/lexbor/html/interfaces/menu_element.c +36 -0
  312. data/vendor/lexbor/source/lexbor/html/interfaces/menu_element.h +34 -0
  313. data/vendor/lexbor/source/lexbor/html/interfaces/meta_element.c +36 -0
  314. data/vendor/lexbor/source/lexbor/html/interfaces/meta_element.h +34 -0
  315. data/vendor/lexbor/source/lexbor/html/interfaces/meter_element.c +36 -0
  316. data/vendor/lexbor/source/lexbor/html/interfaces/meter_element.h +34 -0
  317. data/vendor/lexbor/source/lexbor/html/interfaces/mod_element.c +36 -0
  318. data/vendor/lexbor/source/lexbor/html/interfaces/mod_element.h +34 -0
  319. data/vendor/lexbor/source/lexbor/html/interfaces/o_list_element.c +36 -0
  320. data/vendor/lexbor/source/lexbor/html/interfaces/o_list_element.h +34 -0
  321. data/vendor/lexbor/source/lexbor/html/interfaces/object_element.c +36 -0
  322. data/vendor/lexbor/source/lexbor/html/interfaces/object_element.h +34 -0
  323. data/vendor/lexbor/source/lexbor/html/interfaces/opt_group_element.c +36 -0
  324. data/vendor/lexbor/source/lexbor/html/interfaces/opt_group_element.h +34 -0
  325. data/vendor/lexbor/source/lexbor/html/interfaces/option_element.c +36 -0
  326. data/vendor/lexbor/source/lexbor/html/interfaces/option_element.h +34 -0
  327. data/vendor/lexbor/source/lexbor/html/interfaces/output_element.c +36 -0
  328. data/vendor/lexbor/source/lexbor/html/interfaces/output_element.h +34 -0
  329. data/vendor/lexbor/source/lexbor/html/interfaces/paragraph_element.c +36 -0
  330. data/vendor/lexbor/source/lexbor/html/interfaces/paragraph_element.h +34 -0
  331. data/vendor/lexbor/source/lexbor/html/interfaces/param_element.c +36 -0
  332. data/vendor/lexbor/source/lexbor/html/interfaces/param_element.h +34 -0
  333. data/vendor/lexbor/source/lexbor/html/interfaces/picture_element.c +36 -0
  334. data/vendor/lexbor/source/lexbor/html/interfaces/picture_element.h +34 -0
  335. data/vendor/lexbor/source/lexbor/html/interfaces/pre_element.c +36 -0
  336. data/vendor/lexbor/source/lexbor/html/interfaces/pre_element.h +34 -0
  337. data/vendor/lexbor/source/lexbor/html/interfaces/progress_element.c +36 -0
  338. data/vendor/lexbor/source/lexbor/html/interfaces/progress_element.h +34 -0
  339. data/vendor/lexbor/source/lexbor/html/interfaces/quote_element.c +36 -0
  340. data/vendor/lexbor/source/lexbor/html/interfaces/quote_element.h +34 -0
  341. data/vendor/lexbor/source/lexbor/html/interfaces/script_element.c +36 -0
  342. data/vendor/lexbor/source/lexbor/html/interfaces/script_element.h +34 -0
  343. data/vendor/lexbor/source/lexbor/html/interfaces/select_element.c +36 -0
  344. data/vendor/lexbor/source/lexbor/html/interfaces/select_element.h +34 -0
  345. data/vendor/lexbor/source/lexbor/html/interfaces/slot_element.c +36 -0
  346. data/vendor/lexbor/source/lexbor/html/interfaces/slot_element.h +34 -0
  347. data/vendor/lexbor/source/lexbor/html/interfaces/source_element.c +36 -0
  348. data/vendor/lexbor/source/lexbor/html/interfaces/source_element.h +34 -0
  349. data/vendor/lexbor/source/lexbor/html/interfaces/span_element.c +36 -0
  350. data/vendor/lexbor/source/lexbor/html/interfaces/span_element.h +34 -0
  351. data/vendor/lexbor/source/lexbor/html/interfaces/style_element.c +36 -0
  352. data/vendor/lexbor/source/lexbor/html/interfaces/style_element.h +34 -0
  353. data/vendor/lexbor/source/lexbor/html/interfaces/table_caption_element.c +36 -0
  354. data/vendor/lexbor/source/lexbor/html/interfaces/table_caption_element.h +34 -0
  355. data/vendor/lexbor/source/lexbor/html/interfaces/table_cell_element.c +36 -0
  356. data/vendor/lexbor/source/lexbor/html/interfaces/table_cell_element.h +34 -0
  357. data/vendor/lexbor/source/lexbor/html/interfaces/table_col_element.c +36 -0
  358. data/vendor/lexbor/source/lexbor/html/interfaces/table_col_element.h +34 -0
  359. data/vendor/lexbor/source/lexbor/html/interfaces/table_element.c +36 -0
  360. data/vendor/lexbor/source/lexbor/html/interfaces/table_element.h +34 -0
  361. data/vendor/lexbor/source/lexbor/html/interfaces/table_row_element.c +36 -0
  362. data/vendor/lexbor/source/lexbor/html/interfaces/table_row_element.h +34 -0
  363. data/vendor/lexbor/source/lexbor/html/interfaces/table_section_element.c +36 -0
  364. data/vendor/lexbor/source/lexbor/html/interfaces/table_section_element.h +34 -0
  365. data/vendor/lexbor/source/lexbor/html/interfaces/template_element.c +46 -0
  366. data/vendor/lexbor/source/lexbor/html/interfaces/template_element.h +38 -0
  367. data/vendor/lexbor/source/lexbor/html/interfaces/text_area_element.c +36 -0
  368. data/vendor/lexbor/source/lexbor/html/interfaces/text_area_element.h +34 -0
  369. data/vendor/lexbor/source/lexbor/html/interfaces/time_element.c +36 -0
  370. data/vendor/lexbor/source/lexbor/html/interfaces/time_element.h +34 -0
  371. data/vendor/lexbor/source/lexbor/html/interfaces/title_element.c +133 -0
  372. data/vendor/lexbor/source/lexbor/html/interfaces/title_element.h +42 -0
  373. data/vendor/lexbor/source/lexbor/html/interfaces/track_element.c +36 -0
  374. data/vendor/lexbor/source/lexbor/html/interfaces/track_element.h +34 -0
  375. data/vendor/lexbor/source/lexbor/html/interfaces/u_list_element.c +36 -0
  376. data/vendor/lexbor/source/lexbor/html/interfaces/u_list_element.h +34 -0
  377. data/vendor/lexbor/source/lexbor/html/interfaces/unknown_element.c +36 -0
  378. data/vendor/lexbor/source/lexbor/html/interfaces/unknown_element.h +34 -0
  379. data/vendor/lexbor/source/lexbor/html/interfaces/video_element.c +36 -0
  380. data/vendor/lexbor/source/lexbor/html/interfaces/video_element.h +34 -0
  381. data/vendor/lexbor/source/lexbor/html/interfaces/window.c +36 -0
  382. data/vendor/lexbor/source/lexbor/html/interfaces/window.h +34 -0
  383. data/vendor/lexbor/source/lexbor/html/node.c +14 -0
  384. data/vendor/lexbor/source/lexbor/html/node.h +67 -0
  385. data/vendor/lexbor/source/lexbor/html/parser.c +469 -0
  386. data/vendor/lexbor/source/lexbor/html/parser.h +170 -0
  387. data/vendor/lexbor/source/lexbor/html/serialize.c +1510 -0
  388. data/vendor/lexbor/source/lexbor/html/serialize.h +93 -0
  389. data/vendor/lexbor/source/lexbor/html/tag.h +103 -0
  390. data/vendor/lexbor/source/lexbor/html/tag_res.h +2262 -0
  391. data/vendor/lexbor/source/lexbor/html/token.c +386 -0
  392. data/vendor/lexbor/source/lexbor/html/token.h +130 -0
  393. data/vendor/lexbor/source/lexbor/html/token_attr.c +44 -0
  394. data/vendor/lexbor/source/lexbor/html/token_attr.h +67 -0
  395. data/vendor/lexbor/source/lexbor/html/tokenizer/error.c +28 -0
  396. data/vendor/lexbor/source/lexbor/html/tokenizer/error.h +141 -0
  397. data/vendor/lexbor/source/lexbor/html/tokenizer/res.h +4956 -0
  398. data/vendor/lexbor/source/lexbor/html/tokenizer/state.c +2171 -0
  399. data/vendor/lexbor/source/lexbor/html/tokenizer/state.h +225 -0
  400. data/vendor/lexbor/source/lexbor/html/tokenizer/state_comment.c +489 -0
  401. data/vendor/lexbor/source/lexbor/html/tokenizer/state_comment.h +27 -0
  402. data/vendor/lexbor/source/lexbor/html/tokenizer/state_doctype.c +1654 -0
  403. data/vendor/lexbor/source/lexbor/html/tokenizer/state_doctype.h +27 -0
  404. data/vendor/lexbor/source/lexbor/html/tokenizer/state_rawtext.c +303 -0
  405. data/vendor/lexbor/source/lexbor/html/tokenizer/state_rawtext.h +32 -0
  406. data/vendor/lexbor/source/lexbor/html/tokenizer/state_rcdata.c +311 -0
  407. data/vendor/lexbor/source/lexbor/html/tokenizer/state_rcdata.h +32 -0
  408. data/vendor/lexbor/source/lexbor/html/tokenizer/state_script.c +1209 -0
  409. data/vendor/lexbor/source/lexbor/html/tokenizer/state_script.h +32 -0
  410. data/vendor/lexbor/source/lexbor/html/tokenizer.c +499 -0
  411. data/vendor/lexbor/source/lexbor/html/tokenizer.h +343 -0
  412. data/vendor/lexbor/source/lexbor/html/tree/active_formatting.c +241 -0
  413. data/vendor/lexbor/source/lexbor/html/tree/active_formatting.h +117 -0
  414. data/vendor/lexbor/source/lexbor/html/tree/error.c +26 -0
  415. data/vendor/lexbor/source/lexbor/html/tree/error.h +114 -0
  416. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_after_body.c +62 -0
  417. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_after_frameset.c +63 -0
  418. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_body.c +82 -0
  419. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_frameset.c +88 -0
  420. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_head.c +222 -0
  421. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/before_head.c +144 -0
  422. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/before_html.c +166 -0
  423. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/foreign_content.c +358 -0
  424. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_body.c +1974 -0
  425. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_caption.c +158 -0
  426. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_cell.c +187 -0
  427. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_column_group.c +194 -0
  428. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_frameset.c +149 -0
  429. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_head.c +374 -0
  430. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_head_noscript.c +121 -0
  431. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_row.c +211 -0
  432. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_select.c +341 -0
  433. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_select_in_table.c +115 -0
  434. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_table.c +451 -0
  435. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_table_body.c +208 -0
  436. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_table_text.c +127 -0
  437. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_template.c +189 -0
  438. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/initial.c +411 -0
  439. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/text.c +61 -0
  440. data/vendor/lexbor/source/lexbor/html/tree/insertion_mode.h +135 -0
  441. data/vendor/lexbor/source/lexbor/html/tree/open_elements.c +251 -0
  442. data/vendor/lexbor/source/lexbor/html/tree/open_elements.h +105 -0
  443. data/vendor/lexbor/source/lexbor/html/tree/template_insertion.c +10 -0
  444. data/vendor/lexbor/source/lexbor/html/tree/template_insertion.h +100 -0
  445. data/vendor/lexbor/source/lexbor/html/tree.c +1726 -0
  446. data/vendor/lexbor/source/lexbor/html/tree.h +431 -0
  447. data/vendor/lexbor/source/lexbor/html/tree_res.h +111 -0
  448. data/vendor/lexbor/source/lexbor/ns/base.h +32 -0
  449. data/vendor/lexbor/source/lexbor/ns/config.cmake +2 -0
  450. data/vendor/lexbor/source/lexbor/ns/const.h +37 -0
  451. data/vendor/lexbor/source/lexbor/ns/ns.c +154 -0
  452. data/vendor/lexbor/source/lexbor/ns/ns.h +66 -0
  453. data/vendor/lexbor/source/lexbor/ns/res.h +97 -0
  454. data/vendor/lexbor/source/lexbor/ports/posix/config.cmake +11 -0
  455. data/vendor/lexbor/source/lexbor/ports/posix/lexbor/core/fs.c +236 -0
  456. data/vendor/lexbor/source/lexbor/ports/posix/lexbor/core/memory.c +33 -0
  457. data/vendor/lexbor/source/lexbor/ports/posix/lexbor/core/perf.c +158 -0
  458. data/vendor/lexbor/source/lexbor/ports/windows_nt/config.cmake +18 -0
  459. data/vendor/lexbor/source/lexbor/ports/windows_nt/lexbor/core/fs.c +239 -0
  460. data/vendor/lexbor/source/lexbor/ports/windows_nt/lexbor/core/memory.c +33 -0
  461. data/vendor/lexbor/source/lexbor/ports/windows_nt/lexbor/core/perf.c +81 -0
  462. data/vendor/lexbor/source/lexbor/selectors/base.h +30 -0
  463. data/vendor/lexbor/source/lexbor/selectors/config.cmake +2 -0
  464. data/vendor/lexbor/source/lexbor/selectors/selectors.c +1591 -0
  465. data/vendor/lexbor/source/lexbor/selectors/selectors.h +71 -0
  466. data/vendor/lexbor/source/lexbor/tag/base.h +32 -0
  467. data/vendor/lexbor/source/lexbor/tag/config.cmake +2 -0
  468. data/vendor/lexbor/source/lexbor/tag/const.h +225 -0
  469. data/vendor/lexbor/source/lexbor/tag/res.h +562 -0
  470. data/vendor/lexbor/source/lexbor/tag/tag.c +144 -0
  471. data/vendor/lexbor/source/lexbor/tag/tag.h +123 -0
  472. data/vendor/lexbor/source/lexbor/utils/base.h +32 -0
  473. data/vendor/lexbor/source/lexbor/utils/config.cmake +2 -0
  474. data/vendor/lexbor/source/lexbor/utils/http.c +534 -0
  475. data/vendor/lexbor/source/lexbor/utils/http.h +90 -0
  476. data/vendor/lexbor/source/lexbor/utils/utils.h +15 -0
  477. data/vendor/lexbor/source/lexbor/utils/warc.c +817 -0
  478. data/vendor/lexbor/source/lexbor/utils/warc.h +126 -0
  479. data/vendor/lexbor/utils/lexbor/css/selectors/pseudo.py +231 -0
  480. data/vendor/lexbor/utils/lexbor/css/selectors/tmp/const.h +21 -0
  481. data/vendor/lexbor/utils/lexbor/css/selectors/tmp/res.h +26 -0
  482. data/vendor/lexbor/utils/lexbor/css/syntax/definitions.py +49 -0
  483. data/vendor/lexbor/utils/lexbor/css/syntax/token_res.py +54 -0
  484. data/vendor/lexbor/utils/lexbor/css/syntax/tokenizer_code_map.py +36 -0
  485. data/vendor/lexbor/version +1 -0
  486. metadata +542 -0
@@ -0,0 +1,1726 @@
1
+ /*
2
+ * Copyright (C) 2018-2020 Alexander Borisov
3
+ *
4
+ * Author: Alexander Borisov <borisov@lexbor.com>
5
+ */
6
+
7
+ #include "lexbor/dom/interfaces/document_fragment.h"
8
+ #include "lexbor/dom/interfaces/document_type.h"
9
+ #include "lexbor/dom/interfaces/comment.h"
10
+ #include "lexbor/dom/interfaces/text.h"
11
+
12
+ #include "lexbor/html/tree.h"
13
+ #include "lexbor/html/tree_res.h"
14
+ #include "lexbor/html/tree/insertion_mode.h"
15
+ #include "lexbor/html/tree/open_elements.h"
16
+ #include "lexbor/html/tree/active_formatting.h"
17
+ #include "lexbor/html/tree/template_insertion.h"
18
+ #include "lexbor/html/interface.h"
19
+ #include "lexbor/html/interface.h"
20
+ #include "lexbor/html/interfaces/template_element.h"
21
+ #include "lexbor/html/interfaces/unknown_element.h"
22
+ #include "lexbor/html/tokenizer/state_rawtext.h"
23
+ #include "lexbor/html/tokenizer/state_rcdata.h"
24
+
25
+
26
+ lxb_dom_attr_data_t *
27
+ lxb_dom_attr_local_name_append(lexbor_hash_t *hash,
28
+ const lxb_char_t *name, size_t length);
29
+
30
+ lxb_dom_attr_data_t *
31
+ lxb_dom_attr_qualified_name_append(lexbor_hash_t *hash, const lxb_char_t *name,
32
+ size_t length);
33
+
34
+ const lxb_tag_data_t *
35
+ lxb_tag_append_lower(lexbor_hash_t *hash,
36
+ const lxb_char_t *name, size_t length);
37
+
38
+ static lxb_html_token_t *
39
+ lxb_html_tree_token_callback(lxb_html_tokenizer_t *tkz,
40
+ lxb_html_token_t *token, void *ctx);
41
+
42
+ static lxb_status_t
43
+ lxb_html_tree_insertion_mode(lxb_html_tree_t *tree, lxb_html_token_t *token);
44
+
45
+
46
+ lxb_html_tree_t *
47
+ lxb_html_tree_create(void)
48
+ {
49
+ return lexbor_calloc(1, sizeof(lxb_html_tree_t));
50
+ }
51
+
52
+ lxb_status_t
53
+ lxb_html_tree_init(lxb_html_tree_t *tree, lxb_html_tokenizer_t *tkz)
54
+ {
55
+ if (tree == NULL) {
56
+ return LXB_STATUS_ERROR_OBJECT_IS_NULL;
57
+ }
58
+
59
+ if (tkz == NULL) {
60
+ return LXB_STATUS_ERROR_WRONG_ARGS;
61
+ }
62
+
63
+ lxb_status_t status;
64
+
65
+ /* Stack of open elements */
66
+ tree->open_elements = lexbor_array_create();
67
+ status = lexbor_array_init(tree->open_elements, 128);
68
+ if (status != LXB_STATUS_OK) {
69
+ return status;
70
+ }
71
+
72
+ /* Stack of active formatting */
73
+ tree->active_formatting = lexbor_array_create();
74
+ status = lexbor_array_init(tree->active_formatting, 128);
75
+ if (status != LXB_STATUS_OK) {
76
+ return status;
77
+ }
78
+
79
+ /* Stack of template insertion modes */
80
+ tree->template_insertion_modes = lexbor_array_obj_create();
81
+ status = lexbor_array_obj_init(tree->template_insertion_modes, 64,
82
+ sizeof(lxb_html_tree_template_insertion_t));
83
+ if (status != LXB_STATUS_OK) {
84
+ return status;
85
+ }
86
+
87
+ /* Stack of pending table character tokens */
88
+ tree->pending_table.text_list = lexbor_array_obj_create();
89
+ status = lexbor_array_obj_init(tree->pending_table.text_list, 16,
90
+ sizeof(lexbor_str_t));
91
+ if (status != LXB_STATUS_OK) {
92
+ return status;
93
+ }
94
+
95
+ /* Parse errors */
96
+ tree->parse_errors = lexbor_array_obj_create();
97
+ status = lexbor_array_obj_init(tree->parse_errors, 16,
98
+ sizeof(lxb_html_tree_error_t));
99
+ if (status != LXB_STATUS_OK) {
100
+ return status;
101
+ }
102
+
103
+ tree->tkz_ref = lxb_html_tokenizer_ref(tkz);
104
+
105
+ tree->document = NULL;
106
+ tree->fragment = NULL;
107
+
108
+ tree->form = NULL;
109
+
110
+ tree->foster_parenting = false;
111
+ tree->frameset_ok = true;
112
+
113
+ tree->mode = lxb_html_tree_insertion_mode_initial;
114
+ tree->before_append_attr = NULL;
115
+
116
+ tree->status = LXB_STATUS_OK;
117
+
118
+ tree->ref_count = 1;
119
+
120
+ lxb_html_tokenizer_callback_token_done_set(tkz,
121
+ lxb_html_tree_token_callback,
122
+ tree);
123
+
124
+ return LXB_STATUS_OK;
125
+ }
126
+
127
+ lxb_html_tree_t *
128
+ lxb_html_tree_ref(lxb_html_tree_t *tree)
129
+ {
130
+ if (tree == NULL) {
131
+ return NULL;
132
+ }
133
+
134
+ tree->ref_count++;
135
+
136
+ return tree;
137
+ }
138
+
139
+ lxb_html_tree_t *
140
+ lxb_html_tree_unref(lxb_html_tree_t *tree)
141
+ {
142
+ if (tree == NULL || tree->ref_count == 0) {
143
+ return NULL;
144
+ }
145
+
146
+ tree->ref_count--;
147
+
148
+ if (tree->ref_count == 0) {
149
+ lxb_html_tree_destroy(tree);
150
+ }
151
+
152
+ return NULL;
153
+ }
154
+
155
+ void
156
+ lxb_html_tree_clean(lxb_html_tree_t *tree)
157
+ {
158
+ lexbor_array_clean(tree->open_elements);
159
+ lexbor_array_clean(tree->active_formatting);
160
+ lexbor_array_obj_clean(tree->template_insertion_modes);
161
+ lexbor_array_obj_clean(tree->pending_table.text_list);
162
+ lexbor_array_obj_clean(tree->parse_errors);
163
+
164
+ tree->document = NULL;
165
+ tree->fragment = NULL;
166
+
167
+ tree->form = NULL;
168
+
169
+ tree->foster_parenting = false;
170
+ tree->frameset_ok = true;
171
+
172
+ tree->mode = lxb_html_tree_insertion_mode_initial;
173
+ tree->before_append_attr = NULL;
174
+
175
+ tree->status = LXB_STATUS_OK;
176
+ }
177
+
178
+ lxb_html_tree_t *
179
+ lxb_html_tree_destroy(lxb_html_tree_t *tree)
180
+ {
181
+ if (tree == NULL) {
182
+ return NULL;
183
+ }
184
+
185
+ tree->open_elements = lexbor_array_destroy(tree->open_elements, true);
186
+ tree->active_formatting = lexbor_array_destroy(tree->active_formatting,
187
+ true);
188
+ tree->template_insertion_modes = lexbor_array_obj_destroy(tree->template_insertion_modes,
189
+ true);
190
+ tree->pending_table.text_list = lexbor_array_obj_destroy(tree->pending_table.text_list,
191
+ true);
192
+
193
+ tree->parse_errors = lexbor_array_obj_destroy(tree->parse_errors, true);
194
+ tree->tkz_ref = lxb_html_tokenizer_unref(tree->tkz_ref);
195
+
196
+ return lexbor_free(tree);
197
+ }
198
+
199
+ static lxb_html_token_t *
200
+ lxb_html_tree_token_callback(lxb_html_tokenizer_t *tkz,
201
+ lxb_html_token_t *token, void *ctx)
202
+ {
203
+ lxb_status_t status;
204
+
205
+ status = lxb_html_tree_insertion_mode(ctx, token);
206
+ if (status != LXB_STATUS_OK) {
207
+ tkz->status = status;
208
+ return NULL;
209
+ }
210
+
211
+ return token;
212
+ }
213
+
214
+ /* TODO: not complete!!! */
215
+ lxb_status_t
216
+ lxb_html_tree_stop_parsing(lxb_html_tree_t *tree)
217
+ {
218
+ tree->document->ready_state = LXB_HTML_DOCUMENT_READY_STATE_COMPLETE;
219
+
220
+ return LXB_STATUS_OK;
221
+ }
222
+
223
+ bool
224
+ lxb_html_tree_process_abort(lxb_html_tree_t *tree)
225
+ {
226
+ if (tree->status == LXB_STATUS_OK) {
227
+ tree->status = LXB_STATUS_ABORTED;
228
+ }
229
+
230
+ tree->open_elements->length = 0;
231
+ tree->document->ready_state = LXB_HTML_DOCUMENT_READY_STATE_COMPLETE;
232
+
233
+ return true;
234
+ }
235
+
236
+ void
237
+ lxb_html_tree_parse_error(lxb_html_tree_t *tree, lxb_html_token_t *token,
238
+ lxb_html_tree_error_id_t id)
239
+ {
240
+ lxb_html_tree_error_add(tree->parse_errors, token, id);
241
+ }
242
+
243
+ bool
244
+ lxb_html_tree_construction_dispatcher(lxb_html_tree_t *tree,
245
+ lxb_html_token_t *token)
246
+ {
247
+ lxb_dom_node_t *adjusted;
248
+
249
+ adjusted = lxb_html_tree_adjusted_current_node(tree);
250
+
251
+ if (adjusted == NULL || adjusted->ns == LXB_NS_HTML) {
252
+ return tree->mode(tree, token);
253
+ }
254
+
255
+ if (lxb_html_tree_mathml_text_integration_point(adjusted))
256
+ {
257
+ if ((token->type & LXB_HTML_TOKEN_TYPE_CLOSE) == 0
258
+ && token->tag_id != LXB_TAG_MGLYPH
259
+ && token->tag_id != LXB_TAG_MALIGNMARK)
260
+ {
261
+ return tree->mode(tree, token);
262
+ }
263
+
264
+ if (token->tag_id == LXB_TAG__TEXT) {
265
+ return tree->mode(tree, token);
266
+ }
267
+ }
268
+
269
+ if (adjusted->local_name == LXB_TAG_ANNOTATION_XML
270
+ && adjusted->ns == LXB_NS_MATH
271
+ && (token->type & LXB_HTML_TOKEN_TYPE_CLOSE) == 0
272
+ && token->tag_id == LXB_TAG_SVG)
273
+ {
274
+ return tree->mode(tree, token);
275
+ }
276
+
277
+ if (lxb_html_tree_html_integration_point(adjusted)) {
278
+ if ((token->type & LXB_HTML_TOKEN_TYPE_CLOSE) == 0
279
+ || token->tag_id == LXB_TAG__TEXT)
280
+ {
281
+ return tree->mode(tree, token);
282
+ }
283
+ }
284
+
285
+ if (token->tag_id == LXB_TAG__END_OF_FILE) {
286
+ return tree->mode(tree, token);
287
+ }
288
+
289
+ return lxb_html_tree_insertion_mode_foreign_content(tree, token);
290
+ }
291
+
292
+ static lxb_status_t
293
+ lxb_html_tree_insertion_mode(lxb_html_tree_t *tree, lxb_html_token_t *token)
294
+ {
295
+ while (lxb_html_tree_construction_dispatcher(tree, token) == false) {}
296
+
297
+ return tree->status;
298
+ }
299
+
300
+ /*
301
+ * Action
302
+ */
303
+ lxb_dom_node_t *
304
+ lxb_html_tree_appropriate_place_inserting_node(lxb_html_tree_t *tree,
305
+ lxb_dom_node_t *override_target,
306
+ lxb_html_tree_insertion_position_t *ipos)
307
+ {
308
+ lxb_dom_node_t *target, *adjusted_location = NULL;
309
+
310
+ *ipos = LXB_HTML_TREE_INSERTION_POSITION_CHILD;
311
+
312
+ if (override_target != NULL) {
313
+ target = override_target;
314
+ }
315
+ else {
316
+ target = lxb_html_tree_current_node(tree);
317
+ }
318
+
319
+ if (tree->foster_parenting && target->ns == LXB_NS_HTML
320
+ && (target->local_name == LXB_TAG_TABLE
321
+ || target->local_name == LXB_TAG_TBODY
322
+ || target->local_name == LXB_TAG_TFOOT
323
+ || target->local_name == LXB_TAG_THEAD
324
+ || target->local_name == LXB_TAG_TR))
325
+ {
326
+ lxb_dom_node_t *last_temp, *last_table;
327
+ size_t last_temp_idx, last_table_idx;
328
+
329
+ last_temp = lxb_html_tree_open_elements_find_reverse(tree,
330
+ LXB_TAG_TEMPLATE,
331
+ LXB_NS_HTML,
332
+ &last_temp_idx);
333
+
334
+ last_table = lxb_html_tree_open_elements_find_reverse(tree,
335
+ LXB_TAG_TABLE,
336
+ LXB_NS_HTML,
337
+ &last_table_idx);
338
+
339
+ if(last_temp != NULL && (last_table == NULL
340
+ || last_temp_idx > last_table_idx))
341
+ {
342
+ lxb_dom_document_fragment_t *doc_fragment;
343
+
344
+ doc_fragment = lxb_html_interface_template(last_temp)->content;
345
+
346
+ return lxb_dom_interface_node(doc_fragment);
347
+ }
348
+ else if (last_table == NULL) {
349
+ adjusted_location = lxb_html_tree_open_elements_first(tree);
350
+
351
+ lexbor_assert(adjusted_location != NULL);
352
+ lexbor_assert(adjusted_location->local_name == LXB_TAG_HTML);
353
+ }
354
+ else if (last_table->parent != NULL) {
355
+ adjusted_location = last_table;
356
+
357
+ *ipos = LXB_HTML_TREE_INSERTION_POSITION_BEFORE;
358
+ }
359
+ else {
360
+ lexbor_assert(last_table_idx != 0);
361
+
362
+ adjusted_location = lxb_html_tree_open_elements_get(tree,
363
+ last_table_idx - 1);
364
+ }
365
+ }
366
+ else {
367
+ adjusted_location = target;
368
+ }
369
+
370
+ if (adjusted_location == NULL) {
371
+ return NULL;
372
+ }
373
+
374
+ /*
375
+ * In Spec it is not entirely clear what is meant:
376
+ *
377
+ * If the adjusted insertion location is inside a template element,
378
+ * let it instead be inside the template element's template contents,
379
+ * after its last child (if any).
380
+ */
381
+ if (lxb_html_tree_node_is(adjusted_location, LXB_TAG_TEMPLATE)) {
382
+ lxb_dom_document_fragment_t *df;
383
+
384
+ df = lxb_html_interface_template(adjusted_location)->content;
385
+ adjusted_location = lxb_dom_interface_node(df);
386
+ }
387
+
388
+ return adjusted_location;
389
+ }
390
+
391
+ lxb_html_element_t *
392
+ lxb_html_tree_insert_foreign_element(lxb_html_tree_t *tree,
393
+ lxb_html_token_t *token, lxb_ns_id_t ns)
394
+ {
395
+ lxb_status_t status;
396
+ lxb_dom_node_t *pos;
397
+ lxb_html_element_t *element;
398
+ lxb_html_tree_insertion_position_t ipos;
399
+
400
+ pos = lxb_html_tree_appropriate_place_inserting_node(tree, NULL, &ipos);
401
+
402
+ if (ipos == LXB_HTML_TREE_INSERTION_POSITION_CHILD) {
403
+ element = lxb_html_tree_create_element_for_token(tree, token, ns, pos);
404
+ }
405
+ else {
406
+ element = lxb_html_tree_create_element_for_token(tree, token, ns,
407
+ pos->parent);
408
+ }
409
+
410
+ if (element == NULL) {
411
+ return NULL;
412
+ }
413
+
414
+ if (pos != NULL) {
415
+ lxb_html_tree_insert_node(pos, lxb_dom_interface_node(element), ipos);
416
+ }
417
+
418
+ status = lxb_html_tree_open_elements_push(tree,
419
+ lxb_dom_interface_node(element));
420
+ if (status != LXB_HTML_STATUS_OK) {
421
+ return lxb_html_interface_destroy(element);
422
+ }
423
+
424
+ return element;
425
+ }
426
+
427
+ lxb_html_element_t *
428
+ lxb_html_tree_create_element_for_token(lxb_html_tree_t *tree,
429
+ lxb_html_token_t *token, lxb_ns_id_t ns,
430
+ lxb_dom_node_t *parent)
431
+ {
432
+ lxb_dom_node_t *node = lxb_html_tree_create_node(tree, token->tag_id, ns);
433
+ if (node == NULL) {
434
+ return NULL;
435
+ }
436
+
437
+ lxb_status_t status;
438
+ lxb_dom_element_t *element = lxb_dom_interface_element(node);
439
+
440
+ if (token->base_element == NULL) {
441
+ status = lxb_html_tree_append_attributes(tree, element, token, ns);
442
+ }
443
+ else {
444
+ status = lxb_html_tree_append_attributes_from_element(tree, element,
445
+ token->base_element, ns);
446
+ }
447
+
448
+ if (status != LXB_HTML_STATUS_OK) {
449
+ return lxb_html_interface_destroy(element);
450
+ }
451
+
452
+ return lxb_html_interface_element(node);
453
+ }
454
+
455
+ lxb_status_t
456
+ lxb_html_tree_append_attributes(lxb_html_tree_t *tree,
457
+ lxb_dom_element_t *element,
458
+ lxb_html_token_t *token, lxb_ns_id_t ns)
459
+ {
460
+ lxb_status_t status;
461
+ lxb_dom_attr_t *attr;
462
+ lxb_html_token_attr_t *token_attr = token->attr_first;
463
+
464
+ while (token_attr != NULL) {
465
+ attr = lxb_dom_element_attr_by_local_name_data(element,
466
+ token_attr->name);
467
+ if (attr != NULL) {
468
+ token_attr = token_attr->next;
469
+ continue;
470
+ }
471
+
472
+ attr = lxb_dom_attr_interface_create(element->node.owner_document);
473
+ if (attr == NULL) {
474
+ return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
475
+ }
476
+
477
+ if (token_attr->value_begin != NULL) {
478
+ status = lxb_dom_attr_set_value_wo_copy(attr, token_attr->value,
479
+ token_attr->value_size);
480
+ if (status != LXB_HTML_STATUS_OK) {
481
+ return status;
482
+ }
483
+ }
484
+
485
+ attr->node.local_name = token_attr->name->attr_id;
486
+ attr->node.ns = ns;
487
+
488
+ /* Fix for adjust MathML/SVG attributes */
489
+ if (tree->before_append_attr != NULL) {
490
+ status = tree->before_append_attr(tree, attr, NULL);
491
+ if (status != LXB_STATUS_OK) {
492
+ return status;
493
+ }
494
+ }
495
+
496
+ lxb_dom_element_attr_append(element, attr);
497
+
498
+ token_attr = token_attr->next;
499
+ }
500
+
501
+ return LXB_HTML_STATUS_OK;
502
+ }
503
+
504
+ lxb_status_t
505
+ lxb_html_tree_append_attributes_from_element(lxb_html_tree_t *tree,
506
+ lxb_dom_element_t *element,
507
+ lxb_dom_element_t *from,
508
+ lxb_ns_id_t ns)
509
+ {
510
+ lxb_status_t status;
511
+ lxb_dom_attr_t *attr = from->first_attr;
512
+ lxb_dom_attr_t *new_attr;
513
+
514
+ while (attr != NULL) {
515
+ new_attr = lxb_dom_attr_interface_create(element->node.owner_document);
516
+ if (new_attr == NULL) {
517
+ return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
518
+ }
519
+
520
+ status = lxb_dom_attr_clone_name_value(attr, new_attr);
521
+ if (status != LXB_HTML_STATUS_OK) {
522
+ return status;
523
+ }
524
+
525
+ new_attr->node.ns = attr->node.ns;
526
+
527
+ /* Fix for adjust MathML/SVG attributes */
528
+ if (tree->before_append_attr != NULL) {
529
+ status = tree->before_append_attr(tree, new_attr, NULL);
530
+ if (status != LXB_STATUS_OK) {
531
+ return status;
532
+ }
533
+ }
534
+
535
+ lxb_dom_element_attr_append(element, attr);
536
+
537
+ attr = attr->next;
538
+ }
539
+
540
+ return LXB_HTML_STATUS_OK;
541
+ }
542
+
543
+ lxb_status_t
544
+ lxb_html_tree_adjust_mathml_attributes(lxb_html_tree_t *tree,
545
+ lxb_dom_attr_t *attr, void *ctx)
546
+ {
547
+ lexbor_hash_t *attrs;
548
+ const lxb_dom_attr_data_t *data;
549
+
550
+ attrs = attr->node.owner_document->attrs;
551
+ data = lxb_dom_attr_data_by_id(attrs, attr->node.local_name);
552
+
553
+ if (data->entry.length == 13
554
+ && lexbor_str_data_cmp(lexbor_hash_entry_str(&data->entry),
555
+ (const lxb_char_t *) "definitionurl"))
556
+ {
557
+ data = lxb_dom_attr_qualified_name_append(attrs,
558
+ (const lxb_char_t *) "definitionURL", 13);
559
+ if (data == NULL) {
560
+ return LXB_STATUS_ERROR;
561
+ }
562
+
563
+ attr->qualified_name = data->attr_id;
564
+ }
565
+
566
+ return LXB_STATUS_OK;
567
+ }
568
+
569
+ lxb_status_t
570
+ lxb_html_tree_adjust_svg_attributes(lxb_html_tree_t *tree,
571
+ lxb_dom_attr_t *attr, void *ctx)
572
+ {
573
+ lexbor_hash_t *attrs;
574
+ const lxb_dom_attr_data_t *data;
575
+ const lxb_html_tree_res_attr_adjust_t *adjust;
576
+
577
+ size_t len = sizeof(lxb_html_tree_res_attr_adjust_svg_map)
578
+ / sizeof(lxb_html_tree_res_attr_adjust_t);
579
+
580
+ attrs = attr->node.owner_document->attrs;
581
+
582
+ data = lxb_dom_attr_data_by_id(attrs, attr->node.local_name);
583
+
584
+ for (size_t i = 0; i < len; i++) {
585
+ adjust = &lxb_html_tree_res_attr_adjust_svg_map[i];
586
+
587
+ if (data->entry.length == adjust->len
588
+ && lexbor_str_data_cmp(lexbor_hash_entry_str(&data->entry),
589
+ (const lxb_char_t *) adjust->from))
590
+ {
591
+ data = lxb_dom_attr_qualified_name_append(attrs,
592
+ (const lxb_char_t *) adjust->to, adjust->len);
593
+ if (data == NULL) {
594
+ return LXB_STATUS_ERROR;
595
+ }
596
+
597
+ attr->qualified_name = data->attr_id;
598
+
599
+ return LXB_STATUS_OK;
600
+ }
601
+ }
602
+
603
+ return LXB_STATUS_OK;
604
+ }
605
+
606
+ lxb_status_t
607
+ lxb_html_tree_adjust_foreign_attributes(lxb_html_tree_t *tree,
608
+ lxb_dom_attr_t *attr, void *ctx)
609
+ {
610
+ size_t lname_length;
611
+ lexbor_hash_t *attrs, *prefix;
612
+ const lxb_dom_attr_data_t *attr_data;
613
+ const lxb_ns_prefix_data_t *prefix_data;
614
+ const lxb_dom_attr_data_t *data;
615
+ const lxb_html_tree_res_attr_adjust_foreign_t *adjust;
616
+
617
+ size_t len = sizeof(lxb_html_tree_res_attr_adjust_foreign_map)
618
+ / sizeof(lxb_html_tree_res_attr_adjust_foreign_t);
619
+
620
+ attrs = attr->node.owner_document->attrs;
621
+ prefix = attr->node.owner_document->prefix;
622
+
623
+ data = lxb_dom_attr_data_by_id(attrs, attr->node.local_name);
624
+
625
+ for (size_t i = 0; i < len; i++) {
626
+ adjust = &lxb_html_tree_res_attr_adjust_foreign_map[i];
627
+
628
+ if (data->entry.length == adjust->name_len
629
+ && lexbor_str_data_cmp(lexbor_hash_entry_str(&data->entry),
630
+ (const lxb_char_t *) adjust->name))
631
+ {
632
+ if (adjust->prefix_len != 0) {
633
+ data = lxb_dom_attr_qualified_name_append(attrs,
634
+ (const lxb_char_t *) adjust->name, adjust->name_len);
635
+ if (data == NULL) {
636
+ return LXB_STATUS_ERROR;
637
+ }
638
+
639
+ attr->qualified_name = data->attr_id;
640
+
641
+ lname_length = adjust->name_len - adjust->prefix_len - 1;
642
+
643
+ attr_data = lxb_dom_attr_local_name_append(attrs,
644
+ (const lxb_char_t *) adjust->local_name, lname_length);
645
+ if (attr_data == NULL) {
646
+ return LXB_STATUS_ERROR;
647
+ }
648
+
649
+ attr->node.local_name = attr_data->attr_id;
650
+
651
+ prefix_data = lxb_ns_prefix_append(prefix,
652
+ (const lxb_char_t *) adjust->prefix, adjust->prefix_len);
653
+ if (prefix_data == NULL) {
654
+ return LXB_STATUS_ERROR;
655
+ }
656
+
657
+ attr->node.prefix = prefix_data->prefix_id;
658
+ }
659
+
660
+ attr->node.ns = adjust->ns;
661
+
662
+ return LXB_STATUS_OK;
663
+ }
664
+ }
665
+
666
+ return LXB_STATUS_OK;
667
+ }
668
+
669
+ lxb_status_t
670
+ lxb_html_tree_insert_character(lxb_html_tree_t *tree, lxb_html_token_t *token,
671
+ lxb_dom_node_t **ret_node)
672
+ {
673
+ size_t size;
674
+ lxb_status_t status;
675
+ lexbor_str_t str = {0};
676
+
677
+ size = token->text_end - token->text_start;
678
+
679
+ lexbor_str_init(&str, tree->document->dom_document.text, size + 1);
680
+ if (str.data == NULL) {
681
+ return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
682
+ }
683
+
684
+ memcpy(str.data, token->text_start, size);
685
+
686
+ str.data[size] = 0x00;
687
+ str.length = size;
688
+
689
+ status = lxb_html_tree_insert_character_for_data(tree, &str, ret_node);
690
+ if (status != LXB_STATUS_OK) {
691
+ return status;
692
+ }
693
+
694
+ return LXB_STATUS_OK;
695
+ }
696
+
697
+ lxb_status_t
698
+ lxb_html_tree_insert_character_for_data(lxb_html_tree_t *tree,
699
+ lexbor_str_t *str,
700
+ lxb_dom_node_t **ret_node)
701
+ {
702
+ const lxb_char_t *data;
703
+ lxb_dom_node_t *pos;
704
+ lxb_dom_character_data_t *chrs = NULL;
705
+ lxb_html_tree_insertion_position_t ipos;
706
+
707
+ if (ret_node != NULL) {
708
+ *ret_node = NULL;
709
+ }
710
+
711
+ pos = lxb_html_tree_appropriate_place_inserting_node(tree, NULL, &ipos);
712
+ if (pos == NULL) {
713
+ return LXB_STATUS_ERROR;
714
+ }
715
+
716
+ if (lxb_html_tree_node_is(pos, LXB_TAG__DOCUMENT)) {
717
+ goto destroy_str;
718
+ }
719
+
720
+ if (ipos == LXB_HTML_TREE_INSERTION_POSITION_BEFORE) {
721
+ /* No need check namespace */
722
+ if (pos->prev != NULL && pos->prev->local_name == LXB_TAG__TEXT) {
723
+ chrs = lxb_dom_interface_character_data(pos->prev);
724
+
725
+ if (ret_node != NULL) {
726
+ *ret_node = pos->prev;
727
+ }
728
+ }
729
+ }
730
+ else {
731
+ /* No need check namespace */
732
+ if (pos->last_child != NULL
733
+ && pos->last_child->local_name == LXB_TAG__TEXT)
734
+ {
735
+ chrs = lxb_dom_interface_character_data(pos->last_child);
736
+
737
+ if (ret_node != NULL) {
738
+ *ret_node = pos->last_child;
739
+ }
740
+ }
741
+ }
742
+
743
+ if (chrs != NULL) {
744
+ /* This is error. This can not happen, but... */
745
+ if (chrs->data.data == NULL) {
746
+ data = lexbor_str_init(&chrs->data, tree->document->dom_document.text,
747
+ str->length);
748
+ if (data == NULL) {
749
+ return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
750
+ }
751
+ }
752
+
753
+ data = lexbor_str_append(&chrs->data, tree->document->dom_document.text,
754
+ str->data, str->length);
755
+ if (data == NULL) {
756
+ return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
757
+ }
758
+
759
+ goto destroy_str;
760
+ }
761
+
762
+ lxb_dom_node_t *text = lxb_html_tree_create_node(tree, LXB_TAG__TEXT,
763
+ LXB_NS_HTML);
764
+ if (text == NULL) {
765
+ return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
766
+ }
767
+
768
+ lxb_dom_interface_text(text)->char_data.data = *str;
769
+
770
+ if (ret_node != NULL) {
771
+ *ret_node = text;
772
+ }
773
+
774
+ lxb_html_tree_insert_node(pos, text, ipos);
775
+
776
+ return LXB_STATUS_OK;
777
+
778
+ destroy_str:
779
+
780
+ lexbor_str_destroy(str, tree->document->dom_document.text, false);
781
+
782
+ return LXB_STATUS_OK;
783
+ }
784
+
785
+ lxb_dom_comment_t *
786
+ lxb_html_tree_insert_comment(lxb_html_tree_t *tree,
787
+ lxb_html_token_t *token, lxb_dom_node_t *pos)
788
+ {
789
+ lxb_dom_node_t *node;
790
+ lxb_dom_comment_t *comment;
791
+ lxb_html_tree_insertion_position_t ipos;
792
+
793
+ if (pos == NULL) {
794
+ pos = lxb_html_tree_appropriate_place_inserting_node(tree, NULL, &ipos);
795
+ }
796
+ else {
797
+ ipos = LXB_HTML_TREE_INSERTION_POSITION_CHILD;
798
+ }
799
+
800
+ lexbor_assert(pos != NULL);
801
+
802
+ node = lxb_html_tree_create_node(tree, token->tag_id, pos->ns);
803
+ comment = lxb_dom_interface_comment(node);
804
+
805
+ if (comment == NULL) {
806
+ return NULL;
807
+ }
808
+
809
+ tree->status = lxb_html_token_make_text(token, &comment->char_data.data,
810
+ tree->document->dom_document.text);
811
+ if (tree->status != LXB_STATUS_OK) {
812
+ return NULL;
813
+ }
814
+
815
+ lxb_html_tree_insert_node(pos, node, ipos);
816
+
817
+ return comment;
818
+ }
819
+
820
+ lxb_dom_document_type_t *
821
+ lxb_html_tree_create_document_type_from_token(lxb_html_tree_t *tree,
822
+ lxb_html_token_t *token)
823
+ {
824
+ lxb_status_t status;
825
+ lxb_dom_node_t *doctype_node;
826
+ lxb_dom_document_type_t *doc_type;
827
+
828
+ /* Create */
829
+ doctype_node = lxb_html_tree_create_node(tree, token->tag_id, LXB_NS_HTML);
830
+ if (doctype_node == NULL) {
831
+ return NULL;
832
+ }
833
+
834
+ doc_type = lxb_dom_interface_document_type(doctype_node);
835
+
836
+ /* Parse */
837
+ status = lxb_html_token_doctype_parse(token, doc_type);
838
+ if (status != LXB_STATUS_OK) {
839
+ return lxb_dom_document_type_interface_destroy(doc_type);
840
+ }
841
+
842
+ return doc_type;
843
+ }
844
+
845
+ /*
846
+ * TODO: need use ref and unref for nodes (ref counter)
847
+ * Not implemented until the end. It is necessary to finish it.
848
+ */
849
+ void
850
+ lxb_html_tree_node_delete_deep(lxb_html_tree_t *tree, lxb_dom_node_t *node)
851
+ {
852
+ lxb_dom_node_remove(node);
853
+ }
854
+
855
+ lxb_html_element_t *
856
+ lxb_html_tree_generic_rawtext_parsing(lxb_html_tree_t *tree,
857
+ lxb_html_token_t *token)
858
+ {
859
+ lxb_html_element_t *element;
860
+
861
+ element = lxb_html_tree_insert_html_element(tree, token);
862
+ if (element == NULL) {
863
+ return NULL;
864
+ }
865
+
866
+ /*
867
+ * Need for tokenizer state RAWTEXT
868
+ * See description for 'lxb_html_tokenizer_state_rawtext_before' function
869
+ */
870
+ lxb_html_tokenizer_tmp_tag_id_set(tree->tkz_ref, token->tag_id);
871
+ lxb_html_tokenizer_state_set(tree->tkz_ref,
872
+ lxb_html_tokenizer_state_rawtext_before);
873
+
874
+ tree->original_mode = tree->mode;
875
+ tree->mode = lxb_html_tree_insertion_mode_text;
876
+
877
+ return element;
878
+ }
879
+
880
+ /* Magic of CopyPast power! */
881
+ lxb_html_element_t *
882
+ lxb_html_tree_generic_rcdata_parsing(lxb_html_tree_t *tree,
883
+ lxb_html_token_t *token)
884
+ {
885
+ lxb_html_element_t *element;
886
+
887
+ element = lxb_html_tree_insert_html_element(tree, token);
888
+ if (element == NULL) {
889
+ return NULL;
890
+ }
891
+
892
+ /*
893
+ * Need for tokenizer state RCDATA
894
+ * See description for 'lxb_html_tokenizer_state_rcdata_before' function
895
+ */
896
+ lxb_html_tokenizer_tmp_tag_id_set(tree->tkz_ref, token->tag_id);
897
+ lxb_html_tokenizer_state_set(tree->tkz_ref,
898
+ lxb_html_tokenizer_state_rcdata_before);
899
+
900
+ tree->original_mode = tree->mode;
901
+ tree->mode = lxb_html_tree_insertion_mode_text;
902
+
903
+ return element;
904
+ }
905
+
906
+ void
907
+ lxb_html_tree_generate_implied_end_tags(lxb_html_tree_t *tree,
908
+ lxb_tag_id_t ex_tag, lxb_ns_id_t ex_ns)
909
+ {
910
+ lxb_dom_node_t *node;
911
+
912
+ lexbor_assert(tree->open_elements != 0);
913
+
914
+ while (lexbor_array_length(tree->open_elements) != 0) {
915
+ node = lxb_html_tree_current_node(tree);
916
+
917
+ lexbor_assert(node != NULL);
918
+
919
+ switch (node->local_name) {
920
+ case LXB_TAG_DD:
921
+ case LXB_TAG_DT:
922
+ case LXB_TAG_LI:
923
+ case LXB_TAG_OPTGROUP:
924
+ case LXB_TAG_OPTION:
925
+ case LXB_TAG_P:
926
+ case LXB_TAG_RB:
927
+ case LXB_TAG_RP:
928
+ case LXB_TAG_RT:
929
+ case LXB_TAG_RTC:
930
+ if(node->local_name == ex_tag && node->ns == ex_ns) {
931
+ return;
932
+ }
933
+
934
+ lxb_html_tree_open_elements_pop(tree);
935
+
936
+ break;
937
+
938
+ default:
939
+ return;
940
+ }
941
+ }
942
+ }
943
+
944
+ void
945
+ lxb_html_tree_generate_all_implied_end_tags_thoroughly(lxb_html_tree_t *tree,
946
+ lxb_tag_id_t ex_tag,
947
+ lxb_ns_id_t ex_ns)
948
+ {
949
+ lxb_dom_node_t *node;
950
+
951
+ lexbor_assert(tree->open_elements != 0);
952
+
953
+ while (lexbor_array_length(tree->open_elements) != 0) {
954
+ node = lxb_html_tree_current_node(tree);
955
+
956
+ lexbor_assert(node != NULL);
957
+
958
+ switch (node->local_name) {
959
+ case LXB_TAG_CAPTION:
960
+ case LXB_TAG_COLGROUP:
961
+ case LXB_TAG_DD:
962
+ case LXB_TAG_DT:
963
+ case LXB_TAG_LI:
964
+ case LXB_TAG_OPTGROUP:
965
+ case LXB_TAG_OPTION:
966
+ case LXB_TAG_P:
967
+ case LXB_TAG_RB:
968
+ case LXB_TAG_RP:
969
+ case LXB_TAG_RT:
970
+ case LXB_TAG_RTC:
971
+ case LXB_TAG_TBODY:
972
+ case LXB_TAG_TD:
973
+ case LXB_TAG_TFOOT:
974
+ case LXB_TAG_TH:
975
+ case LXB_TAG_THEAD:
976
+ case LXB_TAG_TR:
977
+ if(node->local_name == ex_tag && node->ns == ex_ns) {
978
+ return;
979
+ }
980
+
981
+ lxb_html_tree_open_elements_pop(tree);
982
+
983
+ break;
984
+
985
+ default:
986
+ return;
987
+ }
988
+ }
989
+ }
990
+
991
+ void
992
+ lxb_html_tree_reset_insertion_mode_appropriately(lxb_html_tree_t *tree)
993
+ {
994
+ lxb_dom_node_t *node;
995
+ size_t idx = tree->open_elements->length;
996
+
997
+ /* Step 1 */
998
+ bool last = false;
999
+ void **list = tree->open_elements->list;
1000
+
1001
+ /* Step 3 */
1002
+ while (idx != 0) {
1003
+ idx--;
1004
+
1005
+ /* Step 2 */
1006
+ node = list[idx];
1007
+
1008
+ /* Step 3 */
1009
+ if (idx == 0) {
1010
+ last = true;
1011
+
1012
+ if (tree->fragment != NULL) {
1013
+ node = tree->fragment;
1014
+ }
1015
+ }
1016
+
1017
+ lexbor_assert(node != NULL);
1018
+
1019
+ /* Step 16 */
1020
+ if (node->ns != LXB_NS_HTML) {
1021
+ if (last) {
1022
+ tree->mode = lxb_html_tree_insertion_mode_in_body;
1023
+ return;
1024
+ }
1025
+
1026
+ continue;
1027
+ }
1028
+
1029
+ /* Step 4 */
1030
+ if (node->local_name == LXB_TAG_SELECT) {
1031
+ /* Step 4.1 */
1032
+ if (last) {
1033
+ tree->mode = lxb_html_tree_insertion_mode_in_select;
1034
+ return;
1035
+ }
1036
+
1037
+ /* Step 4.2 */
1038
+ size_t ancestor = idx;
1039
+
1040
+ for (;;) {
1041
+ /* Step 4.3 */
1042
+ if (ancestor == 0) {
1043
+ tree->mode = lxb_html_tree_insertion_mode_in_select;
1044
+ return;
1045
+ }
1046
+
1047
+ /* Step 4.4 */
1048
+ ancestor--;
1049
+
1050
+ /* Step 4.5 */
1051
+ lxb_dom_node_t *ancestor_node = list[ancestor];
1052
+
1053
+ if(lxb_html_tree_node_is(ancestor_node, LXB_TAG_TEMPLATE)) {
1054
+ tree->mode = lxb_html_tree_insertion_mode_in_select;
1055
+ return;
1056
+ }
1057
+
1058
+ /* Step 4.6 */
1059
+ else if(lxb_html_tree_node_is(ancestor_node, LXB_TAG_TABLE)) {
1060
+ tree->mode = lxb_html_tree_insertion_mode_in_select_in_table;
1061
+ return;
1062
+ }
1063
+ }
1064
+ }
1065
+
1066
+ /* Step 5-15 */
1067
+ switch (node->local_name) {
1068
+ case LXB_TAG_TD:
1069
+ case LXB_TAG_TH:
1070
+ if (last == false) {
1071
+ tree->mode = lxb_html_tree_insertion_mode_in_cell;
1072
+ return;
1073
+ }
1074
+
1075
+ break;
1076
+
1077
+ case LXB_TAG_TR:
1078
+ tree->mode = lxb_html_tree_insertion_mode_in_row;
1079
+ return;
1080
+
1081
+ case LXB_TAG_TBODY:
1082
+ case LXB_TAG_TFOOT:
1083
+ case LXB_TAG_THEAD:
1084
+ tree->mode = lxb_html_tree_insertion_mode_in_table_body;
1085
+ return;
1086
+
1087
+ case LXB_TAG_CAPTION:
1088
+ tree->mode = lxb_html_tree_insertion_mode_in_caption;
1089
+ return;
1090
+
1091
+ case LXB_TAG_COLGROUP:
1092
+ tree->mode = lxb_html_tree_insertion_mode_in_column_group;
1093
+ return;
1094
+
1095
+ case LXB_TAG_TABLE:
1096
+ tree->mode = lxb_html_tree_insertion_mode_in_table;
1097
+ return;
1098
+
1099
+ case LXB_TAG_TEMPLATE:
1100
+ tree->mode = lxb_html_tree_template_insertion_current(tree);
1101
+
1102
+ lexbor_assert(tree->mode != NULL);
1103
+
1104
+ return;
1105
+
1106
+ case LXB_TAG_HEAD:
1107
+ if (last == false) {
1108
+ tree->mode = lxb_html_tree_insertion_mode_in_head;
1109
+ return;
1110
+ }
1111
+
1112
+ break;
1113
+
1114
+ case LXB_TAG_BODY:
1115
+ tree->mode = lxb_html_tree_insertion_mode_in_body;
1116
+ return;
1117
+
1118
+ case LXB_TAG_FRAMESET:
1119
+ tree->mode = lxb_html_tree_insertion_mode_in_frameset;
1120
+ return;
1121
+
1122
+ case LXB_TAG_HTML: {
1123
+ if (tree->document->head == NULL) {
1124
+ tree->mode = lxb_html_tree_insertion_mode_before_head;
1125
+ return;
1126
+ }
1127
+
1128
+ tree->mode = lxb_html_tree_insertion_mode_after_head;
1129
+ return;
1130
+ }
1131
+
1132
+ default:
1133
+ break;
1134
+ }
1135
+
1136
+ /* Step 16 */
1137
+ if (last) {
1138
+ tree->mode = lxb_html_tree_insertion_mode_in_body;
1139
+ return;
1140
+ }
1141
+ }
1142
+ }
1143
+
1144
+ lxb_dom_node_t *
1145
+ lxb_html_tree_element_in_scope(lxb_html_tree_t *tree, lxb_tag_id_t tag_id,
1146
+ lxb_ns_id_t ns, lxb_html_tag_category_t ct)
1147
+ {
1148
+ lxb_dom_node_t *node;
1149
+
1150
+ size_t idx = tree->open_elements->length;
1151
+ void **list = tree->open_elements->list;
1152
+
1153
+ while (idx != 0) {
1154
+ idx--;
1155
+ node = list[idx];
1156
+
1157
+ if (node->local_name == tag_id && node->ns == ns) {
1158
+ return node;
1159
+ }
1160
+
1161
+ if (lxb_html_tag_is_category(node->local_name, node->ns, ct)) {
1162
+ return NULL;
1163
+ }
1164
+ }
1165
+
1166
+ return NULL;
1167
+ }
1168
+
1169
+ lxb_dom_node_t *
1170
+ lxb_html_tree_element_in_scope_by_node(lxb_html_tree_t *tree,
1171
+ lxb_dom_node_t *by_node,
1172
+ lxb_html_tag_category_t ct)
1173
+ {
1174
+ lxb_dom_node_t *node;
1175
+
1176
+ size_t idx = tree->open_elements->length;
1177
+ void **list = tree->open_elements->list;
1178
+
1179
+ while (idx != 0) {
1180
+ idx--;
1181
+ node = list[idx];
1182
+
1183
+ if (node == by_node) {
1184
+ return node;
1185
+ }
1186
+
1187
+ if (lxb_html_tag_is_category(node->local_name, node->ns, ct)) {
1188
+ return NULL;
1189
+ }
1190
+ }
1191
+
1192
+ return NULL;
1193
+ }
1194
+
1195
+ lxb_dom_node_t *
1196
+ lxb_html_tree_element_in_scope_h123456(lxb_html_tree_t *tree)
1197
+ {
1198
+ lxb_dom_node_t *node;
1199
+
1200
+ size_t idx = tree->open_elements->length;
1201
+ void **list = tree->open_elements->list;
1202
+
1203
+ while (idx != 0) {
1204
+ idx--;
1205
+ node = list[idx];
1206
+
1207
+ switch (node->local_name) {
1208
+ case LXB_TAG_H1:
1209
+ case LXB_TAG_H2:
1210
+ case LXB_TAG_H3:
1211
+ case LXB_TAG_H4:
1212
+ case LXB_TAG_H5:
1213
+ case LXB_TAG_H6:
1214
+ if (node->ns == LXB_NS_HTML) {
1215
+ return node;
1216
+ }
1217
+
1218
+ break;
1219
+
1220
+ default:
1221
+ break;
1222
+ }
1223
+
1224
+ if (lxb_html_tag_is_category(node->local_name, LXB_NS_HTML,
1225
+ LXB_HTML_TAG_CATEGORY_SCOPE))
1226
+ {
1227
+ return NULL;
1228
+ }
1229
+ }
1230
+
1231
+ return NULL;
1232
+ }
1233
+
1234
+ lxb_dom_node_t *
1235
+ lxb_html_tree_element_in_scope_tbody_thead_tfoot(lxb_html_tree_t *tree)
1236
+ {
1237
+ lxb_dom_node_t *node;
1238
+
1239
+ size_t idx = tree->open_elements->length;
1240
+ void **list = tree->open_elements->list;
1241
+
1242
+ while (idx != 0) {
1243
+ idx--;
1244
+ node = list[idx];
1245
+
1246
+ switch (node->local_name) {
1247
+ case LXB_TAG_TBODY:
1248
+ case LXB_TAG_THEAD:
1249
+ case LXB_TAG_TFOOT:
1250
+ if (node->ns == LXB_NS_HTML) {
1251
+ return node;
1252
+ }
1253
+
1254
+ break;
1255
+
1256
+ default:
1257
+ break;
1258
+ }
1259
+
1260
+ if (lxb_html_tag_is_category(node->local_name, LXB_NS_HTML,
1261
+ LXB_HTML_TAG_CATEGORY_SCOPE_TABLE))
1262
+ {
1263
+ return NULL;
1264
+ }
1265
+ }
1266
+
1267
+ return NULL;
1268
+ }
1269
+
1270
+ lxb_dom_node_t *
1271
+ lxb_html_tree_element_in_scope_td_th(lxb_html_tree_t *tree)
1272
+ {
1273
+ lxb_dom_node_t *node;
1274
+
1275
+ size_t idx = tree->open_elements->length;
1276
+ void **list = tree->open_elements->list;
1277
+
1278
+ while (idx != 0) {
1279
+ idx--;
1280
+ node = list[idx];
1281
+
1282
+ switch (node->local_name) {
1283
+ case LXB_TAG_TD:
1284
+ case LXB_TAG_TH:
1285
+ if (node->ns == LXB_NS_HTML) {
1286
+ return node;
1287
+ }
1288
+
1289
+ break;
1290
+
1291
+ default:
1292
+ break;
1293
+ }
1294
+
1295
+ if (lxb_html_tag_is_category(node->local_name, LXB_NS_HTML,
1296
+ LXB_HTML_TAG_CATEGORY_SCOPE_TABLE))
1297
+ {
1298
+ return NULL;
1299
+ }
1300
+ }
1301
+
1302
+ return NULL;
1303
+ }
1304
+
1305
+ bool
1306
+ lxb_html_tree_check_scope_element(lxb_html_tree_t *tree)
1307
+ {
1308
+ lxb_dom_node_t *node;
1309
+
1310
+ for (size_t i = 0; i < tree->open_elements->length; i++) {
1311
+ node = tree->open_elements->list[i];
1312
+
1313
+ switch (node->local_name) {
1314
+ case LXB_TAG_DD:
1315
+ case LXB_TAG_DT:
1316
+ case LXB_TAG_LI:
1317
+ case LXB_TAG_OPTGROUP:
1318
+ case LXB_TAG_OPTION:
1319
+ case LXB_TAG_P:
1320
+ case LXB_TAG_RB:
1321
+ case LXB_TAG_RP:
1322
+ case LXB_TAG_RT:
1323
+ case LXB_TAG_RTC:
1324
+ case LXB_TAG_TBODY:
1325
+ case LXB_TAG_TD:
1326
+ case LXB_TAG_TFOOT:
1327
+ case LXB_TAG_TH:
1328
+ case LXB_TAG_THEAD:
1329
+ case LXB_TAG_TR:
1330
+ case LXB_TAG_BODY:
1331
+ case LXB_TAG_HTML:
1332
+ return true;
1333
+
1334
+ default:
1335
+ break;
1336
+ }
1337
+ }
1338
+
1339
+ return false;
1340
+ }
1341
+
1342
+ void
1343
+ lxb_html_tree_close_p_element(lxb_html_tree_t *tree, lxb_html_token_t *token)
1344
+ {
1345
+ lxb_html_tree_generate_implied_end_tags(tree, LXB_TAG_P, LXB_NS_HTML);
1346
+
1347
+ lxb_dom_node_t *node = lxb_html_tree_current_node(tree);
1348
+
1349
+ if (lxb_html_tree_node_is(node, LXB_TAG_P) == false) {
1350
+ lxb_html_tree_parse_error(tree, token,
1351
+ LXB_HTML_RULES_ERROR_UNELINOPELST);
1352
+ }
1353
+
1354
+ lxb_html_tree_open_elements_pop_until_tag_id(tree, LXB_TAG_P, LXB_NS_HTML,
1355
+ true);
1356
+ }
1357
+
1358
+ #include "lexbor/html/serialize.h"
1359
+
1360
+ bool
1361
+ lxb_html_tree_adoption_agency_algorithm(lxb_html_tree_t *tree,
1362
+ lxb_html_token_t *token,
1363
+ lxb_status_t *status)
1364
+ {
1365
+ lexbor_assert(tree->open_elements->length != 0);
1366
+
1367
+ /* State 1 */
1368
+ bool is;
1369
+ short outer_loop;
1370
+ lxb_html_element_t *element;
1371
+ lxb_dom_node_t *node, *marker, **oel_list, **afe_list;
1372
+
1373
+ lxb_tag_id_t subject = token->tag_id;
1374
+
1375
+ oel_list = (lxb_dom_node_t **) tree->open_elements->list;
1376
+ afe_list = (lxb_dom_node_t **) tree->active_formatting->list;
1377
+ marker = (lxb_dom_node_t *) lxb_html_tree_active_formatting_marker();
1378
+
1379
+ *status = LXB_STATUS_OK;
1380
+
1381
+ /* State 2 */
1382
+ node = lxb_html_tree_current_node(tree);
1383
+ lexbor_assert(node != NULL);
1384
+
1385
+ if (lxb_html_tree_node_is(node, subject)) {
1386
+ is = lxb_html_tree_active_formatting_find_by_node_reverse(tree, node,
1387
+ NULL);
1388
+ if (is == false) {
1389
+ lxb_html_tree_open_elements_pop(tree);
1390
+
1391
+ return false;
1392
+ }
1393
+ }
1394
+
1395
+ /* State 3 */
1396
+ outer_loop = 0;
1397
+
1398
+ /* State 4 */
1399
+ while (outer_loop < 8) {
1400
+ /* State 5 */
1401
+ outer_loop++;
1402
+
1403
+ /* State 6 */
1404
+ size_t formatting_index = 0;
1405
+ size_t idx = tree->active_formatting->length;
1406
+ lxb_dom_node_t *formatting_element = NULL;
1407
+
1408
+ while (idx) {
1409
+ idx--;
1410
+
1411
+ if (afe_list[idx] == marker) {
1412
+ return true;
1413
+ }
1414
+ else if (afe_list[idx]->local_name == subject) {
1415
+ formatting_index = idx;
1416
+ formatting_element = afe_list[idx];
1417
+
1418
+ break;
1419
+ }
1420
+ }
1421
+
1422
+ if (formatting_element == NULL) {
1423
+ return true;
1424
+ }
1425
+
1426
+ /* State 7 */
1427
+ size_t oel_formatting_idx;
1428
+ is = lxb_html_tree_open_elements_find_by_node_reverse(tree,
1429
+ formatting_element,
1430
+ &oel_formatting_idx);
1431
+ if (is == false) {
1432
+ lxb_html_tree_parse_error(tree, token,
1433
+ LXB_HTML_RULES_ERROR_MIELINOPELST);
1434
+
1435
+ lxb_html_tree_active_formatting_remove_by_node(tree,
1436
+ formatting_element);
1437
+
1438
+ return false;
1439
+ }
1440
+
1441
+ /* State 8 */
1442
+ node = lxb_html_tree_element_in_scope_by_node(tree, formatting_element,
1443
+ LXB_HTML_TAG_CATEGORY_SCOPE);
1444
+ if (node == NULL) {
1445
+ lxb_html_tree_parse_error(tree, token,
1446
+ LXB_HTML_RULES_ERROR_MIELINSC);
1447
+ return false;
1448
+ }
1449
+
1450
+ /* State 9 */
1451
+ node = lxb_html_tree_current_node(tree);
1452
+
1453
+ if (formatting_element != node) {
1454
+ lxb_html_tree_parse_error(tree, token,
1455
+ LXB_HTML_RULES_ERROR_UNELINOPELST);
1456
+ }
1457
+
1458
+ /* State 10 */
1459
+ lxb_dom_node_t *furthest_block = NULL;
1460
+ size_t furthest_block_idx = 0;
1461
+ size_t oel_idx = tree->open_elements->length;
1462
+
1463
+ for (furthest_block_idx = oel_formatting_idx;
1464
+ furthest_block_idx < oel_idx;
1465
+ furthest_block_idx++)
1466
+ {
1467
+ is = lxb_html_tag_is_category(oel_list[furthest_block_idx]->local_name,
1468
+ oel_list[furthest_block_idx]->ns,
1469
+ LXB_HTML_TAG_CATEGORY_SPECIAL);
1470
+ if (is) {
1471
+ furthest_block = oel_list[furthest_block_idx];
1472
+
1473
+ break;
1474
+ }
1475
+ }
1476
+
1477
+ /* State 11 */
1478
+ if (furthest_block == NULL) {
1479
+ lxb_html_tree_open_elements_pop_until_node(tree, formatting_element,
1480
+ true);
1481
+
1482
+ lxb_html_tree_active_formatting_remove_by_node(tree,
1483
+ formatting_element);
1484
+
1485
+ return false;
1486
+ }
1487
+
1488
+ lexbor_assert(oel_formatting_idx != 0);
1489
+
1490
+ /* State 12 */
1491
+ lxb_dom_node_t *common_ancestor = oel_list[oel_formatting_idx - 1];
1492
+
1493
+ /* State 13 */
1494
+ size_t bookmark = formatting_index;
1495
+
1496
+ /* State 14 */
1497
+ lxb_dom_node_t *node;
1498
+ lxb_dom_node_t *last = furthest_block;
1499
+ size_t node_idx = furthest_block_idx;
1500
+
1501
+ /* State 14.1 */
1502
+ size_t inner_loop_counter = 0;
1503
+
1504
+ /* State 14.2 */
1505
+ while (1) {
1506
+ inner_loop_counter++;
1507
+
1508
+ /* State 14.3 */
1509
+ lexbor_assert(node_idx != 0);
1510
+
1511
+ if (node_idx == 0) {
1512
+ return false;
1513
+ }
1514
+
1515
+ node_idx--;
1516
+ node = oel_list[node_idx];
1517
+
1518
+ /* State 14.4 */
1519
+ if (node == formatting_element) {
1520
+ break;
1521
+ }
1522
+
1523
+ /* State 14.5 */
1524
+ size_t afe_node_idx;
1525
+ is = lxb_html_tree_active_formatting_find_by_node_reverse(tree,
1526
+ node,
1527
+ &afe_node_idx);
1528
+ /* State 14.5 */
1529
+ if (inner_loop_counter > 3 && is) {
1530
+ lxb_html_tree_active_formatting_remove_by_node(tree, node);
1531
+
1532
+ continue;
1533
+ }
1534
+
1535
+ /* State 14.6 */
1536
+ if (is == false) {
1537
+ lxb_html_tree_open_elements_remove_by_node(tree, node);
1538
+
1539
+ continue;
1540
+ }
1541
+
1542
+ /* State 14.7 */
1543
+ lxb_html_token_t fake_token = {0};
1544
+
1545
+ fake_token.tag_id = node->local_name;
1546
+ fake_token.base_element = node;
1547
+
1548
+ element = lxb_html_tree_create_element_for_token(tree, &fake_token,
1549
+ LXB_NS_HTML,
1550
+ common_ancestor);
1551
+ if (element == NULL) {
1552
+ *status = LXB_STATUS_ERROR_MEMORY_ALLOCATION;
1553
+
1554
+ return false;
1555
+ }
1556
+
1557
+ node = lxb_dom_interface_node(element);
1558
+
1559
+ afe_list[afe_node_idx] = node;
1560
+ oel_list[node_idx] = node;
1561
+
1562
+ /* State 14.8 */
1563
+ if (last == furthest_block) {
1564
+ bookmark = afe_node_idx + 1;
1565
+
1566
+ lexbor_assert(bookmark < tree->active_formatting->length);
1567
+ }
1568
+
1569
+ /* State 14.9 */
1570
+ if (last->parent != NULL) {
1571
+ lxb_dom_node_remove(last);
1572
+ }
1573
+
1574
+ lxb_dom_node_insert_child(node, last);
1575
+
1576
+ /* State 14.10 */
1577
+ last = node;
1578
+ }
1579
+
1580
+ if (last->parent != NULL) {
1581
+ lxb_dom_node_remove(last);
1582
+ }
1583
+
1584
+ /* State 15 */
1585
+ lxb_dom_node_t *pos;
1586
+ lxb_html_tree_insertion_position_t ipos;
1587
+
1588
+ pos = lxb_html_tree_appropriate_place_inserting_node(tree,
1589
+ common_ancestor,
1590
+ &ipos);
1591
+ if (pos == NULL) {
1592
+ return false;
1593
+ }
1594
+
1595
+ lxb_html_tree_insert_node(pos, last, ipos);
1596
+
1597
+ /* State 16 */
1598
+ lxb_html_token_t fake_token = {0};
1599
+
1600
+ fake_token.tag_id = formatting_element->local_name;
1601
+ fake_token.base_element = formatting_element;
1602
+
1603
+ element = lxb_html_tree_create_element_for_token(tree, &fake_token,
1604
+ LXB_NS_HTML,
1605
+ furthest_block);
1606
+ if (element == NULL) {
1607
+ *status = LXB_STATUS_ERROR_MEMORY_ALLOCATION;
1608
+
1609
+ return false;
1610
+ }
1611
+
1612
+ /* State 17 */
1613
+ lxb_dom_node_t *next;
1614
+ node = furthest_block->first_child;
1615
+
1616
+ while (node != NULL) {
1617
+ next = node->next;
1618
+
1619
+ lxb_dom_node_remove(node);
1620
+ lxb_dom_node_insert_child(lxb_dom_interface_node(element), node);
1621
+
1622
+ node = next;
1623
+ }
1624
+
1625
+ node = lxb_dom_interface_node(element);
1626
+
1627
+ /* State 18 */
1628
+ lxb_dom_node_insert_child(furthest_block, node);
1629
+
1630
+ /* State 19 */
1631
+ lxb_html_tree_active_formatting_remove(tree, formatting_index);
1632
+
1633
+ if (bookmark > tree->active_formatting->length) {
1634
+ bookmark = tree->active_formatting->length;
1635
+ }
1636
+
1637
+ *status = lxb_html_tree_active_formatting_insert(tree, node, bookmark);
1638
+ if (*status != LXB_STATUS_OK) {
1639
+ return false;
1640
+ }
1641
+
1642
+ /* State 20 */
1643
+ lxb_html_tree_open_elements_remove_by_node(tree, formatting_element);
1644
+
1645
+ lxb_html_tree_open_elements_find_by_node(tree, furthest_block,
1646
+ &furthest_block_idx);
1647
+
1648
+ *status = lxb_html_tree_open_elements_insert_after(tree, node,
1649
+ furthest_block_idx);
1650
+ if (*status != LXB_STATUS_OK) {
1651
+ return false;
1652
+ }
1653
+ }
1654
+
1655
+ return false;
1656
+ }
1657
+
1658
+ bool
1659
+ lxb_html_tree_html_integration_point(lxb_dom_node_t *node)
1660
+ {
1661
+ if (node->ns == LXB_NS_MATH
1662
+ && node->local_name == LXB_TAG_ANNOTATION_XML)
1663
+ {
1664
+ lxb_dom_attr_t *attr;
1665
+ attr = lxb_dom_element_attr_is_exist(lxb_dom_interface_element(node),
1666
+ (const lxb_char_t *) "encoding",
1667
+ 8);
1668
+ if (attr == NULL || attr->value == NULL) {
1669
+ return false;
1670
+ }
1671
+
1672
+ if (attr->value->length == 9
1673
+ && lexbor_str_data_casecmp(attr->value->data,
1674
+ (const lxb_char_t *) "text/html"))
1675
+ {
1676
+ return true;
1677
+ }
1678
+
1679
+ if (attr->value->length == 21
1680
+ && lexbor_str_data_casecmp(attr->value->data,
1681
+ (const lxb_char_t *) "application/xhtml+xml"))
1682
+ {
1683
+ return true;
1684
+ }
1685
+
1686
+ return false;
1687
+ }
1688
+
1689
+ if (node->ns == LXB_NS_SVG
1690
+ && (node->local_name == LXB_TAG_FOREIGNOBJECT
1691
+ || node->local_name == LXB_TAG_DESC
1692
+ || node->local_name == LXB_TAG_TITLE))
1693
+ {
1694
+ return true;
1695
+ }
1696
+
1697
+ return false;
1698
+ }
1699
+
1700
+ lxb_status_t
1701
+ lxb_html_tree_adjust_attributes_mathml(lxb_html_tree_t *tree,
1702
+ lxb_dom_attr_t *attr, void *ctx)
1703
+ {
1704
+ lxb_status_t status;
1705
+
1706
+ status = lxb_html_tree_adjust_mathml_attributes(tree, attr, ctx);
1707
+ if (status !=LXB_STATUS_OK) {
1708
+ return status;
1709
+ }
1710
+
1711
+ return lxb_html_tree_adjust_foreign_attributes(tree, attr, ctx);
1712
+ }
1713
+
1714
+ lxb_status_t
1715
+ lxb_html_tree_adjust_attributes_svg(lxb_html_tree_t *tree,
1716
+ lxb_dom_attr_t *attr, void *ctx)
1717
+ {
1718
+ lxb_status_t status;
1719
+
1720
+ status = lxb_html_tree_adjust_svg_attributes(tree, attr, ctx);
1721
+ if (status !=LXB_STATUS_OK) {
1722
+ return status;
1723
+ }
1724
+
1725
+ return lxb_html_tree_adjust_foreign_attributes(tree, attr, ctx);
1726
+ }