nokolexbor 0.4.0 → 0.4.2

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: 4d9b715c95c44d85153796fbb2bd0760cde7c83d4a58d0df026a5bd5cddbd7dc
4
+ data.tar.gz: '01958cbe391c1dd9b57419ee84bc7db14c961428ec3c91c916d8a34cc36afddb'
5
5
  SHA512:
6
- metadata.gz: 70c50097ea4a844399ee4c74e7d0413a833dbdfd878208a8b7054ad2d01c2d96c35897b62848b199555b675a409f897a30e9cf90d2dd8c3e74c2fdf8b501340f
7
- data.tar.gz: 7c772720a861bde11b10c1ff23d4796738a58eaa07d32b43478975a4feaab6402ef5fe8819eb9081619b50b970a422a40b613ce405fa2940b54da4929e352bc8
6
+ metadata.gz: 8bbb957b15cac859b5565c57ccd0830b0ce184db5e63bf5b609b788ac4854e9620ba60e5477de1f85492357b216c4d39cded91ea2297142cef7ee529a0aa1692
7
+ data.tar.gz: 9dc2200b3506a5ff3eb14ea4438b09798f6845715238193e09d76468943d08e125992ce758bd3a946ad5b5efcb6443a58fa3aae68d2d7b381410883a974d98da
@@ -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.2'
5
5
  end
@@ -0,0 +1,77 @@
1
+ diff --git a/source/lexbor/dom/interfaces/node.c b/source/lexbor/dom/interfaces/node.c
2
+ index cf6475d..9f1cf75 100755
3
+ --- a/source/lexbor/dom/interfaces/node.c
4
+ +++ b/source/lexbor/dom/interfaces/node.c
5
+ @@ -85,6 +85,7 @@ lxb_dom_node_interface_copy(lxb_dom_node_t *dst,
6
+
7
+ dst->type = src->type;
8
+ dst->user = src->user;
9
+ + dst->source_location = src->source_location;
10
+
11
+ if (dst->owner_document == src->owner_document) {
12
+ dst->local_name = src->local_name;
13
+ diff --git a/source/lexbor/dom/interfaces/node.h b/source/lexbor/dom/interfaces/node.h
14
+ index acd0c1c..f436257 100755
15
+ --- a/source/lexbor/dom/interfaces/node.h
16
+ +++ b/source/lexbor/dom/interfaces/node.h
17
+ @@ -46,6 +46,8 @@ struct lxb_dom_node {
18
+ uintptr_t prefix; /* lowercase: lalala */
19
+ uintptr_t ns; /* namespace */
20
+
21
+ + size_t source_location; /* char offset to the source HTML */
22
+ +
23
+ lxb_dom_document_t *owner_document;
24
+
25
+ lxb_dom_node_t *next;
26
+ diff --git a/source/lexbor/html/tokenizer.c b/source/lexbor/html/tokenizer.c
27
+ index 741bced..6343c65 100755
28
+ --- a/source/lexbor/html/tokenizer.c
29
+ +++ b/source/lexbor/html/tokenizer.c
30
+ @@ -309,6 +309,7 @@ lxb_html_tokenizer_chunk(lxb_html_tokenizer_t *tkz, const lxb_char_t *data,
31
+
32
+ tkz->is_eof = false;
33
+ tkz->status = LXB_STATUS_OK;
34
+ + tkz->first = data;
35
+ tkz->last = end;
36
+
37
+ while (data < end) {
38
+ diff --git a/source/lexbor/html/tokenizer.h b/source/lexbor/html/tokenizer.h
39
+ index ba9602f..08d0d9a 100755
40
+ --- a/source/lexbor/html/tokenizer.h
41
+ +++ b/source/lexbor/html/tokenizer.h
42
+ @@ -72,6 +72,7 @@ struct lxb_html_tokenizer {
43
+ lxb_char_t *pos;
44
+ const lxb_char_t *end;
45
+ const lxb_char_t *begin;
46
+ + const lxb_char_t *first;
47
+ const lxb_char_t *last;
48
+
49
+ /* Entities */
50
+ diff --git a/source/lexbor/html/tree.c b/source/lexbor/html/tree.c
51
+ index 8c42990..28c97cc 100755
52
+ --- a/source/lexbor/html/tree.c
53
+ +++ b/source/lexbor/html/tree.c
54
+ @@ -484,6 +484,7 @@ lxb_html_tree_append_attributes(lxb_html_tree_t *tree,
55
+
56
+ attr->node.local_name = token_attr->name->attr_id;
57
+ attr->node.ns = ns;
58
+ + attr->node.source_location = token_attr->name_begin - tree->tkz_ref->first;
59
+
60
+ /* Fix for adjust MathML/SVG attributes */
61
+ if (tree->before_append_attr != NULL) {
62
+ diff --git a/source/lexbor/html/tree.h b/source/lexbor/html/tree.h
63
+ index 231239d..bc0249e 100755
64
+ --- a/source/lexbor/html/tree.h
65
+ +++ b/source/lexbor/html/tree.h
66
+ @@ -266,8 +266,10 @@ lxb_inline lxb_dom_node_t *
67
+ lxb_html_tree_create_node(lxb_html_tree_t *tree,
68
+ lxb_tag_id_t tag_id, lxb_ns_id_t ns)
69
+ {
70
+ - return (lxb_dom_node_t *) lxb_html_interface_create(tree->document,
71
+ + lxb_dom_node_t *node = (lxb_dom_node_t *) lxb_html_interface_create(tree->document,
72
+ tag_id, ns);
73
+ + 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;
74
+ + return node;
75
+ }
76
+
77
+ 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.2
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-05 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