1/*  Part of Extended Libraries for SWI-Prolog
    2
    3    Author:        Edison Mera
    4    E-mail:        efmera@gmail.com
    5    WWW:           https://github.com/edisonm/xlibrary
    6    Copyright (C): 2016, Process Design Center, Breda, The Netherlands.
    7    All rights reserved.
    8
    9    Redistribution and use in source and binary forms, with or without
   10    modification, are permitted provided that the following conditions
   11    are met:
   12
   13    1. Redistributions of source code must retain the above copyright
   14       notice, this list of conditions and the following disclaimer.
   15
   16    2. Redistributions in binary form must reproduce the above copyright
   17       notice, this list of conditions and the following disclaimer in
   18       the documentation and/or other materials provided with the
   19       distribution.
   20
   21    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   22    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   23    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   24    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   25    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   26    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   27    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   28    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   29    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   30    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   31    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   32    POSSIBILITY OF SUCH DAMAGE.
   33*/
   34
   35:- module(codes_html,
   36          [code_html/3,         % ?Code,  ?Html, ?Tail
   37           codes_html/2,        % +Codes, ?Html
   38           codes_html/3         % +Codes, ?Html, ?Tail
   39          ]).   40
   41codes_html(Codes, Html) :-
   42    codes_html(Codes, Html, []).
   43
   44codes_html(Codes) -->
   45    foldl(code_html_nf, Codes).
   46
   47code_html_nf(Code) --> code_html(Code), !.
   48code_html_nf(Code) --> [Code].
   49
   50% escape characters taken from:
   51% http://www.theukwebdesigncompany.com/articles/entity-escape-characters.php
   52
   53code_html(0'") --> """. % quotation mark
   54code_html(0'') --> "'". % apostrophe
   55code_html(0'&) --> "&". % ampersand
   56code_html(0'<) --> "&lt;". % less-than
   57code_html(0'>) --> "&gt;". % greater-than
   58code_html(0' ) --> "&nbsp;". % non-breaking space
   59code_html(0'¡) --> "&iexcl;". % inverted exclamation mark
   60code_html(0'¢) --> "&cent;". % cent
   61code_html(0'£) --> "&pound;". % pound sterling
   62code_html(0'¤) --> "&curren;". % currency
   63code_html(0'¥) --> "&yen;". % yen
   64code_html(0'¦) --> "&brvbar;". % broken vertical bar
   65code_html(0'§) --> "&sect;". % section
   66code_html(0'¨) --> "&uml;". % spacing diaeresis
   67code_html(0'©) --> "&copy;". % copyright
   68code_html(0'ª) --> "&ordf;". % feminine ordinal indicator
   69code_html(0'«) --> "&laquo;". % angle quotation mark (left)
   70code_html(0'¬) --> "&not;". % negation
   71code_html(0'&) --> "hy;". % soft hyphen
   72code_html(0'®) --> "&reg;". % registered trademark
   73code_html(0'¯) --> "&macr;". % spacing macron
   74code_html(0'°) --> "&deg;". % degree
   75code_html(0'±) --> "&plusmn;". % plus-or-minus
   76code_html(0'²) --> "&sup2;". % superscript 2
   77code_html(0'³) --> "&sup3;". % superscript 3
   78code_html(0'´) --> "&acute;". % spacing acute
   79code_html(0'µ) --> "&micro;". % micro
   80code_html(0'¶) --> "&para;". % paragraph
   81code_html(0'·) --> "&middot;". % middle dot
   82code_html(0'¸) --> "&cedil;". % spacing cedilla
   83code_html(0'¹) --> "&sup1;". % superscript 1
   84code_html(0'º) --> "&ordm;". % masculine ordinal indicator
   85code_html(0'») --> "&raquo;". % angle quotation mark (right)
   86code_html(0'¼) --> "&frac14;". % fraction 1/4
   87code_html(0'½) --> "&frac12;". % fraction 1/2
   88code_html(0'¾) --> "&frac34;". % fraction 3/4
   89code_html(0'¿) --> "&iquest;". % inverted question mark
   90code_html(0'×) --> "&times;". % multiplication
   91code_html(0'÷) --> "&divide;". % division
   92code_html(0'À) --> "&Agrave;". % capital a, grave accent
   93code_html(0'Á) --> "&Aacute;". % capital a, acute accent
   94code_html(0'Â) --> "&Acirc;". % capital a, circumflex accent
   95code_html(0'Ã) --> "&Atilde;". % capital a, tilde
   96code_html(0'Ä) --> "&Auml;". % capital a, umlaut mark
   97code_html(0'Å) --> "&Aring;". % capital a, ring
   98code_html(0'Æ) --> "&AElig;". % capital ae
   99code_html(0'Ç) --> "&Ccedil;". % capital c, cedilla
  100code_html(0'È) --> "&Egrave;". % capital e, grave accent
  101code_html(0'É) --> "&Eacute;". % capital e, acute accent
  102code_html(0'Ê) --> "&Ecirc;". % capital e, circumflex accent
  103code_html(0'Ë) --> "&Euml;". % capital e, umlaut mark
  104code_html(0'Ì) --> "&Igrave;". % capital i, grave accent
  105code_html(0'Í) --> "&Iacute;". % capital i, acute accent
  106code_html(0'Î) --> "&Icirc;". % capital i, circumflex accent
  107code_html(0'Ï) --> "&Iuml;". % capital i, umlaut mark
  108code_html(0'Ð) --> "&ETH;". % capital eth, Icelandic
  109code_html(0'Ñ) --> "&Ntilde;". % capital n, tilde
  110code_html(0'Ò) --> "&Ograve;". % capital o, grave accent
  111code_html(0'Ó) --> "&Oacute;". % capital o, acute accent
  112code_html(0'Ô) --> "&Ocirc;". % capital o, circumflex accent
  113code_html(0'Õ) --> "&Otilde;". % capital o, tilde
  114code_html(0'Ö) --> "&Ouml;". % capital o, umlaut mark
  115code_html(0'Ø) --> "&Oslash;". % capital o, slash
  116code_html(0'Ù) --> "&Ugrave;". % capital u, grave accent
  117code_html(0'Ú) --> "&Uacute;". % capital u, acute accent
  118code_html(0'Û) --> "&Ucirc;". % capital u, circumflex accent
  119code_html(0'Ü) --> "&Uuml;". % capital u, umlaut mark
  120code_html(0'Ý) --> "&Yacute;". % capital y, acute accent
  121code_html(0'Þ) --> "&THORN;". % capital THORN, Icelandic
  122code_html(0'ß) --> "&szlig;". % small sharp s, German
  123code_html(0'à) --> "&agrave;". % small a, grave accent
  124code_html(0'á) --> "&aacute;". % small a, acute accent
  125code_html(0'â) --> "&acirc;". % small a, circumflex accent
  126code_html(0'ã) --> "&atilde;". % small a, tilde
  127code_html(0'ä) --> "&auml;". % small a, umlaut mark
  128code_html(0'å) --> "&aring;". % small a, ring
  129code_html(0'æ) --> "&aelig;". % small ae
  130code_html(0'ç) --> "&ccedil;". % small c, cedilla
  131code_html(0'è) --> "&egrave;". % small e, grave accent
  132code_html(0'é) --> "&eacute;". % small e, acute accent
  133code_html(0'ê) --> "&ecirc;". % small e, circumflex accent
  134code_html(0'ë) --> "&euml;". % small e, umlaut mark
  135code_html(0'ì) --> "&igrave;". % small i, grave accent
  136code_html(0'í) --> "&iacute;". % small i, acute accent
  137code_html(0'î) --> "&icirc;". % small i, circumflex accent
  138code_html(0'ï) --> "&iuml;". % small i, umlaut mark
  139code_html(0'ð) --> "&eth;". % small eth, Icelandic
  140code_html(0'ñ) --> "&ntilde;". % small n, tilde
  141code_html(0'ò) --> "&ograve;". % small o, grave accent
  142code_html(0'ó) --> "&oacute;". % small o, acute accent
  143code_html(0'ô) --> "&ocirc;". % small o, circumflex accent
  144code_html(0'õ) --> "&otilde;". % small o, tilde
  145code_html(0'ö) --> "&ouml;". % small o, umlaut mark
  146code_html(0'ø) --> "&oslash;". % small o, slash
  147code_html(0'ù) --> "&ugrave;". % small u, grave accent
  148code_html(0'ú) --> "&uacute;". % small u, acute accent
  149code_html(0'û) --> "&ucirc;". % small u, circumflex accent
  150code_html(0'ü) --> "&uuml;". % small u, umlaut mark
  151code_html(0'ý) --> "&yacute;". % small y, acute accent
  152code_html(0'þ) --> "&thorn;". % small thorn, Icelandic
  153code_html(0'ÿ) --> "&yuml;". % small y, umlaut mark