【发布时间】:2021-02-19 21:11:26
【问题描述】:
我正在尝试使用 SWI Prolog 的 library(http/html_write) 生成 HTML 文件。我想生成下面的 HTML 并将其写入名为“mypage.html”的文件:
<!DOCTYPE html>
<html>
<head>
<title>Hello</title>
</head>
<body>
<h1>Hello</h1>
<p id="my-id">This is a paragraph.</p>
</body>
</html>
到目前为止,我已经编写了 HTML 的 Prolog 表示:
html(head(title('Hello')),
body([h1('Hello'),
p(id('my-id'), 'This is a paragraph.')]))
现在呢?我如何实际将此表示形式转换为字符串,然后将其写入名为“mypage.html”的文件?我已阅读文档 (Examples for using the HTML write library),但无法理解如何将 HTML 表示形式转换为字符串。
我尝试使用html_write:print_html/1,但它所做的只是像我写的那样打印结构:
$ swipl --quiet
?- use_module(library(http/html_write)).
true.
?- print_html([html(head(title('Hello')),
| body([h1('Hello'),
| p(id('my-id'), 'This is a paragraph.')]))]).
html(head(title(Hello)),body([h1(Hello),p(id(my-id),This is a paragraph.)]))
true.
?-
您能否提供一个最小的工作示例,将 HTML 的 Prolog 表示形式转换为字符串,然后写入文件?
更新:我已经在 SWi Prolog 的论坛上交叉发布了这个问题并收到了回复:How to use the http/html_write library to write HTML to a file
【问题讨论】:
标签: html prolog swi-prolog