/* Part of XPCE --- The SWI-Prolog GUI toolkit
Author: Jan Wielemaker and Anjo Anjewierden
E-mail: jan@swi.psy.uva.nl
WWW: http://www.swi.psy.uva.nl/projects/xpce/
Copyright (c) 2000-2020, University of Amsterdam
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
:- module(html,
[
]).
:- use_module(doc(emit)).
:- use_module(library(pce)).
:- use_module(doc(util)).
:- use_module(doc(url_fetch)).
:- use_module(doc(form)).
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
This module connects the xml2pl library to the XPCE document rendering
primitives, providing parsing HTML files as well as required hooks into
emit/3 to deal with the HTML xml2pl element/3 terms.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/*******************************
* RENDERING *
*******************************/
:- multifile
doc:emit/3,
doc:action/3.
doc:emit(document(_, Content), PB, Mode) :-
!,
emit(Content, PB, Mode).
doc:emit([element(p, A, C)|T0], PB, Mode) :-
!,
join_paragraphs(element(p, A, C), T0, P, T),
phrase(P, T1, T),
emit(T1, PB, Mode).
doc:emit([element(Tag, Attributes, Content)|T], PB, Mode) :-
( phrase(element(Tag, Attributes, Content, Mode), T1, T)
; phrase(element(Tag, Attributes, Content), T1, T)
),
!,
emit(T1, PB, Mode).
% Delete empty paragraphs before real paragraphs.
join_paragraphs(element(p, [], []), [element(p, A, C)|T0], P, T) :-
!,
join_paragraphs(element(p, A, C), T0, P, T).
join_paragraphs(P, T, P, T).
/*******************************
* MACROS *
*******************************/
:- multifile
element/5, % +Tag, +Attributes, +Content
element/6. % +Tag, +Attributes, +Content, +ParBox
% Basic text handling
element(p, [], Content) --> %