nx_html_to_text_real_test.nx source
↩ module page · 34 lines · 1163 B
1// nx_html_to_text_real_test.nx -- bits-up render stage.
2//
3// Reads /tmp/example_com.html (dropped by nx_https_get_live_real_ca)
4// and pipes it through nx_html_to_text, printing the rendered plain
5// text on stdout. Split off from the live test to keep that test
6// under the bootstrap parser's 2048 module-const cap. The HTML
7// itself was fetched bits-up through DNS+TCP+TLS+cert chain+HTTP
8// already; this stage just does the document-side render.
9//
10// expect_exit: 0.
11// license_tier: ORIGINAL
12
13import "nx_syscalls.nx"
14import "nx_html_to_text.nx"
15
16func main() -> i64 {
17 let path: *u8 = "/tmp/example_com.html\x00"
18 let len_p: *i64 = sys_mmap(16) as *i64
19 let html: *u8 = sys_read_file(path, len_p)
20 let html_len: i64 = *len_p
21 if html_len <= 0 { return 1 }
22
23 let text: *u8 = sys_mmap(8192)
24 let text_len: i64 = nx_html_to_text(html, html_len, text, 8192)
25
26 let banner: *u8 = "---- example.com via bits-up NishiLang ----\n\x00"
27 var i: i64 = 0
28 while banner[i] != 0 { i = i + 1 }
29 sys_write(1, banner, i)
30 sys_write(1, text, text_len)
31 let nl: *u8 = sys_mmap(8); nl[0] = 0x0A
32 sys_write(1, nl, 1)
33 return 0
34}