nokolexbor 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f60315f588c46f8ae2927633d3e34ee8f3aa3f6fb97575851bc967f306d216a5
4
- data.tar.gz: 8e71ffb858e63f59284b94eee695b90808875c9af388175937a4e04cfbff715c
3
+ metadata.gz: 0055757bc7b9a92e9a2d37235722ca6a6945fb438855880ce10055dfa10d0fcb
4
+ data.tar.gz: b42cb00bc57ac3db09e928ff0b4ae3b3f7fb950312ab64f2606436184785dcc0
5
5
  SHA512:
6
- metadata.gz: 70c50097ea4a844399ee4c74e7d0413a833dbdfd878208a8b7054ad2d01c2d96c35897b62848b199555b675a409f897a30e9cf90d2dd8c3e74c2fdf8b501340f
7
- data.tar.gz: 7c772720a861bde11b10c1ff23d4796738a58eaa07d32b43478975a4feaab6402ef5fe8819eb9081619b50b970a422a40b613ce405fa2940b54da4929e352bc8
6
+ metadata.gz: 5527c86fea7d9efbbea6bcc1a2fcaaad506057ccf2d22d689f0de143b6c142f9bd1e8b33686ed2be1d01c37c1b02879c35e392a0ca81489f7f9cb125e569bf33
7
+ data.tar.gz: 4af797ac972b1ddfaafceec1ded5de2541daa92a366568f768f63f978bf3215e9a03295f598f4e05eea253aa2af8098ff8de33431119e7aeecad8a223de0c6f4
@@ -1053,20 +1053,8 @@ static VALUE
1053
1053
  nl_node_first_element_child(VALUE self)
