This module implements predicates for HTML/XML generation and parsing.
canonic_html_item(comment(S)) :- string(S). canonic_html_item(declare(S)) :- string(S). canonic_html_item(env(Tag,Atts,Terms)) :- atm(Tag), list(tag_attrib,Atts), canonic_html_term(Terms). canonic_html_item($(Tag,Atts)) :- atm(Tag), list(tag_attrib,Atts). canonic_html_item(S) :- string(S).
tag_attrib(Att) :- atm(Att). tag_attrib(Att=Val) :- atm(Att), string(Val).Each structure represents one HTML construction:
For example, the term
env(a,[href="www.therainforestsite.com"], ["Visit ",img$[src="TRFS.gif"]])is output to (or parsed from):
<a href="www.therainforestsite.com">Visit <img src="TRFS.gif"></a>
Usage:canonic_html_term(HTMLTerm)
HTMLTerm is a term representing HTML code in canonical form.
canonic_xml_item(Term) :- canonic_html_item(Term). canonic_xml_item(xmldecl(Atts)) :- list(tag_attrib,Atts). canonic_xml_item(env(Tag,Atts,Terms)) :- atm(Tag), list(tag_attrib,Atts), canonic_xml_term(Terms). canonic_xml_item(elem(Tag,Atts)) :- atm(Tag), list(tag_attrib,Atts).In addition to the structures defined by canonic_html_term/1 (the ($)/2 structure appears only in malformed XML code), the following structures can be used:
elem(arc,[weigh="3",begin="n1",end="n2"])is output to (or parsed from):
<arc weigh="3" begin="n1" end="n2"/>
Usage:canonic_xml_term(XMLTerm)
XMLTerm is a term representing XML code in canonical form.
address('clip@clip.dia.fi.upm.es')is translated into the HTML source
<address>clip@clip.dia.fi.upm.es</address>
a([href='http://www.clip.dia.fi.upm.es/'],"Clip home")represents the HTML source
<a href="http://www.clip.dia.fi.upm.es/">Clip home</a>
Usage:html_term(HTMLTerm)
HTMLTerm is a term representing HTML code.
Outputs HTMLTerm, interpreted as an html_term/1, to current output stream.
Usage:
String is a character list containing HTML code and Terms is its prolog structured representation.
Usage 1:
Translates an HTML-term into the HTML code it represents.
Usage 2:
Translates HTML code into a structured HTML-term.
String is a character list containing XML code and Terms is its prolog structured representation.
Usage 1:
Translates a XML-term into the XML code it represents.
Usage 2:
Translates XML code into a structured XML-term.
Interprets Chars as an HTML template returning in Terms the corresponding structured HTML-term, which includes variables, and unifying Dict with a dictionary of those variables (an incomplete list of name=Var pairs). An HTML template is standard HTML code, but in which “slots” can be defined and given an identifier. These slots represent parts of the HTML code in which other HTML code can be inserted, and are represented in the HTML-term as free variables. There are two kinds of variables in templates:
As an example, suposse the following HTML template:
<html> <body bgcolor=_bgcolor> <v>content</v> </body> </html>The following query in the Ciao toplevel shows how the template is parsed, and the dictionary returned:
?- file_to_string('template.html',_S), html_template(_S,Terms,Dict). Dict = [bgcolor=_A,content=_B|_], Terms = [env(html,[],[" ",env(body,[bgcolor=_A],[" ",_B," "])," "])," "] ? yesIf a dictionary with values is supplied at call time, then variables are unified accordingly inside the template:
?- file_to_string('template.html',_S), html_template(_S,Terms,[content=b("hello world!"),bgcolor="white"]). Terms = [env(html,[],[" ",env(body,[bgcolor="white"],[" ",b("hello world!")," "])," "])," "] ? yes
Usage:
Usage:html_expansion(Term,Expansion)
Hook predicate to define macros. Expand occurrences of Term into Expansion, in output_html/1. Take care to not transform something into itself!