-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-wasm.html
More file actions
74 lines (66 loc) · 2.5 KB
/
Copy pathtest-wasm.html
File metadata and controls
74 lines (66 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Trek WASM Test</title>
</head>
<body>
<h1>Trek WASM Test</h1>
<p>Check the console for output.</p>
<script type="module">
import init, { TrekWasm } from './pkg/trek_rs.js';
async function run() {
// Initialize the WASM module
await init();
// Create a Trek instance
const trek = new TrekWasm({
debug: false,
min_content_score: 20.0,
max_attempts: 3,
include_metadata: true,
remove_exact_selectors: true,
remove_partial_selectors: true,
remove_selectors: [],
preserve_selectors: []
});
// Test HTML
const html = `
<html>
<head>
<title>Test Article</title>
<meta name="description" content="This is a test article">
<meta name="author" content="Test Author">
</head>
<body>
<nav>Navigation menu</nav>
<article>
<h1>Main Article Title</h1>
<p>This is the first paragraph of the main content.</p>
<p>This is the second paragraph with more important information.</p>
<div class="code-block">
<pre><code>console.log("Hello, Trek!");</code></pre>
</div>
</article>
<aside>Sidebar content</aside>
<footer>Footer information</footer>
</body>
</html>
`;
try {
// Parse the HTML
const result = trek.parse(html);
console.log('Trek extraction result:', result);
// Also test async version
const asyncResult = await trek.parse_async(html);
console.log('Trek async extraction result:', asyncResult);
} catch (error) {
console.error('Error:', error);
}
// Clean up
trek.free();
}
run();
</script>
</body>
</html>