1054
1054
  {
1055
1055
  lxb_dom_node_t *parent = nl_rb_node_unwrap(self);
1056
- lxb_dom_node_t *cur;
1056
+ lxb_dom_node_t *cur = parent->first_child;
1057
1057
 
1058
- if (parent == NULL) {
1059
- return Qnil;
1060
- }
1061
- switch (parent->type) {
1062
- case LXB_DOM_NODE_TYPE_ELEMENT:
1063
- case LXB_DOM_NODE_TYPE_ENTITY:
1064
- case LXB_DOM_NODE_TYPE_DOCUMENT:
1065
- cur = parent->first_child;
1066
- break;
1067
- default:
1068
- return Qnil;
1069
- }
1070
1058
  while (cur != NULL) {
1071
1059
  if (cur->type == LXB_DOM_NODE_TYPE_ELEMENT) {
1072
1060
  return nl_rb_node_create(cur, nl_rb_document_get(self));
@@ -1083,20 +1071,8 @@ static VALUE
1083
1071
  nl_node_last_element_child(VALUE self)
1084
1072
  {
1085
1073
  lxb_dom_node_t *parent = nl_rb_node_unwrap(self);
1086
- lxb_dom_node_t *cur;
1074
+ lxb_dom_node_t *cur = parent->last_child;
1087
1075
 
1088
- if (parent == NULL) {
1089
- return Qnil;
1090
- }
1091
- switch (parent->type) {
1092
- case LXB_DOM_NODE_TYPE_ELEMENT:
1093
- case LXB_DOM_NODE_TYPE_ENTITY:
1094
- case LXB_DOM_NODE_TYPE_DOCUMENT:
1095
- cur = parent->last_child;
1096
- break;
1097
- default:
1098
- return Qnil;
1099
- }
1100
1076
  while (cur != NULL) {
1101
1077
  if (cur->type == LXB_DOM_NODE_TYPE_ELEMENT) {
1102
1078
  return nl_rb_node_create(cur, nl_rb_document_get(self));
@@ -1155,6 +1131,16 @@ nl_node_inspect(int argc, VALUE *argv, VALUE self)
1155
1131
  return rb_call_super(argc, argv);
1156
1132
  }
1157
1133
 
1134
+ /**
1135
+ * @return [Integer] The node's location at the source HTML. Returns 0 if the node is not parsed from a HTML string.
1136
+ */
1137
+ static VALUE
1138
+ nl_node_source_location(VALUE self)
1139
+ {
1140
+ lxb_dom_node_t *node = nl_rb_node_unwrap(self);
1141
+ return ULONG2NUM(node->source_location);
1142
+ }
1143
+
1158
1144
  void Init_nl_node(void)
1159
1145
  {
1160
1146
  cNokolexborNode = rb_define_class_under(mNokolexbor, "Node", rb_cObject);
@@ -1199,6 +1185,7 @@ void Init_nl_node(void)
1199
1185
  rb_define_method(cNokolexborNode, "last_element_child", nl_node_last_element_child, 0);
1200
1186
  rb_define_method(cNokolexborNode, "clone", nl_node_clone, 0);
1201
1187
  rb_define_method(cNokolexborNode, "inspect", nl_node_inspect, -1);
1188
+ rb_define_method(cNokolexborNode, "source_location", nl_node_source_location, 0);
1202
1189
 
1203
1190
  rb_define_alias(cNokolexborNode, "attr", "[]");
1204
1191
  rb_define_alias(cNokolexborNode, "get_attribute", "[]");
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nokolexbor
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.1'
5
5
  end
@@ -0,0 +1,65 @@
1
+ diff --git a/source/lexbor/dom/interfaces/node.h b/source/lexbor/dom/interfaces/node.h
2
+ index acd0c1c..f436257 100755
3
+ --- a/source/lexbor/dom/interfaces/node.h
4
+ +++ b/source/lexbor/dom/interfaces/node.h
5
+ @@ -46,6 +46,8 @@ struct lxb_dom_node {
6
+ uintptr_t prefix; /* lowercase: lalala */
7
+ uintptr_t ns; /* namespace */
8
+
9
+ + size_t source_location; /* char offset to the source HTML */
10
+ +
11
+ lxb_dom_document_t *owner_document;
12
+
13
+ lxb_dom_node_t *next;
14
+ diff --git a/source/lexbor/html/tokenizer.c b/source/lexbor/html/tokenizer.c
15
+ index 741bced..6343c65 100755
16
+ --- a/source/lexbor/html/tokenizer.c
17
+ +++ b/source/lexbor/html/tokenizer.c
18
+ @@ -309,6 +309,7 @@ lxb_html_tokenizer_chunk(lxb_html_tokenizer_t *tkz, const lxb_char_t *data,
19
+
20
+ tkz->is_eof = false;
21
+ tkz->status = LXB_STATUS_OK;
22
+ + tkz->first = data;
23
+ tkz->last = end;
24
+
25
+ while (data < end) {
26
+ diff --git a/source/lexbor/html/tokenizer.h b/source/lexbor/html/tokenizer.h
27
+ index ba9602f..08d0d9a 100755
28
+ --- a/source/lexbor/html/tokenizer.h
29
+ +++ b/source/lexbor/html/tokenizer.h
30
+ @@ -72,6 +72,7 @@ struct lxb_html_tokenizer {
31
+ lxb_char_t *pos;
32
+ const lxb_char_t *end;
33
+ const lxb_char_t *begin;
34
+ + const lxb_char_t *first;
35
+ const lxb_char_t *last;
36
+
37
+ /* Entities */
38
+ diff --git a/source/lexbor/html/tree.c b/source/lexbor/html/tree.c
39
+ index 8c42990..28c97cc 100755
40
+ --- a/source/lexbor/html/tree.c
41
+ +++ b/source/lexbor/html/tree.c
42
+ @@ -484,6 +484,7 @@ lxb_html_tree_append_attributes(lxb_html_tree_t *tree,
43
+
44
+ attr->node.local_name = token_attr->name->attr_id;
45
+ attr->node.ns = ns;
46
+ + attr->node.source_location = token_attr->name_begin - tree->tkz_ref->first;
47
+
48
+ /* Fix for adjust MathML/SVG attributes */
49
+ if (tree->before_append_attr != NULL) {
50
+ diff --git a/source/lexbor/html/tree.h b/source/lexbor/html/tree.h
51
+ index 231239d..bc0249e 100755
52
+ --- a/source/lexbor/html/tree.h
53
+ +++ b/source/lexbor/html/tree.h
54
+ @@ -266,8 +266,10 @@ lxb_inline lxb_dom_node_t *
55
+ lxb_html_tree_create_node(lxb_html_tree_t *tree,
56
+ lxb_tag_id_t tag_id, lxb_ns_id_t ns)
57
+ {
58
+ - return (lxb_dom_node_t *) lxb_html_interface_create(tree->document,
59
+ + lxb_dom_node_t *node = (lxb_dom_node_t *) lxb_html_interface_create(tree->document,
60
+ tag_id, ns);
61
+ + node->source_location = (tree->tkz_ref->token->begin > tree->tkz_ref->first ? tree->tkz_ref->token->begin : tree->tkz_ref->begin) - tree->tkz_ref->first;
62
+ + return node;
63
+ }
64
+
65
+ lxb_inline bool
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokolexbor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yicheng Zhou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-22 00:00:00.000000000 Z
11
+ date: 2023-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -131,6 +131,7 @@ files:
131
131
  - patches/0002-lexbor-match-id-class-case-sensitive.patch
132
132
  - patches/0003-lexbor-attach-template-content-to-self.patch
133
133
  - patches/0004-lexbor-fix-template-clone.patch
134
+ - patches/0005-lexbor-add-source-location-to-node.patch
134
135
  - vendor/lexbor/CMakeLists.txt
135
136
  - vendor/lexbor/config.cmake
136
137
  - vendor/lexbor/feature.cmake