nokolexbor 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/nokolexbor/config.h +186 -0
- data/ext/nokolexbor/extconf.rb +131 -0
- data/ext/nokolexbor/libxml/HTMLparser.h +320 -0
- data/ext/nokolexbor/libxml/SAX2.h +173 -0
- data/ext/nokolexbor/libxml/chvalid.h +230 -0
- data/ext/nokolexbor/libxml/debugXML.h +217 -0
- data/ext/nokolexbor/libxml/dict.h +81 -0
- data/ext/nokolexbor/libxml/encoding.h +232 -0
- data/ext/nokolexbor/libxml/entities.h +153 -0
- data/ext/nokolexbor/libxml/globals.h +529 -0
- data/ext/nokolexbor/libxml/hash.h +236 -0
- data/ext/nokolexbor/libxml/list.h +137 -0
- data/ext/nokolexbor/libxml/parser.h +1264 -0
- data/ext/nokolexbor/libxml/parserInternals.h +641 -0
- data/ext/nokolexbor/libxml/pattern.h +100 -0
- data/ext/nokolexbor/libxml/threads.h +94 -0
- data/ext/nokolexbor/libxml/tree.h +1315 -0
- data/ext/nokolexbor/libxml/uri.h +94 -0
- data/ext/nokolexbor/libxml/valid.h +448 -0
- data/ext/nokolexbor/libxml/xmlIO.h +369 -0
- data/ext/nokolexbor/libxml/xmlautomata.h +146 -0
- data/ext/nokolexbor/libxml/xmlerror.h +919 -0
- data/ext/nokolexbor/libxml/xmlexports.h +79 -0
- data/ext/nokolexbor/libxml/xmlmemory.h +226 -0
- data/ext/nokolexbor/libxml/xmlregexp.h +222 -0
- data/ext/nokolexbor/libxml/xmlstring.h +140 -0
- data/ext/nokolexbor/libxml/xmlversion.h +526 -0
- data/ext/nokolexbor/libxml/xpath.h +575 -0
- data/ext/nokolexbor/libxml/xpathInternals.h +632 -0
- data/ext/nokolexbor/libxml/xpointer.h +137 -0
- data/ext/nokolexbor/libxml.h +76 -0
- data/ext/nokolexbor/memory.c +39 -0
- data/ext/nokolexbor/nl_document.c +51 -0
- data/ext/nokolexbor/nl_node.c +790 -0
- data/ext/nokolexbor/nl_node_set.c +368 -0
- data/ext/nokolexbor/nl_xpath_context.c +200 -0
- data/ext/nokolexbor/nokolexbor.c +63 -0
- data/ext/nokolexbor/nokolexbor.h +37 -0
- data/ext/nokolexbor/private/buf.h +70 -0
- data/ext/nokolexbor/private/dict.h +11 -0
- data/ext/nokolexbor/private/enc.h +17 -0
- data/ext/nokolexbor/private/error.h +21 -0
- data/ext/nokolexbor/private/globals.h +9 -0
- data/ext/nokolexbor/private/memory.h +9 -0
- data/ext/nokolexbor/private/parser.h +27 -0
- data/ext/nokolexbor/private/string.h +9 -0
- data/ext/nokolexbor/private/threads.h +50 -0
- data/ext/nokolexbor/private/tree.h +18 -0
- data/ext/nokolexbor/private/xpath.h +7 -0
- data/ext/nokolexbor/timsort.h +601 -0
- data/ext/nokolexbor/xml_SAX2.c +80 -0
- data/ext/nokolexbor/xml_buf.c +363 -0
- data/ext/nokolexbor/xml_chvalid.c +334 -0
- data/ext/nokolexbor/xml_dict.c +1264 -0
- data/ext/nokolexbor/xml_encoding.c +124 -0
- data/ext/nokolexbor/xml_error.c +134 -0
- data/ext/nokolexbor/xml_globals.c +1085 -0
- data/ext/nokolexbor/xml_hash.c +1141 -0
- data/ext/nokolexbor/xml_memory.c +203 -0
- data/ext/nokolexbor/xml_parser.c +127 -0
- data/ext/nokolexbor/xml_parserInternals.c +338 -0
- data/ext/nokolexbor/xml_pattern.c +2375 -0
- data/ext/nokolexbor/xml_string.c +1051 -0
- data/ext/nokolexbor/xml_threads.c +881 -0
- data/ext/nokolexbor/xml_tree.c +148 -0
- data/ext/nokolexbor/xml_xpath.c +14743 -0
- data/lib/nokolexbor/attribute.rb +18 -0
- data/lib/nokolexbor/document.rb +6 -0
- data/lib/nokolexbor/node.rb +264 -0
- data/lib/nokolexbor/node_set.rb +124 -0
- data/lib/nokolexbor/version.rb +5 -0
- data/lib/nokolexbor/xpath_context.rb +14 -0
- data/lib/nokolexbor.rb +17 -0
- data/patches/0001-lexbor-support-text-pseudo-element.patch +137 -0
- data/patches/0002-lexbor-match-id-class-case-sensitive.patch +22 -0
- data/patches/0003-lexbor-attach-template-content-to-self.patch +13 -0
- data/vendor/lexbor/CMakeLists.txt +331 -0
- data/vendor/lexbor/config.cmake +890 -0
- data/vendor/lexbor/feature.cmake +134 -0
- data/vendor/lexbor/source/lexbor/core/array.c +208 -0
- data/vendor/lexbor/source/lexbor/core/array.h +100 -0
- data/vendor/lexbor/source/lexbor/core/array_obj.c +216 -0
- data/vendor/lexbor/source/lexbor/core/array_obj.h +134 -0
- data/vendor/lexbor/source/lexbor/core/avl.c +442 -0
- data/vendor/lexbor/source/lexbor/core/avl.h +82 -0
- data/vendor/lexbor/source/lexbor/core/base.h +86 -0
- data/vendor/lexbor/source/lexbor/core/bst.c +468 -0
- data/vendor/lexbor/source/lexbor/core/bst.h +108 -0
- data/vendor/lexbor/source/lexbor/core/bst_map.c +238 -0
- data/vendor/lexbor/source/lexbor/core/bst_map.h +87 -0
- data/vendor/lexbor/source/lexbor/core/config.cmake +12 -0
- data/vendor/lexbor/source/lexbor/core/conv.c +203 -0
- data/vendor/lexbor/source/lexbor/core/conv.h +53 -0
- data/vendor/lexbor/source/lexbor/core/core.h +35 -0
- data/vendor/lexbor/source/lexbor/core/def.h +57 -0
- data/vendor/lexbor/source/lexbor/core/diyfp.c +153 -0
- data/vendor/lexbor/source/lexbor/core/diyfp.h +258 -0
- data/vendor/lexbor/source/lexbor/core/dobject.c +187 -0
- data/vendor/lexbor/source/lexbor/core/dobject.h +92 -0
- data/vendor/lexbor/source/lexbor/core/dtoa.c +404 -0
- data/vendor/lexbor/source/lexbor/core/dtoa.h +28 -0
- data/vendor/lexbor/source/lexbor/core/fs.h +60 -0
- data/vendor/lexbor/source/lexbor/core/hash.c +476 -0
- data/vendor/lexbor/source/lexbor/core/hash.h +218 -0
- data/vendor/lexbor/source/lexbor/core/in.c +267 -0
- data/vendor/lexbor/source/lexbor/core/in.h +172 -0
- data/vendor/lexbor/source/lexbor/core/lexbor.h +35 -0
- data/vendor/lexbor/source/lexbor/core/mem.c +228 -0
- data/vendor/lexbor/source/lexbor/core/mem.h +141 -0
- data/vendor/lexbor/source/lexbor/core/mraw.c +428 -0
- data/vendor/lexbor/source/lexbor/core/mraw.h +114 -0
- data/vendor/lexbor/source/lexbor/core/perf.h +45 -0
- data/vendor/lexbor/source/lexbor/core/plog.c +73 -0
- data/vendor/lexbor/source/lexbor/core/plog.h +102 -0
- data/vendor/lexbor/source/lexbor/core/print.c +168 -0
- data/vendor/lexbor/source/lexbor/core/print.h +39 -0
- data/vendor/lexbor/source/lexbor/core/sbst.h +59 -0
- data/vendor/lexbor/source/lexbor/core/serialize.c +27 -0
- data/vendor/lexbor/source/lexbor/core/serialize.h +32 -0
- data/vendor/lexbor/source/lexbor/core/shs.c +118 -0
- data/vendor/lexbor/source/lexbor/core/shs.h +82 -0
- data/vendor/lexbor/source/lexbor/core/str.c +617 -0
- data/vendor/lexbor/source/lexbor/core/str.h +247 -0
- data/vendor/lexbor/source/lexbor/core/str_res.h +369 -0
- data/vendor/lexbor/source/lexbor/core/strtod.c +326 -0
- data/vendor/lexbor/source/lexbor/core/strtod.h +28 -0
- data/vendor/lexbor/source/lexbor/core/types.h +39 -0
- data/vendor/lexbor/source/lexbor/core/utils.c +43 -0
- data/vendor/lexbor/source/lexbor/core/utils.h +36 -0
- data/vendor/lexbor/source/lexbor/css/base.h +44 -0
- data/vendor/lexbor/source/lexbor/css/config.cmake +2 -0
- data/vendor/lexbor/source/lexbor/css/css.h +25 -0
- data/vendor/lexbor/source/lexbor/css/log.c +336 -0
- data/vendor/lexbor/source/lexbor/css/log.h +103 -0
- data/vendor/lexbor/source/lexbor/css/node.h +29 -0
- data/vendor/lexbor/source/lexbor/css/parser.c +473 -0
- data/vendor/lexbor/source/lexbor/css/parser.h +368 -0
- data/vendor/lexbor/source/lexbor/css/selectors/base.h +48 -0
- data/vendor/lexbor/source/lexbor/css/selectors/pseudo.c +91 -0
- data/vendor/lexbor/source/lexbor/css/selectors/pseudo.h +66 -0
- data/vendor/lexbor/source/lexbor/css/selectors/pseudo_const.h +109 -0
- data/vendor/lexbor/source/lexbor/css/selectors/pseudo_res.h +302 -0
- data/vendor/lexbor/source/lexbor/css/selectors/pseudo_state.c +279 -0
- data/vendor/lexbor/source/lexbor/css/selectors/pseudo_state.h +85 -0
- data/vendor/lexbor/source/lexbor/css/selectors/selector.c +927 -0
- data/vendor/lexbor/source/lexbor/css/selectors/selector.h +200 -0
- data/vendor/lexbor/source/lexbor/css/selectors/selectors.c +340 -0
- data/vendor/lexbor/source/lexbor/css/selectors/selectors.h +137 -0
- data/vendor/lexbor/source/lexbor/css/selectors/state.c +1718 -0
- data/vendor/lexbor/source/lexbor/css/selectors/state.h +79 -0
- data/vendor/lexbor/source/lexbor/css/stylesheet.h +37 -0
- data/vendor/lexbor/source/lexbor/css/syntax/anb.c +443 -0
- data/vendor/lexbor/source/lexbor/css/syntax/anb.h +45 -0
- data/vendor/lexbor/source/lexbor/css/syntax/base.h +33 -0
- data/vendor/lexbor/source/lexbor/css/syntax/parser.c +9 -0
- data/vendor/lexbor/source/lexbor/css/syntax/parser.h +25 -0
- data/vendor/lexbor/source/lexbor/css/syntax/res.h +48 -0
- data/vendor/lexbor/source/lexbor/css/syntax/state.c +2603 -0
- data/vendor/lexbor/source/lexbor/css/syntax/state.h +140 -0
- data/vendor/lexbor/source/lexbor/css/syntax/state_res.h +273 -0
- data/vendor/lexbor/source/lexbor/css/syntax/syntax.c +67 -0
- data/vendor/lexbor/source/lexbor/css/syntax/token.c +618 -0
- data/vendor/lexbor/source/lexbor/css/syntax/token.h +298 -0
- data/vendor/lexbor/source/lexbor/css/syntax/token_res.h +68 -0
- data/vendor/lexbor/source/lexbor/css/syntax/tokenizer/error.c +30 -0
- data/vendor/lexbor/source/lexbor/css/syntax/tokenizer/error.h +58 -0
- data/vendor/lexbor/source/lexbor/css/syntax/tokenizer.c +278 -0
- data/vendor/lexbor/source/lexbor/css/syntax/tokenizer.h +121 -0
- data/vendor/lexbor/source/lexbor/dom/base.h +32 -0
- data/vendor/lexbor/source/lexbor/dom/collection.c +97 -0
- data/vendor/lexbor/source/lexbor/dom/collection.h +112 -0
- data/vendor/lexbor/source/lexbor/dom/config.cmake +3 -0
- data/vendor/lexbor/source/lexbor/dom/dom.h +29 -0
- data/vendor/lexbor/source/lexbor/dom/exception.c +18 -0
- data/vendor/lexbor/source/lexbor/dom/exception.h +73 -0
- data/vendor/lexbor/source/lexbor/dom/interface.c +110 -0
- data/vendor/lexbor/source/lexbor/dom/interface.h +88 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/attr.c +445 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/attr.h +152 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/attr_const.h +62 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/attr_res.h +143 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/cdata_section.c +55 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/cdata_section.h +38 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/character_data.c +110 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/character_data.h +51 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/comment.c +64 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/comment.h +42 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/document.c +536 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/document.h +243 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/document_fragment.c +36 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/document_fragment.h +36 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/document_type.c +125 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/document_type.h +108 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/element.c +1411 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/element.h +319 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/event_target.c +32 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/event_target.h +34 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/node.c +661 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/node.h +192 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/processing_instruction.c +87 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/processing_instruction.h +66 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/shadow_root.c +36 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/shadow_root.h +44 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/text.c +63 -0
- data/vendor/lexbor/source/lexbor/dom/interfaces/text.h +42 -0
- data/vendor/lexbor/source/lexbor/encoding/base.h +218 -0
- data/vendor/lexbor/source/lexbor/encoding/big5.c +42839 -0
- data/vendor/lexbor/source/lexbor/encoding/config.cmake +12 -0
- data/vendor/lexbor/source/lexbor/encoding/const.h +65 -0
- data/vendor/lexbor/source/lexbor/encoding/decode.c +3193 -0
- data/vendor/lexbor/source/lexbor/encoding/decode.h +370 -0
- data/vendor/lexbor/source/lexbor/encoding/encode.c +1931 -0
- data/vendor/lexbor/source/lexbor/encoding/encode.h +377 -0
- data/vendor/lexbor/source/lexbor/encoding/encoding.c +252 -0
- data/vendor/lexbor/source/lexbor/encoding/encoding.h +475 -0
- data/vendor/lexbor/source/lexbor/encoding/euc_kr.c +53883 -0
- data/vendor/lexbor/source/lexbor/encoding/gb18030.c +47905 -0
- data/vendor/lexbor/source/lexbor/encoding/iso_2022_jp_katakana.c +159 -0
- data/vendor/lexbor/source/lexbor/encoding/jis0208.c +22477 -0
- data/vendor/lexbor/source/lexbor/encoding/jis0212.c +15787 -0
- data/vendor/lexbor/source/lexbor/encoding/multi.h +53 -0
- data/vendor/lexbor/source/lexbor/encoding/range.c +71 -0
- data/vendor/lexbor/source/lexbor/encoding/range.h +34 -0
- data/vendor/lexbor/source/lexbor/encoding/res.c +222 -0
- data/vendor/lexbor/source/lexbor/encoding/res.h +34 -0
- data/vendor/lexbor/source/lexbor/encoding/single.c +13748 -0
- data/vendor/lexbor/source/lexbor/encoding/single.h +116 -0
- data/vendor/lexbor/source/lexbor/html/base.h +44 -0
- data/vendor/lexbor/source/lexbor/html/config.cmake +3 -0
- data/vendor/lexbor/source/lexbor/html/encoding.c +574 -0
- data/vendor/lexbor/source/lexbor/html/encoding.h +106 -0
- data/vendor/lexbor/source/lexbor/html/html.h +107 -0
- data/vendor/lexbor/source/lexbor/html/interface.c +165 -0
- data/vendor/lexbor/source/lexbor/html/interface.h +186 -0
- data/vendor/lexbor/source/lexbor/html/interface_res.h +4449 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/anchor_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/anchor_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/area_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/area_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/audio_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/audio_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/base_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/base_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/body_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/body_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/br_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/br_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/button_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/button_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/canvas_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/canvas_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/d_list_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/d_list_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/data_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/data_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/data_list_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/data_list_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/details_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/details_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/dialog_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/dialog_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/directory_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/directory_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/div_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/div_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/document.c +444 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/document.h +256 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/element.c +64 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/element.h +54 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/embed_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/embed_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/field_set_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/field_set_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/font_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/font_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/form_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/form_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/frame_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/frame_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/frame_set_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/frame_set_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/head_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/head_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/heading_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/heading_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/hr_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/hr_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/html_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/html_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/iframe_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/iframe_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/image_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/image_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/input_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/input_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/label_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/label_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/legend_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/legend_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/li_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/li_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/link_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/link_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/map_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/map_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/marquee_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/marquee_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/media_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/media_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/menu_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/menu_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/meta_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/meta_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/meter_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/meter_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/mod_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/mod_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/o_list_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/o_list_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/object_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/object_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/opt_group_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/opt_group_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/option_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/option_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/output_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/output_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/paragraph_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/paragraph_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/param_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/param_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/picture_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/picture_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/pre_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/pre_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/progress_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/progress_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/quote_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/quote_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/script_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/script_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/select_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/select_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/slot_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/slot_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/source_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/source_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/span_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/span_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/style_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/style_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/table_caption_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/table_caption_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/table_cell_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/table_cell_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/table_col_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/table_col_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/table_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/table_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/table_row_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/table_row_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/table_section_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/table_section_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/template_element.c +46 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/template_element.h +38 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/text_area_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/text_area_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/time_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/time_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/title_element.c +133 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/title_element.h +42 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/track_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/track_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/u_list_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/u_list_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/unknown_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/unknown_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/video_element.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/video_element.h +34 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/window.c +36 -0
- data/vendor/lexbor/source/lexbor/html/interfaces/window.h +34 -0
- data/vendor/lexbor/source/lexbor/html/node.c +14 -0
- data/vendor/lexbor/source/lexbor/html/node.h +67 -0
- data/vendor/lexbor/source/lexbor/html/parser.c +469 -0
- data/vendor/lexbor/source/lexbor/html/parser.h +170 -0
- data/vendor/lexbor/source/lexbor/html/serialize.c +1510 -0
- data/vendor/lexbor/source/lexbor/html/serialize.h +93 -0
- data/vendor/lexbor/source/lexbor/html/tag.h +103 -0
- data/vendor/lexbor/source/lexbor/html/tag_res.h +2262 -0
- data/vendor/lexbor/source/lexbor/html/token.c +386 -0
- data/vendor/lexbor/source/lexbor/html/token.h +130 -0
- data/vendor/lexbor/source/lexbor/html/token_attr.c +44 -0
- data/vendor/lexbor/source/lexbor/html/token_attr.h +67 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer/error.c +28 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer/error.h +141 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer/res.h +4956 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer/state.c +2171 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer/state.h +225 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer/state_comment.c +489 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer/state_comment.h +27 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer/state_doctype.c +1654 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer/state_doctype.h +27 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer/state_rawtext.c +303 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer/state_rawtext.h +32 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer/state_rcdata.c +311 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer/state_rcdata.h +32 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer/state_script.c +1209 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer/state_script.h +32 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer.c +499 -0
- data/vendor/lexbor/source/lexbor/html/tokenizer.h +343 -0
- data/vendor/lexbor/source/lexbor/html/tree/active_formatting.c +241 -0
- data/vendor/lexbor/source/lexbor/html/tree/active_formatting.h +117 -0
- data/vendor/lexbor/source/lexbor/html/tree/error.c +26 -0
- data/vendor/lexbor/source/lexbor/html/tree/error.h +114 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_after_body.c +62 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_after_frameset.c +63 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_body.c +82 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_frameset.c +88 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/after_head.c +222 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/before_head.c +144 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/before_html.c +166 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/foreign_content.c +358 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_body.c +1974 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_caption.c +158 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_cell.c +187 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_column_group.c +194 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_frameset.c +149 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_head.c +374 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_head_noscript.c +121 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_row.c +211 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_select.c +341 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_select_in_table.c +115 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_table.c +451 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_table_body.c +208 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_table_text.c +127 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/in_template.c +189 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/initial.c +411 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode/text.c +61 -0
- data/vendor/lexbor/source/lexbor/html/tree/insertion_mode.h +135 -0
- data/vendor/lexbor/source/lexbor/html/tree/open_elements.c +251 -0
- data/vendor/lexbor/source/lexbor/html/tree/open_elements.h +105 -0
- data/vendor/lexbor/source/lexbor/html/tree/template_insertion.c +10 -0
- data/vendor/lexbor/source/lexbor/html/tree/template_insertion.h +100 -0
- data/vendor/lexbor/source/lexbor/html/tree.c +1726 -0
- data/vendor/lexbor/source/lexbor/html/tree.h +431 -0
- data/vendor/lexbor/source/lexbor/html/tree_res.h +111 -0
- data/vendor/lexbor/source/lexbor/ns/base.h +32 -0
- data/vendor/lexbor/source/lexbor/ns/config.cmake +2 -0
- data/vendor/lexbor/source/lexbor/ns/const.h +37 -0
- data/vendor/lexbor/source/lexbor/ns/ns.c +154 -0
- data/vendor/lexbor/source/lexbor/ns/ns.h +66 -0
- data/vendor/lexbor/source/lexbor/ns/res.h +97 -0
- data/vendor/lexbor/source/lexbor/ports/posix/config.cmake +11 -0
- data/vendor/lexbor/source/lexbor/ports/posix/lexbor/core/fs.c +236 -0
- data/vendor/lexbor/source/lexbor/ports/posix/lexbor/core/memory.c +33 -0
- data/vendor/lexbor/source/lexbor/ports/posix/lexbor/core/perf.c +158 -0
- data/vendor/lexbor/source/lexbor/ports/windows_nt/config.cmake +18 -0
- data/vendor/lexbor/source/lexbor/ports/windows_nt/lexbor/core/fs.c +239 -0
- data/vendor/lexbor/source/lexbor/ports/windows_nt/lexbor/core/memory.c +33 -0
- data/vendor/lexbor/source/lexbor/ports/windows_nt/lexbor/core/perf.c +81 -0
- data/vendor/lexbor/source/lexbor/selectors/base.h +30 -0
- data/vendor/lexbor/source/lexbor/selectors/config.cmake +2 -0
- data/vendor/lexbor/source/lexbor/selectors/selectors.c +1591 -0
- data/vendor/lexbor/source/lexbor/selectors/selectors.h +71 -0
- data/vendor/lexbor/source/lexbor/tag/base.h +32 -0
- data/vendor/lexbor/source/lexbor/tag/config.cmake +2 -0
- data/vendor/lexbor/source/lexbor/tag/const.h +225 -0
- data/vendor/lexbor/source/lexbor/tag/res.h +562 -0
- data/vendor/lexbor/source/lexbor/tag/tag.c +144 -0
- data/vendor/lexbor/source/lexbor/tag/tag.h +123 -0
- data/vendor/lexbor/source/lexbor/utils/base.h +32 -0
- data/vendor/lexbor/source/lexbor/utils/config.cmake +2 -0
- data/vendor/lexbor/source/lexbor/utils/http.c +534 -0
- data/vendor/lexbor/source/lexbor/utils/http.h +90 -0
- data/vendor/lexbor/source/lexbor/utils/utils.h +15 -0
- data/vendor/lexbor/source/lexbor/utils/warc.c +817 -0
- data/vendor/lexbor/source/lexbor/utils/warc.h +126 -0
- data/vendor/lexbor/utils/lexbor/css/selectors/pseudo.py +231 -0
- data/vendor/lexbor/utils/lexbor/css/selectors/tmp/const.h +21 -0
- data/vendor/lexbor/utils/lexbor/css/selectors/tmp/res.h +26 -0
- data/vendor/lexbor/utils/lexbor/css/syntax/definitions.py +49 -0
- data/vendor/lexbor/utils/lexbor/css/syntax/token_res.py +54 -0
- data/vendor/lexbor/utils/lexbor/css/syntax/tokenizer_code_map.py +36 -0
- data/vendor/lexbor/version +1 -0
- metadata +542 -0
|
@@ -0,0 +1,1510 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2018-2020 Alexander Borisov
|
|
3
|
+
*
|
|
4
|
+
* Author: Alexander Borisov <borisov@lexbor.com>
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#include "lexbor/dom/interfaces/text.h"
|
|
8
|
+
#include "lexbor/dom/interfaces/comment.h"
|
|
9
|
+
#include "lexbor/dom/interfaces/processing_instruction.h"
|
|
10
|
+
#include "lexbor/dom/interfaces/document_type.h"
|
|
11
|
+
|
|
12
|
+
#include "lexbor/html/serialize.h"
|
|
13
|
+
#include "lexbor/html/tree.h"
|
|
14
|
+
#include "lexbor/ns/ns.h"
|
|
15
|
+
#include "lexbor/html/interfaces/template_element.h"
|
|
16
|
+
|
|
17
|
+
#define LEXBOR_TOKENIZER_CHARS_MAP
|
|
18
|
+
#include "lexbor/core/str_res.h"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
#define lxb_html_serialize_send(data, len, ctx) \
|
|
22
|
+
do { \
|
|
23
|
+
status = cb((const lxb_char_t *) data, len, ctx); \
|
|
24
|
+
if (status != LXB_STATUS_OK) { \
|
|
25
|
+
return status; \
|
|
26
|
+
} \
|
|
27
|
+
} \
|
|
28
|
+
while (0)
|
|
29
|
+
|
|
30
|
+
#define lxb_html_serialize_send_indent(count, ctx) \
|
|
31
|
+
do { \
|
|
32
|
+
for (size_t i = 0; i < count; i++) { \
|
|
33
|
+
lxb_html_serialize_send(" ", 2, ctx); \
|
|
34
|
+
} \
|
|
35
|
+
} \
|
|
36
|
+
while (0)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
typedef struct {
|
|
40
|
+
lexbor_str_t *str;
|
|
41
|
+
lexbor_mraw_t *mraw;
|
|
42
|
+
}
|
|
43
|
+
lxb_html_serialize_ctx_t;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
static lxb_status_t
|
|
47
|
+
lxb_html_serialize_str_callback(const lxb_char_t *data, size_t len, void *ctx);
|
|
48
|
+
|
|
49
|
+
static lxb_status_t
|
|
50
|
+
lxb_html_serialize_node_cb(lxb_dom_node_t *node,
|
|
51
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
52
|
+
|
|
53
|
+
static lxb_status_t
|
|
54
|
+
lxb_html_serialize_element_cb(lxb_dom_element_t *element,
|
|
55
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
56
|
+
|
|
57
|
+
static lxb_status_t
|
|
58
|
+
lxb_html_serialize_element_closed_cb(lxb_dom_element_t *element,
|
|
59
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
60
|
+
|
|
61
|
+
static lxb_status_t
|
|
62
|
+
lxb_html_serialize_text_cb(lxb_dom_text_t *text,
|
|
63
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
64
|
+
|
|
65
|
+
static lxb_status_t
|
|
66
|
+
lxb_html_serialize_comment_cb(lxb_dom_comment_t *comment,
|
|
67
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
68
|
+
|
|
69
|
+
static lxb_status_t
|
|
70
|
+
lxb_html_serialize_processing_instruction_cb(lxb_dom_processing_instruction_t *pi,
|
|
71
|
+
lxb_html_serialize_cb_f cb,
|
|
72
|
+
void *ctx);
|
|
73
|
+
|
|
74
|
+
static lxb_status_t
|
|
75
|
+
lxb_html_serialize_document_type_cb(lxb_dom_document_type_t *doctype,
|
|
76
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
77
|
+
|
|
78
|
+
static lxb_status_t
|
|
79
|
+
lxb_html_serialize_document_type_full_cb(lxb_dom_document_type_t *doctype,
|
|
80
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
81
|
+
|
|
82
|
+
static lxb_status_t
|
|
83
|
+
lxb_html_serialize_document_cb(lxb_dom_document_t *document,
|
|
84
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
85
|
+
|
|
86
|
+
static lxb_status_t
|
|
87
|
+
lxb_html_serialize_send_escaping_attribute_string(const lxb_char_t *data,
|
|
88
|
+
size_t len,
|
|
89
|
+
lxb_html_serialize_cb_f cb,
|
|
90
|
+
void *ctx);
|
|
91
|
+
|
|
92
|
+
static lxb_status_t
|
|
93
|
+
lxb_html_serialize_send_escaping_string(const lxb_char_t *data, size_t len,
|
|
94
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
95
|
+
|
|
96
|
+
static lxb_status_t
|
|
97
|
+
lxb_html_serialize_attribute_cb(lxb_dom_attr_t *attr, bool has_raw,
|
|
98
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
99
|
+
|
|
100
|
+
static lxb_status_t
|
|
101
|
+
lxb_html_serialize_pretty_node_cb(lxb_dom_node_t *node,
|
|
102
|
+
lxb_html_serialize_opt_t opt, size_t deep,
|
|
103
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
104
|
+
|
|
105
|
+
static lxb_status_t
|
|
106
|
+
lxb_html_serialize_pretty_element_cb(lxb_dom_element_t *element,
|
|
107
|
+
lxb_html_serialize_opt_t opt, size_t indent,
|
|
108
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
109
|
+
|
|
110
|
+
static lxb_status_t
|
|
111
|
+
lxb_html_serialize_pretty_text_cb(lxb_dom_text_t *text,
|
|
112
|
+
lxb_html_serialize_opt_t opt, size_t indent,
|
|
113
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
114
|
+
|
|
115
|
+
static lxb_status_t
|
|
116
|
+
lxb_html_serialize_pretty_comment_cb(lxb_dom_comment_t *comment,
|
|
117
|
+
size_t indent, bool with_indent,
|
|
118
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
119
|
+
|
|
120
|
+
static lxb_status_t
|
|
121
|
+
lxb_html_serialize_pretty_document_cb(lxb_dom_document_t *document,
|
|
122
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
123
|
+
|
|
124
|
+
static lxb_status_t
|
|
125
|
+
lxb_html_serialize_pretty_send_escaping_string(const lxb_char_t *data, size_t len,
|
|
126
|
+
size_t indent, bool with_indent,
|
|
127
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
128
|
+
|
|
129
|
+
static lxb_status_t
|
|
130
|
+
lxb_html_serialize_pretty_send_string(const lxb_char_t *data, size_t len,
|
|
131
|
+
size_t indent, bool with_indent,
|
|
132
|
+
lxb_html_serialize_cb_f cb, void *ctx);
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
lxb_status_t
|
|
136
|
+
lxb_html_serialize_cb(lxb_dom_node_t *node,
|
|
137
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
138
|
+
{
|
|
139
|
+
switch (node->type) {
|
|
140
|
+
case LXB_DOM_NODE_TYPE_ELEMENT:
|
|
141
|
+
return lxb_html_serialize_element_cb(lxb_dom_interface_element(node),
|
|
142
|
+
cb, ctx);
|
|
143
|
+
|
|
144
|
+
case LXB_DOM_NODE_TYPE_TEXT:
|
|
145
|
+
return lxb_html_serialize_text_cb(lxb_dom_interface_text(node),
|
|
146
|
+
cb, ctx);
|
|
147
|
+
|
|
148
|
+
case LXB_DOM_NODE_TYPE_COMMENT:
|
|
149
|
+
return lxb_html_serialize_comment_cb(lxb_dom_interface_comment(node),
|
|
150
|
+
cb, ctx);
|
|
151
|
+
|
|
152
|
+
case LXB_DOM_NODE_TYPE_PROCESSING_INSTRUCTION:
|
|
153
|
+
return lxb_html_serialize_processing_instruction_cb(lxb_dom_interface_processing_instruction(node),
|
|
154
|
+
cb, ctx);
|
|
155
|
+
|
|
156
|
+
case LXB_DOM_NODE_TYPE_DOCUMENT_TYPE:
|
|
157
|
+
return lxb_html_serialize_document_type_cb(lxb_dom_interface_document_type(node),
|
|
158
|
+
cb, ctx);
|
|
159
|
+
|
|
160
|
+
case LXB_DOM_NODE_TYPE_DOCUMENT:
|
|
161
|
+
return lxb_html_serialize_document_cb(lxb_dom_interface_document(node),
|
|
162
|
+
cb, ctx);
|
|
163
|
+
|
|
164
|
+
default:
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return LXB_STATUS_ERROR;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
lxb_status_t
|
|
172
|
+
lxb_html_serialize_str(lxb_dom_node_t *node, lexbor_str_t *str)
|
|
173
|
+
{
|
|
174
|
+
lxb_html_serialize_ctx_t ctx;
|
|
175
|
+
|
|
176
|
+
if (str->data == NULL) {
|
|
177
|
+
lexbor_str_init(str, node->owner_document->text, 1024);
|
|
178
|
+
|
|
179
|
+
if (str->data == NULL) {
|
|
180
|
+
return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
ctx.str = str;
|
|
185
|
+
ctx.mraw = node->owner_document->text;
|
|
186
|
+
|
|
187
|
+
return lxb_html_serialize_cb(node, lxb_html_serialize_str_callback, &ctx);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
static lxb_status_t
|
|
191
|
+
lxb_html_serialize_str_callback(const lxb_char_t *data, size_t len, void *ctx)
|
|
192
|
+
{
|
|
193
|
+
lxb_char_t *ret;
|
|
194
|
+
lxb_html_serialize_ctx_t *s_ctx = ctx;
|
|
195
|
+
|
|
196
|
+
ret = lexbor_str_append(s_ctx->str, s_ctx->mraw, data, len);
|
|
197
|
+
if (ret == NULL) {
|
|
198
|
+
return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return LXB_STATUS_OK;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
lxb_status_t
|
|
205
|
+
lxb_html_serialize_deep_cb(lxb_dom_node_t *node,
|
|
206
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
207
|
+
{
|
|
208
|
+
lxb_status_t status;
|
|
209
|
+
|
|
210
|
+
node = node->first_child;
|
|
211
|
+
|
|
212
|
+
while (node != NULL) {
|
|
213
|
+
status = lxb_html_serialize_node_cb(node, cb, ctx);
|
|
214
|
+
if (status != LXB_STATUS_OK) {
|
|
215
|
+
return status;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
node = node->next;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return LXB_STATUS_OK;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
lxb_status_t
|
|
225
|
+
lxb_html_serialize_deep_str(lxb_dom_node_t *node, lexbor_str_t *str)
|
|
226
|
+
{
|
|
227
|
+
lxb_html_serialize_ctx_t ctx;
|
|
228
|
+
|
|
229
|
+
if (str->data == NULL) {
|
|
230
|
+
lexbor_str_init(str, node->owner_document->text, 1024);
|
|
231
|
+
|
|
232
|
+
if (str->data == NULL) {
|
|
233
|
+
return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
ctx.str = str;
|
|
238
|
+
ctx.mraw = node->owner_document->text;
|
|
239
|
+
|
|
240
|
+
return lxb_html_serialize_deep_cb(node,
|
|
241
|
+
lxb_html_serialize_str_callback, &ctx);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
static lxb_status_t
|
|
245
|
+
lxb_html_serialize_node_cb(lxb_dom_node_t *node,
|
|
246
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
247
|
+
{
|
|
248
|
+
bool skip_it;
|
|
249
|
+
lxb_status_t status;
|
|
250
|
+
lxb_dom_node_t *root = node;
|
|
251
|
+
|
|
252
|
+
while (node != NULL) {
|
|
253
|
+
status = lxb_html_serialize_cb(node, cb, ctx);
|
|
254
|
+
if (status != LXB_STATUS_OK) {
|
|
255
|
+
return status;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (node->local_name == LXB_TAG_TEMPLATE) {
|
|
259
|
+
lxb_html_template_element_t *temp;
|
|
260
|
+
|
|
261
|
+
temp = lxb_html_interface_template(node);
|
|
262
|
+
|
|
263
|
+
if (temp->content != NULL) {
|
|
264
|
+
if (temp->content->node.first_child != NULL)
|
|
265
|
+
{
|
|
266
|
+
status = lxb_html_serialize_deep_cb(&temp->content->node,
|
|
267
|
+
cb, ctx);
|
|
268
|
+
if (status != LXB_STATUS_OK) {
|
|
269
|
+
return status;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
skip_it = lxb_html_node_is_void(node);
|
|
276
|
+
|
|
277
|
+
if (skip_it == false && node->first_child != NULL) {
|
|
278
|
+
node = node->first_child;
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
while(node != root && node->next == NULL)
|
|
282
|
+
{
|
|
283
|
+
if (node->type == LXB_DOM_NODE_TYPE_ELEMENT
|
|
284
|
+
&& lxb_html_node_is_void(node) == false)
|
|
285
|
+
{
|
|
286
|
+
status = lxb_html_serialize_element_closed_cb(lxb_dom_interface_element(node),
|
|
287
|
+
cb, ctx);
|
|
288
|
+
if (status != LXB_STATUS_OK) {
|
|
289
|
+
return status;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
node = node->parent;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (node->type == LXB_DOM_NODE_TYPE_ELEMENT
|
|
297
|
+
&& lxb_html_node_is_void(node) == false)
|
|
298
|
+
{
|
|
299
|
+
status = lxb_html_serialize_element_closed_cb(lxb_dom_interface_element(node),
|
|
300
|
+
cb, ctx);
|
|
301
|
+
if (status != LXB_STATUS_OK) {
|
|
302
|
+
return status;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (node == root) {
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
node = node->next;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return LXB_STATUS_OK;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
static lxb_status_t
|
|
318
|
+
lxb_html_serialize_element_cb(lxb_dom_element_t *element,
|
|
319
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
320
|
+
{
|
|
321
|
+
lxb_status_t status;
|
|
322
|
+
const lxb_char_t *tag_name;
|
|
323
|
+
size_t len = 0;
|
|
324
|
+
|
|
325
|
+
lxb_dom_attr_t *attr;
|
|
326
|
+
|
|
327
|
+
tag_name = lxb_dom_element_qualified_name(element, &len);
|
|
328
|
+
if (tag_name == NULL) {
|
|
329
|
+
return LXB_STATUS_ERROR;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
lxb_html_serialize_send("<", 1, ctx);
|
|
333
|
+
lxb_html_serialize_send(tag_name, len, ctx);
|
|
334
|
+
|
|
335
|
+
if (element->is_value != NULL && element->is_value->data != NULL) {
|
|
336
|
+
attr = lxb_dom_element_attr_is_exist(element,
|
|
337
|
+
(const lxb_char_t *) "is", 2);
|
|
338
|
+
if (attr == NULL) {
|
|
339
|
+
lxb_html_serialize_send(" is=\"", 5, ctx);
|
|
340
|
+
|
|
341
|
+
status = lxb_html_serialize_send_escaping_attribute_string(element->is_value->data,
|
|
342
|
+
element->is_value->length,
|
|
343
|
+
cb, ctx);
|
|
344
|
+
if (status != LXB_STATUS_OK) {
|
|
345
|
+
return status;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
lxb_html_serialize_send("\"", 1, ctx);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
attr = element->first_attr;
|
|
353
|
+
|
|
354
|
+
while (attr != NULL) {
|
|
355
|
+
lxb_html_serialize_send(" ", 1, ctx);
|
|
356
|
+
|
|
357
|
+
status = lxb_html_serialize_attribute_cb(attr, false, cb, ctx);
|
|
358
|
+
if (status != LXB_STATUS_OK) {
|
|
359
|
+
return status;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
attr = attr->next;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
lxb_html_serialize_send(">", 1, ctx);
|
|
366
|
+
|
|
367
|
+
return LXB_STATUS_OK;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
static lxb_status_t
|
|
371
|
+
lxb_html_serialize_element_closed_cb(lxb_dom_element_t *element,
|
|
372
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
373
|
+
{
|
|
374
|
+
lxb_status_t status;
|
|
375
|
+
const lxb_char_t *tag_name;
|
|
376
|
+
size_t len = 0;
|
|
377
|
+
|
|
378
|
+
tag_name = lxb_dom_element_qualified_name(element, &len);
|
|
379
|
+
if (tag_name == NULL) {
|
|
380
|
+
return LXB_STATUS_ERROR;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
lxb_html_serialize_send("</", 2, ctx);
|
|
384
|
+
lxb_html_serialize_send(tag_name, len, ctx);
|
|
385
|
+
lxb_html_serialize_send(">", 1, ctx);
|
|
386
|
+
|
|
387
|
+
return LXB_STATUS_OK;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
static lxb_status_t
|
|
391
|
+
lxb_html_serialize_text_cb(lxb_dom_text_t *text,
|
|
392
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
393
|
+
{
|
|
394
|
+
lxb_status_t status;
|
|
395
|
+
|
|
396
|
+
lxb_dom_node_t *node = lxb_dom_interface_node(text);
|
|
397
|
+
lxb_dom_document_t *doc = node->owner_document;
|
|
398
|
+
lexbor_str_t *data = &text->char_data.data;
|
|
399
|
+
|
|
400
|
+
if (node->parent != NULL) {
|
|
401
|
+
switch (node->parent->local_name) {
|
|
402
|
+
case LXB_TAG_STYLE:
|
|
403
|
+
case LXB_TAG_SCRIPT:
|
|
404
|
+
case LXB_TAG_XMP:
|
|
405
|
+
case LXB_TAG_IFRAME:
|
|
406
|
+
case LXB_TAG_NOEMBED:
|
|
407
|
+
case LXB_TAG_NOFRAMES:
|
|
408
|
+
case LXB_TAG_PLAINTEXT:
|
|
409
|
+
lxb_html_serialize_send(data->data, data->length, ctx);
|
|
410
|
+
|
|
411
|
+
return LXB_STATUS_OK;
|
|
412
|
+
|
|
413
|
+
case LXB_TAG_NOSCRIPT:
|
|
414
|
+
if (doc->scripting) {
|
|
415
|
+
lxb_html_serialize_send(data->data, data->length, ctx);
|
|
416
|
+
|
|
417
|
+
return LXB_STATUS_OK;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
break;
|
|
421
|
+
|
|
422
|
+
default:
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return lxb_html_serialize_send_escaping_string(data->data, data->length,
|
|
428
|
+
cb, ctx);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
static lxb_status_t
|
|
432
|
+
lxb_html_serialize_comment_cb(lxb_dom_comment_t *comment,
|
|
433
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
434
|
+
{
|
|
435
|
+
lxb_status_t status;
|
|
436
|
+
lexbor_str_t *data = &comment->char_data.data;
|
|
437
|
+
|
|
438
|
+
lxb_html_serialize_send("<!--", 4, ctx);
|
|
439
|
+
lxb_html_serialize_send(data->data, data->length, ctx);
|
|
440
|
+
lxb_html_serialize_send("-->", 3, ctx);
|
|
441
|
+
|
|
442
|
+
return LXB_STATUS_OK;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
static lxb_status_t
|
|
446
|
+
lxb_html_serialize_processing_instruction_cb(lxb_dom_processing_instruction_t *pi,
|
|
447
|
+
lxb_html_serialize_cb_f cb,
|
|
448
|
+
void *ctx)
|
|
449
|
+
{
|
|
450
|
+
lxb_status_t status;
|
|
451
|
+
lexbor_str_t *data = &pi->char_data.data;
|
|
452
|
+
|
|
453
|
+
lxb_html_serialize_send("<?", 2, ctx);
|
|
454
|
+
lxb_html_serialize_send(pi->target.data, pi->target.length, ctx);
|
|
455
|
+
lxb_html_serialize_send(" ", 1, ctx);
|
|
456
|
+
lxb_html_serialize_send(data->data, data->length, ctx);
|
|
457
|
+
lxb_html_serialize_send(">", 1, ctx);
|
|
458
|
+
|
|
459
|
+
return LXB_STATUS_OK;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
static lxb_status_t
|
|
463
|
+
lxb_html_serialize_document_type_cb(lxb_dom_document_type_t *doctype,
|
|
464
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
465
|
+
{
|
|
466
|
+
size_t length;
|
|
467
|
+
const lxb_char_t *name;
|
|
468
|
+
lxb_status_t status;
|
|
469
|
+
|
|
470
|
+
lxb_html_serialize_send("<!DOCTYPE", 9, ctx);
|
|
471
|
+
lxb_html_serialize_send(" ", 1, ctx);
|
|
472
|
+
|
|
473
|
+
name = lxb_dom_document_type_name(doctype, &length);
|
|
474
|
+
|
|
475
|
+
if (length != 0) {
|
|
476
|
+
lxb_html_serialize_send(name, length, ctx);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
lxb_html_serialize_send(">", 1, ctx);
|
|
480
|
+
|
|
481
|
+
return LXB_STATUS_OK;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
static lxb_status_t
|
|
485
|
+
lxb_html_serialize_document_type_full_cb(lxb_dom_document_type_t *doctype,
|
|
486
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
487
|
+
{
|
|
488
|
+
size_t length;
|
|
489
|
+
const lxb_char_t *name;
|
|
490
|
+
lxb_status_t status;
|
|
491
|
+
|
|
492
|
+
lxb_html_serialize_send("<!DOCTYPE", 9, ctx);
|
|
493
|
+
lxb_html_serialize_send(" ", 1, ctx);
|
|
494
|
+
|
|
495
|
+
name = lxb_dom_document_type_name(doctype, &length);
|
|
496
|
+
|
|
497
|
+
if (length != 0) {
|
|
498
|
+
lxb_html_serialize_send(name, length, ctx);
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (doctype->public_id.data != NULL && doctype->public_id.length != 0) {
|
|
502
|
+
lxb_html_serialize_send(" PUBLIC ", 8, ctx);
|
|
503
|
+
lxb_html_serialize_send("\"", 1, ctx);
|
|
504
|
+
|
|
505
|
+
lxb_html_serialize_send(doctype->public_id.data,
|
|
506
|
+
doctype->public_id.length, ctx);
|
|
507
|
+
|
|
508
|
+
lxb_html_serialize_send("\"", 1, ctx);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (doctype->system_id.data != NULL && doctype->system_id.length != 0) {
|
|
512
|
+
if (doctype->public_id.length == 0) {
|
|
513
|
+
lxb_html_serialize_send(" SYSTEM", 7, ctx);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
lxb_html_serialize_send(" \"", 2, ctx);
|
|
517
|
+
|
|
518
|
+
lxb_html_serialize_send(doctype->system_id.data,
|
|
519
|
+
doctype->system_id.length, ctx);
|
|
520
|
+
|
|
521
|
+
lxb_html_serialize_send("\"", 1, ctx);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
lxb_html_serialize_send(">", 1, ctx);
|
|
525
|
+
|
|
526
|
+
return LXB_STATUS_OK;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
static lxb_status_t
|
|
530
|
+
lxb_html_serialize_document_cb(lxb_dom_document_t *document,
|
|
531
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
532
|
+
{
|
|
533
|
+
lxb_status_t status;
|
|
534
|
+
|
|
535
|
+
lxb_html_serialize_send("<#document>", 11, ctx);
|
|
536
|
+
|
|
537
|
+
return LXB_STATUS_OK;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
static lxb_status_t
|
|
541
|
+
lxb_html_serialize_send_escaping_attribute_string(const lxb_char_t *data,
|
|
542
|
+
size_t len,
|
|
543
|
+
lxb_html_serialize_cb_f cb,
|
|
544
|
+
void *ctx)
|
|
545
|
+
{
|
|
546
|
+
lxb_status_t status;
|
|
547
|
+
const lxb_char_t *pos = data;
|
|
548
|
+
const lxb_char_t *end = data + len;
|
|
549
|
+
|
|
550
|
+
while (data != end) {
|
|
551
|
+
switch (*data) {
|
|
552
|
+
/* U+0026 AMPERSAND (&) */
|
|
553
|
+
case 0x26:
|
|
554
|
+
if (pos != data) {
|
|
555
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
lxb_html_serialize_send("&", 5, ctx);
|
|
559
|
+
|
|
560
|
+
data++;
|
|
561
|
+
pos = data;
|
|
562
|
+
|
|
563
|
+
break;
|
|
564
|
+
|
|
565
|
+
/* {0xC2, 0xA0} NO-BREAK SPACE */
|
|
566
|
+
case 0xC2:
|
|
567
|
+
data += 1;
|
|
568
|
+
if (data == end) {
|
|
569
|
+
break;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
if (*data != 0xA0) {
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
data -= 1;
|
|
577
|
+
|
|
578
|
+
if (pos != data) {
|
|
579
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
lxb_html_serialize_send(" ", 6, ctx);
|
|
583
|
+
|
|
584
|
+
data += 2;
|
|
585
|
+
pos = data;
|
|
586
|
+
|
|
587
|
+
break;
|
|
588
|
+
|
|
589
|
+
/* U+0022 QUOTATION MARK (") */
|
|
590
|
+
case 0x22:
|
|
591
|
+
if (pos != data) {
|
|
592
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
lxb_html_serialize_send(""", 6, ctx);
|
|
596
|
+
|
|
597
|
+
data++;
|
|
598
|
+
pos = data;
|
|
599
|
+
|
|
600
|
+
break;
|
|
601
|
+
|
|
602
|
+
default:
|
|
603
|
+
data++;
|
|
604
|
+
|
|
605
|
+
break;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
if (pos != data) {
|
|
610
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
return LXB_STATUS_OK;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
static lxb_status_t
|
|
617
|
+
lxb_html_serialize_send_escaping_string(const lxb_char_t *data, size_t len,
|
|
618
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
619
|
+
{
|
|
620
|
+
lxb_status_t status;
|
|
621
|
+
const lxb_char_t *pos = data;
|
|
622
|
+
const lxb_char_t *end = data + len;
|
|
623
|
+
|
|
624
|
+
while (data != end) {
|
|
625
|
+
switch (*data) {
|
|
626
|
+
/* U+0026 AMPERSAND (&) */
|
|
627
|
+
case 0x26:
|
|
628
|
+
if (pos != data) {
|
|
629
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
lxb_html_serialize_send("&", 5, ctx);
|
|
633
|
+
|
|
634
|
+
data++;
|
|
635
|
+
pos = data;
|
|
636
|
+
|
|
637
|
+
break;
|
|
638
|
+
|
|
639
|
+
/* {0xC2, 0xA0} NO-BREAK SPACE */
|
|
640
|
+
case 0xC2:
|
|
641
|
+
data += 1;
|
|
642
|
+
if (data == end) {
|
|
643
|
+
break;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
if (*data != 0xA0) {
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
data -= 1;
|
|
651
|
+
|
|
652
|
+
if (pos != data) {
|
|
653
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
lxb_html_serialize_send(" ", 6, ctx);
|
|
657
|
+
|
|
658
|
+
data += 2;
|
|
659
|
+
pos = data;
|
|
660
|
+
|
|
661
|
+
break;
|
|
662
|
+
|
|
663
|
+
/* U+003C LESS-THAN SIGN (<) */
|
|
664
|
+
case 0x3C:
|
|
665
|
+
if (pos != data) {
|
|
666
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
lxb_html_serialize_send("<", 4, ctx);
|
|
670
|
+
|
|
671
|
+
data++;
|
|
672
|
+
pos = data;
|
|
673
|
+
|
|
674
|
+
break;
|
|
675
|
+
|
|
676
|
+
/* U+003E GREATER-THAN SIGN (>) */
|
|
677
|
+
case 0x3E:
|
|
678
|
+
if (pos != data) {
|
|
679
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
lxb_html_serialize_send(">", 4, ctx);
|
|
683
|
+
|
|
684
|
+
data++;
|
|
685
|
+
pos = data;
|
|
686
|
+
|
|
687
|
+
break;
|
|
688
|
+
|
|
689
|
+
default:
|
|
690
|
+
data++;
|
|
691
|
+
|
|
692
|
+
break;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
if (pos != data) {
|
|
697
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
return LXB_STATUS_OK;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
static lxb_status_t
|
|
704
|
+
lxb_html_serialize_attribute_cb(lxb_dom_attr_t *attr, bool has_raw,
|
|
705
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
706
|
+
{
|
|
707
|
+
size_t length;
|
|
708
|
+
lxb_status_t status;
|
|
709
|
+
const lxb_char_t *str;
|
|
710
|
+
const lxb_dom_attr_data_t *data;
|
|
711
|
+
|
|
712
|
+
data = lxb_dom_attr_data_by_id(attr->node.owner_document->attrs,
|
|
713
|
+
attr->node.local_name);
|
|
714
|
+
if (data == NULL) {
|
|
715
|
+
return LXB_STATUS_ERROR;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
if (attr->node.ns == LXB_NS__UNDEF) {
|
|
719
|
+
lxb_html_serialize_send(lexbor_hash_entry_str(&data->entry),
|
|
720
|
+
data->entry.length, ctx);
|
|
721
|
+
goto value;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
if (attr->node.ns == LXB_NS_XML) {
|
|
725
|
+
lxb_html_serialize_send((const lxb_char_t *) "xml:", 4, ctx);
|
|
726
|
+
lxb_html_serialize_send(lexbor_hash_entry_str(&data->entry),
|
|
727
|
+
data->entry.length, ctx);
|
|
728
|
+
|
|
729
|
+
goto value;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
if (attr->node.ns == LXB_NS_XMLNS)
|
|
733
|
+
{
|
|
734
|
+
if (data->entry.length == 5
|
|
735
|
+
&& lexbor_str_data_cmp(lexbor_hash_entry_str(&data->entry),
|
|
736
|
+
(const lxb_char_t *) "xmlns"))
|
|
737
|
+
{
|
|
738
|
+
lxb_html_serialize_send((const lxb_char_t *) "xmlns", 5, ctx);
|
|
739
|
+
}
|
|
740
|
+
else {
|
|
741
|
+
lxb_html_serialize_send((const lxb_char_t *) "xmlns:", 5, ctx);
|
|
742
|
+
lxb_html_serialize_send(lexbor_hash_entry_str(&data->entry),
|
|
743
|
+
data->entry.length, ctx);
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
goto value;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
if (attr->node.ns == LXB_NS_XLINK) {
|
|
750
|
+
lxb_html_serialize_send((const lxb_char_t *) "xlink:", 6, ctx);
|
|
751
|
+
lxb_html_serialize_send(lexbor_hash_entry_str(&data->entry),
|
|
752
|
+
data->entry.length, ctx);
|
|
753
|
+
|
|
754
|
+
goto value;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
str = lxb_dom_attr_qualified_name(attr, &length);
|
|
758
|
+
if (str == NULL) {
|
|
759
|
+
return LXB_STATUS_ERROR;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
lxb_html_serialize_send(str, length, ctx);
|
|
763
|
+
|
|
764
|
+
value:
|
|
765
|
+
|
|
766
|
+
if (attr->value == NULL) {
|
|
767
|
+
return LXB_STATUS_OK;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
lxb_html_serialize_send("=\"", 2, ctx);
|
|
771
|
+
|
|
772
|
+
if (has_raw) {
|
|
773
|
+
lxb_html_serialize_send(attr->value->data, attr->value->length, ctx);
|
|
774
|
+
}
|
|
775
|
+
else {
|
|
776
|
+
status = lxb_html_serialize_send_escaping_attribute_string(attr->value->data,
|
|
777
|
+
attr->value->length,
|
|
778
|
+
cb, ctx);
|
|
779
|
+
if (status != LXB_STATUS_OK) {
|
|
780
|
+
return status;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
lxb_html_serialize_send("\"", 1, ctx);
|
|
785
|
+
|
|
786
|
+
return LXB_STATUS_OK;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
lxb_status_t
|
|
790
|
+
lxb_html_serialize_pretty_cb(lxb_dom_node_t *node,
|
|
791
|
+
lxb_html_serialize_opt_t opt, size_t indent,
|
|
792
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
793
|
+
{
|
|
794
|
+
lxb_status_t status;
|
|
795
|
+
|
|
796
|
+
switch (node->type) {
|
|
797
|
+
case LXB_DOM_NODE_TYPE_ELEMENT:
|
|
798
|
+
lxb_html_serialize_send_indent(indent, ctx);
|
|
799
|
+
|
|
800
|
+
status = lxb_html_serialize_pretty_element_cb(lxb_dom_interface_element(node),
|
|
801
|
+
opt, indent, cb, ctx);
|
|
802
|
+
|
|
803
|
+
break;
|
|
804
|
+
|
|
805
|
+
case LXB_DOM_NODE_TYPE_TEXT:
|
|
806
|
+
return lxb_html_serialize_pretty_text_cb(lxb_dom_interface_text(node),
|
|
807
|
+
opt, indent, cb, ctx);
|
|
808
|
+
|
|
809
|
+
case LXB_DOM_NODE_TYPE_COMMENT: {
|
|
810
|
+
bool with_indent;
|
|
811
|
+
|
|
812
|
+
if (opt & LXB_HTML_SERIALIZE_OPT_SKIP_COMMENT) {
|
|
813
|
+
return LXB_STATUS_OK;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
with_indent = (opt & LXB_HTML_SERIALIZE_OPT_WITHOUT_TEXT_INDENT) == 0;
|
|
817
|
+
|
|
818
|
+
status = lxb_html_serialize_pretty_comment_cb(lxb_dom_interface_comment(node),
|
|
819
|
+
indent, with_indent, cb, ctx);
|
|
820
|
+
|
|
821
|
+
break;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
case LXB_DOM_NODE_TYPE_PROCESSING_INSTRUCTION:
|
|
825
|
+
lxb_html_serialize_send_indent(indent, ctx);
|
|
826
|
+
|
|
827
|
+
status = lxb_html_serialize_processing_instruction_cb(lxb_dom_interface_processing_instruction(node),
|
|
828
|
+
cb, ctx);
|
|
829
|
+
|
|
830
|
+
break;
|
|
831
|
+
|
|
832
|
+
case LXB_DOM_NODE_TYPE_DOCUMENT_TYPE:
|
|
833
|
+
lxb_html_serialize_send_indent(indent, ctx);
|
|
834
|
+
|
|
835
|
+
if (opt & LXB_HTML_SERIALIZE_OPT_FULL_DOCTYPE) {
|
|
836
|
+
status = lxb_html_serialize_document_type_full_cb(lxb_dom_interface_document_type(node),
|
|
837
|
+
cb, ctx);
|
|
838
|
+
}
|
|
839
|
+
else {
|
|
840
|
+
status = lxb_html_serialize_document_type_cb(lxb_dom_interface_document_type(node),
|
|
841
|
+
cb, ctx);
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
break;
|
|
845
|
+
|
|
846
|
+
case LXB_DOM_NODE_TYPE_DOCUMENT:
|
|
847
|
+
lxb_html_serialize_send_indent(indent, ctx);
|
|
848
|
+
|
|
849
|
+
status = lxb_html_serialize_pretty_document_cb(lxb_dom_interface_document(node),
|
|
850
|
+
cb, ctx);
|
|
851
|
+
|
|
852
|
+
break;
|
|
853
|
+
|
|
854
|
+
default:
|
|
855
|
+
return LXB_STATUS_ERROR;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
if (status != LXB_STATUS_OK) {
|
|
859
|
+
return status;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
lxb_html_serialize_send("\n", 1, ctx);
|
|
863
|
+
|
|
864
|
+
return LXB_STATUS_OK;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
lxb_status_t
|
|
868
|
+
lxb_html_serialize_pretty_str(lxb_dom_node_t *node,
|
|
869
|
+
lxb_html_serialize_opt_t opt, size_t indent,
|
|
870
|
+
lexbor_str_t *str)
|
|
871
|
+
{
|
|
872
|
+
lxb_html_serialize_ctx_t ctx;
|
|
873
|
+
|
|
874
|
+
if (str->data == NULL) {
|
|
875
|
+
lexbor_str_init(str, node->owner_document->text, 1024);
|
|
876
|
+
|
|
877
|
+
if (str->data == NULL) {
|
|
878
|
+
return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
ctx.str = str;
|
|
883
|
+
ctx.mraw = node->owner_document->text;
|
|
884
|
+
|
|
885
|
+
return lxb_html_serialize_pretty_cb(node, opt, indent,
|
|
886
|
+
lxb_html_serialize_str_callback, &ctx);
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
lxb_status_t
|
|
890
|
+
lxb_html_serialize_pretty_deep_cb(lxb_dom_node_t *node,
|
|
891
|
+
lxb_html_serialize_opt_t opt, size_t indent,
|
|
892
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
893
|
+
{
|
|
894
|
+
lxb_status_t status;
|
|
895
|
+
|
|
896
|
+
node = node->first_child;
|
|
897
|
+
|
|
898
|
+
while (node != NULL) {
|
|
899
|
+
status = lxb_html_serialize_pretty_node_cb(node, opt, indent, cb, ctx);
|
|
900
|
+
if (status != LXB_STATUS_OK) {
|
|
901
|
+
return status;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
node = node->next;
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
return LXB_STATUS_OK;
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
lxb_status_t
|
|
911
|
+
lxb_html_serialize_pretty_deep_str(lxb_dom_node_t *node,
|
|
912
|
+
lxb_html_serialize_opt_t opt, size_t indent,
|
|
913
|
+
lexbor_str_t *str)
|
|
914
|
+
{
|
|
915
|
+
lxb_html_serialize_ctx_t ctx;
|
|
916
|
+
|
|
917
|
+
if (str->data == NULL) {
|
|
918
|
+
lexbor_str_init(str, node->owner_document->text, 1024);
|
|
919
|
+
|
|
920
|
+
if (str->data == NULL) {
|
|
921
|
+
return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
ctx.str = str;
|
|
926
|
+
ctx.mraw = node->owner_document->text;
|
|
927
|
+
|
|
928
|
+
return lxb_html_serialize_pretty_deep_cb(node, opt, indent,
|
|
929
|
+
lxb_html_serialize_str_callback,
|
|
930
|
+
&ctx);
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
static lxb_status_t
|
|
934
|
+
lxb_html_serialize_pretty_node_cb(lxb_dom_node_t *node,
|
|
935
|
+
lxb_html_serialize_opt_t opt, size_t deep,
|
|
936
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
937
|
+
{
|
|
938
|
+
bool skip_it;
|
|
939
|
+
lxb_status_t status;
|
|
940
|
+
lxb_dom_node_t *root = node;
|
|
941
|
+
|
|
942
|
+
while (node != NULL) {
|
|
943
|
+
status = lxb_html_serialize_pretty_cb(node, opt, deep, cb, ctx);
|
|
944
|
+
if (status != LXB_STATUS_OK) {
|
|
945
|
+
return status;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
if (lxb_html_tree_node_is(node, LXB_TAG_TEMPLATE)) {
|
|
949
|
+
lxb_html_template_element_t *temp;
|
|
950
|
+
|
|
951
|
+
temp = lxb_html_interface_template(node);
|
|
952
|
+
|
|
953
|
+
if (temp->content != NULL) {
|
|
954
|
+
if (temp->content->node.first_child != NULL)
|
|
955
|
+
{
|
|
956
|
+
lxb_html_serialize_send_indent((deep + 1), ctx);
|
|
957
|
+
lxb_html_serialize_send("#document-fragment", 18, ctx);
|
|
958
|
+
lxb_html_serialize_send("\n", 1, ctx);
|
|
959
|
+
|
|
960
|
+
status = lxb_html_serialize_pretty_deep_cb(&temp->content->node,
|
|
961
|
+
opt, (deep + 2),
|
|
962
|
+
cb, ctx);
|
|
963
|
+
if (status != LXB_STATUS_OK) {
|
|
964
|
+
return status;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
skip_it = lxb_html_node_is_void(node);
|
|
971
|
+
|
|
972
|
+
if (skip_it == false && node->first_child != NULL) {
|
|
973
|
+
deep++;
|
|
974
|
+
|
|
975
|
+
node = node->first_child;
|
|
976
|
+
}
|
|
977
|
+
else {
|
|
978
|
+
while(node != root && node->next == NULL)
|
|
979
|
+
{
|
|
980
|
+
if (node->type == LXB_DOM_NODE_TYPE_ELEMENT
|
|
981
|
+
&& lxb_html_node_is_void(node) == false)
|
|
982
|
+
{
|
|
983
|
+
if ((opt & LXB_HTML_SERIALIZE_OPT_WITHOUT_CLOSING) == 0) {
|
|
984
|
+
lxb_html_serialize_send_indent(deep, ctx);
|
|
985
|
+
|
|
986
|
+
status = lxb_html_serialize_element_closed_cb(lxb_dom_interface_element(node),
|
|
987
|
+
cb, ctx);
|
|
988
|
+
if (status != LXB_STATUS_OK) {
|
|
989
|
+
return status;
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
lxb_html_serialize_send("\n", 1, ctx);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
deep--;
|
|
997
|
+
|
|
998
|
+
node = node->parent;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
if (node->type == LXB_DOM_NODE_TYPE_ELEMENT
|
|
1002
|
+
&& lxb_html_node_is_void(node) == false)
|
|
1003
|
+
{
|
|
1004
|
+
if ((opt & LXB_HTML_SERIALIZE_OPT_WITHOUT_CLOSING) == 0) {
|
|
1005
|
+
lxb_html_serialize_send_indent(deep, ctx);
|
|
1006
|
+
|
|
1007
|
+
status = lxb_html_serialize_element_closed_cb(lxb_dom_interface_element(node),
|
|
1008
|
+
cb, ctx);
|
|
1009
|
+
if (status != LXB_STATUS_OK) {
|
|
1010
|
+
return status;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
lxb_html_serialize_send("\n", 1, ctx);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
if (node == root) {
|
|
1018
|
+
break;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
node = node->next;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
return LXB_STATUS_OK;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
static lxb_status_t
|
|
1029
|
+
lxb_html_serialize_pretty_element_cb(lxb_dom_element_t *element,
|
|
1030
|
+
lxb_html_serialize_opt_t opt, size_t indent,
|
|
1031
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
1032
|
+
{
|
|
1033
|
+
lxb_status_t status;
|
|
1034
|
+
const lxb_char_t *tag_name;
|
|
1035
|
+
size_t len = 0;
|
|
1036
|
+
|
|
1037
|
+
lxb_dom_attr_t *attr;
|
|
1038
|
+
lxb_dom_node_t *node = lxb_dom_interface_node(element);
|
|
1039
|
+
|
|
1040
|
+
tag_name = lxb_dom_element_qualified_name(element, &len);
|
|
1041
|
+
if (tag_name == NULL) {
|
|
1042
|
+
return LXB_STATUS_ERROR;
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
lxb_html_serialize_send("<", 1, ctx);
|
|
1046
|
+
|
|
1047
|
+
if (element->node.ns != LXB_NS_HTML
|
|
1048
|
+
&& opt & LXB_HTML_SERIALIZE_OPT_TAG_WITH_NS)
|
|
1049
|
+
{
|
|
1050
|
+
const lxb_ns_prefix_data_t *data = NULL;
|
|
1051
|
+
|
|
1052
|
+
if (element->node.prefix != LXB_NS__UNDEF) {
|
|
1053
|
+
data = lxb_ns_prefix_data_by_id(node->owner_document->prefix,
|
|
1054
|
+
element->node.prefix);
|
|
1055
|
+
}
|
|
1056
|
+
else if (element->node.ns < LXB_NS__LAST_ENTRY) {
|
|
1057
|
+
data = lxb_ns_prefix_data_by_id(node->owner_document->prefix,
|
|
1058
|
+
element->node.ns);
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
if (data != NULL) {
|
|
1062
|
+
lxb_html_serialize_send(lexbor_hash_entry_str(&data->entry),
|
|
1063
|
+
data->entry.length, ctx);
|
|
1064
|
+
lxb_html_serialize_send(":", 1, ctx);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
lxb_html_serialize_send(tag_name, len, ctx);
|
|
1069
|
+
|
|
1070
|
+
if (element->is_value != NULL && element->is_value->data != NULL) {
|
|
1071
|
+
attr = lxb_dom_element_attr_is_exist(element,
|
|
1072
|
+
(const lxb_char_t *) "is", 2);
|
|
1073
|
+
if (attr == NULL) {
|
|
1074
|
+
lxb_html_serialize_send(" is=\"", 5, ctx);
|
|
1075
|
+
|
|
1076
|
+
if (opt & LXB_HTML_SERIALIZE_OPT_RAW) {
|
|
1077
|
+
lxb_html_serialize_send(element->is_value->data,
|
|
1078
|
+
element->is_value->length, ctx);
|
|
1079
|
+
}
|
|
1080
|
+
else {
|
|
1081
|
+
status = lxb_html_serialize_send_escaping_attribute_string(element->is_value->data,
|
|
1082
|
+
element->is_value->length,
|
|
1083
|
+
cb, ctx);
|
|
1084
|
+
if (status != LXB_STATUS_OK) {
|
|
1085
|
+
return status;
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
lxb_html_serialize_send("\"", 1, ctx);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
attr = element->first_attr;
|
|
1094
|
+
|
|
1095
|
+
while (attr != NULL) {
|
|
1096
|
+
lxb_html_serialize_send(" ", 1, ctx);
|
|
1097
|
+
|
|
1098
|
+
status = lxb_html_serialize_attribute_cb(attr,
|
|
1099
|
+
(opt & LXB_HTML_SERIALIZE_OPT_RAW),
|
|
1100
|
+
cb, ctx);
|
|
1101
|
+
if (status != LXB_STATUS_OK) {
|
|
1102
|
+
return status;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
attr = attr->next;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
lxb_html_serialize_send(">", 1, ctx);
|
|
1109
|
+
|
|
1110
|
+
return LXB_STATUS_OK;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
static lxb_status_t
|
|
1114
|
+
lxb_html_serialize_pretty_text_cb(lxb_dom_text_t *text,
|
|
1115
|
+
lxb_html_serialize_opt_t opt, size_t indent,
|
|
1116
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
1117
|
+
{
|
|
1118
|
+
lxb_status_t status;
|
|
1119
|
+
lxb_dom_node_t *node = lxb_dom_interface_node(text);
|
|
1120
|
+
lxb_dom_document_t *doc = node->owner_document;
|
|
1121
|
+
lexbor_str_t *data = &text->char_data.data;
|
|
1122
|
+
|
|
1123
|
+
bool with_indent = (opt & LXB_HTML_SERIALIZE_OPT_WITHOUT_TEXT_INDENT) == 0;
|
|
1124
|
+
|
|
1125
|
+
if (opt & LXB_HTML_SERIALIZE_OPT_SKIP_WS_NODES) {
|
|
1126
|
+
const lxb_char_t *pos = data->data;
|
|
1127
|
+
const lxb_char_t *end = pos + data->length;
|
|
1128
|
+
|
|
1129
|
+
while (pos != end) {
|
|
1130
|
+
if (lexbor_tokenizer_chars_map[ *pos ]
|
|
1131
|
+
!= LEXBOR_STR_RES_MAP_CHAR_WHITESPACE)
|
|
1132
|
+
{
|
|
1133
|
+
break;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
pos++;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
return LXB_STATUS_OK;
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
if (node->parent != NULL) {
|
|
1143
|
+
switch (node->parent->local_name) {
|
|
1144
|
+
case LXB_TAG_STYLE:
|
|
1145
|
+
case LXB_TAG_SCRIPT:
|
|
1146
|
+
case LXB_TAG_XMP:
|
|
1147
|
+
case LXB_TAG_IFRAME:
|
|
1148
|
+
case LXB_TAG_NOEMBED:
|
|
1149
|
+
case LXB_TAG_NOFRAMES:
|
|
1150
|
+
case LXB_TAG_PLAINTEXT:
|
|
1151
|
+
status = lxb_html_serialize_pretty_send_string(data->data,
|
|
1152
|
+
data->length,
|
|
1153
|
+
indent,
|
|
1154
|
+
with_indent,
|
|
1155
|
+
cb, ctx);
|
|
1156
|
+
goto end;
|
|
1157
|
+
|
|
1158
|
+
case LXB_TAG_NOSCRIPT:
|
|
1159
|
+
if (doc->scripting) {
|
|
1160
|
+
status = lxb_html_serialize_pretty_send_string(data->data,
|
|
1161
|
+
data->length,
|
|
1162
|
+
indent,
|
|
1163
|
+
with_indent,
|
|
1164
|
+
cb, ctx);
|
|
1165
|
+
goto end;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
break;
|
|
1169
|
+
|
|
1170
|
+
default:
|
|
1171
|
+
break;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
if (opt & LXB_HTML_SERIALIZE_OPT_RAW) {
|
|
1176
|
+
status = lxb_html_serialize_pretty_send_string(data->data, data->length,
|
|
1177
|
+
indent, with_indent,
|
|
1178
|
+
cb, ctx);
|
|
1179
|
+
}
|
|
1180
|
+
else {
|
|
1181
|
+
status = lxb_html_serialize_pretty_send_escaping_string(data->data,
|
|
1182
|
+
data->length,
|
|
1183
|
+
indent,
|
|
1184
|
+
with_indent,
|
|
1185
|
+
cb, ctx);
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
end:
|
|
1189
|
+
|
|
1190
|
+
if (status != LXB_STATUS_OK) {
|
|
1191
|
+
return status;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
lxb_html_serialize_send("\n", 1, ctx);
|
|
1195
|
+
|
|
1196
|
+
return LXB_STATUS_OK;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
static lxb_status_t
|
|
1200
|
+
lxb_html_serialize_pretty_comment_cb(lxb_dom_comment_t *comment,
|
|
1201
|
+
size_t indent, bool with_indent,
|
|
1202
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
1203
|
+
{
|
|
1204
|
+
lxb_status_t status;
|
|
1205
|
+
|
|
1206
|
+
lxb_html_serialize_send_indent(indent, ctx);
|
|
1207
|
+
lxb_html_serialize_send("<!-- ", 5, ctx);
|
|
1208
|
+
|
|
1209
|
+
if (with_indent) {
|
|
1210
|
+
const lxb_char_t *data = comment->char_data.data.data;
|
|
1211
|
+
const lxb_char_t *pos = data;
|
|
1212
|
+
const lxb_char_t *end = pos + comment->char_data.data.length;
|
|
1213
|
+
|
|
1214
|
+
while (data != end) {
|
|
1215
|
+
/*
|
|
1216
|
+
* U+000A LINE FEED (LF)
|
|
1217
|
+
* U+000D CARRIAGE RETURN (CR)
|
|
1218
|
+
*/
|
|
1219
|
+
if (*data == 0x0A || *data == 0x0D) {
|
|
1220
|
+
if (pos != data) {
|
|
1221
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
lxb_html_serialize_send(data, 1, ctx);
|
|
1225
|
+
lxb_html_serialize_send_indent(indent, ctx);
|
|
1226
|
+
|
|
1227
|
+
data++;
|
|
1228
|
+
pos = data;
|
|
1229
|
+
}
|
|
1230
|
+
else {
|
|
1231
|
+
data++;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
if (pos != data) {
|
|
1236
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
else {
|
|
1240
|
+
lxb_html_serialize_send(comment->char_data.data.data,
|
|
1241
|
+
comment->char_data.data.length, ctx);
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
lxb_html_serialize_send(" -->", 4, ctx);
|
|
1245
|
+
|
|
1246
|
+
return LXB_STATUS_OK;
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
static lxb_status_t
|
|
1250
|
+
lxb_html_serialize_pretty_document_cb(lxb_dom_document_t *document,
|
|
1251
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
1252
|
+
{
|
|
1253
|
+
lxb_status_t status;
|
|
1254
|
+
|
|
1255
|
+
lxb_html_serialize_send("#document", 9, ctx);
|
|
1256
|
+
|
|
1257
|
+
return LXB_STATUS_OK;
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
lxb_status_t
|
|
1261
|
+
lxb_html_serialize_tree_cb(lxb_dom_node_t *node,
|
|
1262
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
1263
|
+
{
|
|
1264
|
+
/* For a document we must serialize all children without document node. */
|
|
1265
|
+
if (node->local_name == LXB_TAG__DOCUMENT) {
|
|
1266
|
+
node = node->first_child;
|
|
1267
|
+
|
|
1268
|
+
while (node != NULL) {
|
|
1269
|
+
lxb_status_t status = lxb_html_serialize_node_cb(node, cb, ctx);
|
|
1270
|
+
if (status != LXB_STATUS_OK) {
|
|
1271
|
+
return status;
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
node = node->next;
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
return LXB_STATUS_OK;
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
return lxb_html_serialize_node_cb(node, cb, ctx);
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
lxb_status_t
|
|
1284
|
+
lxb_html_serialize_tree_str(lxb_dom_node_t *node, lexbor_str_t *str)
|
|
1285
|
+
{
|
|
1286
|
+
lxb_html_serialize_ctx_t ctx;
|
|
1287
|
+
|
|
1288
|
+
if (str->data == NULL) {
|
|
1289
|
+
lexbor_str_init(str, node->owner_document->text, 1024);
|
|
1290
|
+
|
|
1291
|
+
if (str->data == NULL) {
|
|
1292
|
+
return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
ctx.str = str;
|
|
1297
|
+
ctx.mraw = node->owner_document->text;
|
|
1298
|
+
|
|
1299
|
+
return lxb_html_serialize_tree_cb(node, lxb_html_serialize_str_callback, &ctx);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
lxb_status_t
|
|
1303
|
+
lxb_html_serialize_pretty_tree_cb(lxb_dom_node_t *node,
|
|
1304
|
+
lxb_html_serialize_opt_t opt, size_t indent,
|
|
1305
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
1306
|
+
{
|
|
1307
|
+
/* For a document we must serialize all children without document node. */
|
|
1308
|
+
if (node->local_name == LXB_TAG__DOCUMENT) {
|
|
1309
|
+
node = node->first_child;
|
|
1310
|
+
|
|
1311
|
+
while (node != NULL) {
|
|
1312
|
+
lxb_status_t status = lxb_html_serialize_pretty_node_cb(node, opt,
|
|
1313
|
+
indent, cb, ctx);
|
|
1314
|
+
if (status != LXB_STATUS_OK) {
|
|
1315
|
+
return status;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
node = node->next;
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
return LXB_STATUS_OK;
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
return lxb_html_serialize_pretty_node_cb(node, opt, indent, cb, ctx);
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
lxb_status_t
|
|
1328
|
+
lxb_html_serialize_pretty_tree_str(lxb_dom_node_t *node,
|
|
1329
|
+
lxb_html_serialize_opt_t opt, size_t indent,
|
|
1330
|
+
lexbor_str_t *str)
|
|
1331
|
+
{
|
|
1332
|
+
lxb_html_serialize_ctx_t ctx;
|
|
1333
|
+
|
|
1334
|
+
if (str->data == NULL) {
|
|
1335
|
+
lexbor_str_init(str, node->owner_document->text, 1024);
|
|
1336
|
+
|
|
1337
|
+
if (str->data == NULL) {
|
|
1338
|
+
return LXB_STATUS_ERROR_MEMORY_ALLOCATION;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
ctx.str = str;
|
|
1343
|
+
ctx.mraw = node->owner_document->text;
|
|
1344
|
+
|
|
1345
|
+
return lxb_html_serialize_pretty_tree_cb(node, opt, indent,
|
|
1346
|
+
lxb_html_serialize_str_callback,
|
|
1347
|
+
&ctx);
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
static lxb_status_t
|
|
1351
|
+
lxb_html_serialize_pretty_send_escaping_string(const lxb_char_t *data, size_t len,
|
|
1352
|
+
size_t indent, bool with_indent,
|
|
1353
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
1354
|
+
{
|
|
1355
|
+
lxb_status_t status;
|
|
1356
|
+
const lxb_char_t *pos = data;
|
|
1357
|
+
const lxb_char_t *end = data + len;
|
|
1358
|
+
|
|
1359
|
+
lxb_html_serialize_send_indent(indent, ctx);
|
|
1360
|
+
lxb_html_serialize_send("\"", 1, ctx);
|
|
1361
|
+
|
|
1362
|
+
while (data != end) {
|
|
1363
|
+
switch (*data) {
|
|
1364
|
+
/* U+0026 AMPERSAND (&) */
|
|
1365
|
+
case 0x26:
|
|
1366
|
+
if (pos != data) {
|
|
1367
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
lxb_html_serialize_send("&", 5, ctx);
|
|
1371
|
+
|
|
1372
|
+
data++;
|
|
1373
|
+
pos = data;
|
|
1374
|
+
|
|
1375
|
+
break;
|
|
1376
|
+
|
|
1377
|
+
/* {0xC2, 0xA0} NO-BREAK SPACE */
|
|
1378
|
+
case 0xC2:
|
|
1379
|
+
data += 1;
|
|
1380
|
+
if (data == end) {
|
|
1381
|
+
break;
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
if (*data != 0xA0) {
|
|
1385
|
+
continue;
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
data -= 1;
|
|
1389
|
+
|
|
1390
|
+
if (pos != data) {
|
|
1391
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
lxb_html_serialize_send(" ", 6, ctx);
|
|
1395
|
+
|
|
1396
|
+
data += 2;
|
|
1397
|
+
pos = data;
|
|
1398
|
+
|
|
1399
|
+
break;
|
|
1400
|
+
|
|
1401
|
+
/* U+003C LESS-THAN SIGN (<) */
|
|
1402
|
+
case 0x3C:
|
|
1403
|
+
if (pos != data) {
|
|
1404
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
lxb_html_serialize_send("<", 4, ctx);
|
|
1408
|
+
|
|
1409
|
+
data++;
|
|
1410
|
+
pos = data;
|
|
1411
|
+
|
|
1412
|
+
break;
|
|
1413
|
+
|
|
1414
|
+
/* U+003E GREATER-THAN SIGN (>) */
|
|
1415
|
+
case 0x3E:
|
|
1416
|
+
if (pos != data) {
|
|
1417
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
lxb_html_serialize_send(">", 4, ctx);
|
|
1421
|
+
|
|
1422
|
+
data++;
|
|
1423
|
+
pos = data;
|
|
1424
|
+
|
|
1425
|
+
break;
|
|
1426
|
+
|
|
1427
|
+
/*
|
|
1428
|
+
* U+000A LINE FEED (LF)
|
|
1429
|
+
* U+000D CARRIAGE RETURN (CR)
|
|
1430
|
+
*/
|
|
1431
|
+
case 0x0A:
|
|
1432
|
+
case 0x0D:
|
|
1433
|
+
if (with_indent) {
|
|
1434
|
+
if (pos != data) {
|
|
1435
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
lxb_html_serialize_send("\n", 1, ctx);
|
|
1439
|
+
lxb_html_serialize_send_indent(indent, ctx);
|
|
1440
|
+
|
|
1441
|
+
data++;
|
|
1442
|
+
pos = data;
|
|
1443
|
+
|
|
1444
|
+
break;
|
|
1445
|
+
}
|
|
1446
|
+
/* fall through */
|
|
1447
|
+
|
|
1448
|
+
default:
|
|
1449
|
+
data++;
|
|
1450
|
+
|
|
1451
|
+
break;
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
if (pos != data) {
|
|
1456
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
lxb_html_serialize_send("\"", 1, ctx);
|
|
1460
|
+
|
|
1461
|
+
return LXB_STATUS_OK;
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
static lxb_status_t
|
|
1465
|
+
lxb_html_serialize_pretty_send_string(const lxb_char_t *data, size_t len,
|
|
1466
|
+
size_t indent, bool with_indent,
|
|
1467
|
+
lxb_html_serialize_cb_f cb, void *ctx)
|
|
1468
|
+
{
|
|
1469
|
+
lxb_status_t status;
|
|
1470
|
+
|
|
1471
|
+
lxb_html_serialize_send_indent(indent, ctx);
|
|
1472
|
+
lxb_html_serialize_send("\"", 1, ctx);
|
|
1473
|
+
|
|
1474
|
+
if (with_indent) {
|
|
1475
|
+
const lxb_char_t *pos = data;
|
|
1476
|
+
const lxb_char_t *end = data + len;
|
|
1477
|
+
|
|
1478
|
+
while (data != end) {
|
|
1479
|
+
/*
|
|
1480
|
+
* U+000A LINE FEED (LF)
|
|
1481
|
+
* U+000D CARRIAGE RETURN (CR)
|
|
1482
|
+
*/
|
|
1483
|
+
if (*data == 0x0A || *data == 0x0D) {
|
|
1484
|
+
if (pos != data) {
|
|
1485
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
lxb_html_serialize_send(data, 1, ctx);
|
|
1489
|
+
lxb_html_serialize_send_indent(indent, ctx);
|
|
1490
|
+
|
|
1491
|
+
data++;
|
|
1492
|
+
pos = data;
|
|
1493
|
+
}
|
|
1494
|
+
else {
|
|
1495
|
+
data++;
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
if (pos != data) {
|
|
1500
|
+
lxb_html_serialize_send(pos, (data - pos), ctx);
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
else {
|
|
1504
|
+
lxb_html_serialize_send(data, len, ctx);
|
|
1505
|
+
}
|
|
1506
|
+
|
|
1507
|
+
lxb_html_serialize_send("\"", 1, ctx);
|
|
1508
|
+
|
|
1509
|
+
return LXB_STATUS_OK;
|
|
1510
|
+
}
|