nokolexbor 0.6.0 → 0.6.1
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 +4 -4
- data/ext/nokolexbor/extconf.rb +13 -4
- data/ext/nokolexbor/nl_document.c +3 -20
- data/lib/nokolexbor/document.rb +20 -0
- data/lib/nokolexbor/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd05d369d77b5bcd7ba2e513ff1063cf2a72b9eb215172e4db12f71207c1de8e
|
4
|
+
data.tar.gz: 1e476b729e48e5e16753acd7c07306de2503659d3cd3b17f5f1d1674f073b058
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7adf82735fc97339b9990999674c7a2afafa78e52cab6940edebbc3efe74e26f9e9231b9bc7e3ee3895cc5f938cba7891e482724f28f87be0d13256a8536db80
|
7
|
+
data.tar.gz: 599b41913bf994d633d4e3b86ec7013ce43db80f7c3bdb5d4560bfab4d2b5ae4e0fabed26d9807a0b8b493963ffd0b3bf1de16dda9758fe2d15de19df089c22d
|
data/ext/nokolexbor/extconf.rb
CHANGED
@@ -24,7 +24,20 @@ def which(cmd)
|
|
24
24
|
return nil
|
25
25
|
end
|
26
26
|
|
27
|
+
if !find_executable('cmake')
|
28
|
+
abort "ERROR: CMake is required to build Lexbor."
|
29
|
+
end
|
30
|
+
|
27
31
|
cmake_flags = [ ENV["CMAKE_FLAGS"] ]
|
32
|
+
|
33
|
+
cmake_version_full = `cmake --version`
|
34
|
+
unless cmake_version_full.empty?
|
35
|
+
cmake_version = cmake_version_full[/cmake version ([0-9\.]+)/, 1]
|
36
|
+
if Gem::Version.new(cmake_version) >= Gem::Version.new('4.0')
|
37
|
+
cmake_flags << "-DCMAKE_POLICY_VERSION_MINIMUM=3.5"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
28
41
|
cmake_flags << "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY"
|
29
42
|
# Set system name explicitly when cross-compiling
|
30
43
|
cmake_flags << "-DCMAKE_SYSTEM_NAME=Windows -DWIN32=1" if windows?
|
@@ -116,10 +129,6 @@ LEXBOR_DIR = File.join(CWD, '..', '..', 'vendor', 'lexbor')
|
|
116
129
|
EXT_DIR = File.join(CWD, '..', '..', 'ext', 'nokolexbor')
|
117
130
|
INSTALL_DIR = File.join(LEXBOR_DIR, 'dist')
|
118
131
|
|
119
|
-
if !find_executable('cmake')
|
120
|
-
abort "ERROR: CMake is required to build Lexbor."
|
121
|
-
end
|
122
|
-
|
123
132
|
Dir.chdir(LEXBOR_DIR) do
|
124
133
|
# Patch lexbor
|
125
134
|
Dir['../../patches/*-lexbor-*.patch'].each do |patch_file|
|
@@ -22,26 +22,9 @@ const rb_data_type_t nl_document_type = {
|
|
22
22
|
RUBY_TYPED_FREE_IMMEDIATELY,
|
23
23
|
};
|
24
24
|
|
25
|
-
/**
|
26
|
-
* call-seq:
|
27
|
-
* parse(string_or_io) -> Document
|
28
|
-
*
|
29
|
-
* Parse HTML into a {Document}.
|
30
|
-
*
|
31
|
-
* @param string_or_io [String, #read]
|
32
|
-
* The HTML to be parsed. It may be a String, or any object that
|
33
|
-
* responds to #read such as an IO, or StringIO.
|
34
|
-
*/
|
35
25
|
static VALUE
|
36
|
-
|
26
|
+
nl_document_parse_native(VALUE self, VALUE rb_html)
|
37
27
|
{
|
38
|
-
VALUE id_read = rb_intern("read");
|
39
|
-
VALUE rb_html;
|
40
|
-
if (rb_respond_to(rb_string_or_io, id_read)) {
|
41
|
-
rb_html = rb_funcall(rb_string_or_io, id_read, 0);
|
42
|
-
} else {
|
43
|
-
rb_html = rb_string_or_io;
|
44
|
-
}
|
45
28
|
const char *html_c = StringValuePtr(rb_html);
|
46
29
|
size_t html_len = RSTRING_LEN(rb_html);
|
47
30
|
|
@@ -74,7 +57,7 @@ nl_document_parse(VALUE self, VALUE rb_string_or_io)
|
|
74
57
|
static VALUE
|
75
58
|
nl_document_new(VALUE self)
|
76
59
|
{
|
77
|
-
return
|
60
|
+
return nl_document_parse_native(self, rb_str_new("", 0));
|
78
61
|
}
|
79
62
|
|
80
63
|
lxb_dom_document_t *
|
@@ -136,7 +119,7 @@ void Init_nl_document(void)
|
|
136
119
|
{
|
137
120
|
cNokolexborDocument = rb_define_class_under(mNokolexbor, "Document", cNokolexborNode);
|
138
121
|
rb_define_singleton_method(cNokolexborDocument, "new", nl_document_new, 0);
|
139
|
-
rb_define_singleton_method(cNokolexborDocument, "
|
122
|
+
rb_define_singleton_method(cNokolexborDocument, "parse_native", nl_document_parse_native, 1);
|
140
123
|
rb_define_method(cNokolexborDocument, "title", nl_document_get_title, 0);
|
141
124
|
rb_define_method(cNokolexborDocument, "title=", nl_document_set_title, 1);
|
142
125
|
rb_define_method(cNokolexborDocument, "root", nl_document_root, 0);
|
data/lib/nokolexbor/document.rb
CHANGED
@@ -141,6 +141,26 @@ module Nokolexbor
|
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
|
+
# Parse HTML into a {Document}.
|
145
|
+
#
|
146
|
+
# @param string_or_io [String, #read]
|
147
|
+
# The HTML to be parsed. It may be a String, or any object that
|
148
|
+
# responds to #read such as an IO, or StringIO.
|
149
|
+
#
|
150
|
+
# @return [Document]
|
151
|
+
def self.parse(string_or_io)
|
152
|
+
html = string_or_io
|
153
|
+
if string_or_io.respond_to?(:read)
|
154
|
+
html = string_or_io.read
|
155
|
+
end
|
156
|
+
|
157
|
+
if html.respond_to?(:encoding) && html.encoding != Encoding::UTF_8
|
158
|
+
html = html.encode(Encoding::UTF_8, invalid: :replace, undef: :replace)
|
159
|
+
end
|
160
|
+
|
161
|
+
parse_native(html)
|
162
|
+
end
|
163
|
+
|
144
164
|
private
|
145
165
|
|
146
166
|
IMPLIED_XPATH_CONTEXTS = ["//"].freeze # :nodoc:
|
data/lib/nokolexbor/version.rb
CHANGED
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.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yicheng Zhou
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -523,7 +523,7 @@ licenses:
|
|
523
523
|
- MIT
|
524
524
|
metadata:
|
525
525
|
msys2_mingw_dependencies: cmake
|
526
|
-
post_install_message:
|
526
|
+
post_install_message:
|
527
527
|
rdoc_options: []
|
528
528
|
require_paths:
|
529
529
|
- lib
|
@@ -539,7 +539,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
539
539
|
version: '0'
|
540
540
|
requirements: []
|
541
541
|
rubygems_version: 3.0.3.1
|
542
|
-
signing_key:
|
542
|
+
signing_key:
|
543
543
|
specification_version: 4
|
544
544
|
summary: High-performance HTML5 parser, with support for both CSS selectors and XPath.
|
545
545
|
test_files: []
|