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
   41:- use_module(library(apply)).   42
   43codes_html(Codes, Html) :-
   44    codes_html(Codes, Html, []).
   45
   46codes_html(Codes) -->
   47    foldl(code_html_nf, Codes).
   48
   49code_html_nf(Code) --> code_html(Code), !.
   50code_html_nf(Code) --> [Code].
   51
   52% escape characters taken from:
   53% http://www.theukwebdesigncompany.com/articles/entity-escape-characters.php
   54
   55code_html(0'") --> """. % quotation mark
   56code_html(0'') --> "'". % apostrophe
   57code_html(0'&) --> "&". % ampersand
   58code_html(0'<) --> "&lt;". % less-than
   59code_html(0'>) --> "&gt;". % greater-than
   60code_html(0' ) --> "&nbsp;". % non-breaking space
   61code_html(0'¡) --> "&iexcl;". % inverted exclamation mark
   62code_html(0'¢) --> "&cent;". % cent
   63code_html(0'£) --> "&pound;". % pound sterling
   64code_html(0'¤) --> "&curren;". % currency
   65code_html(0'¥) --> "&yen;". % yen
   66code_html(0'¦) --> "&brvbar;". % broken vertical bar
   67code_html(0'§) --> "&sect;". % section
   68code_html(0'¨) --> "&uml;". % spacing diaeresis
   69code_html(0'©) --> "&copy;". % copyright
   70code_html(0'ª) --> "&ordf;". % feminine ordinal indicator
   71code_html(0'«) --> "&laquo;". % angle quotation mark (left)
   72code_html(0'¬) --> "&not;". % negation
   73code_html(0'&) --> "hy;". % soft hyphen
   74code_html(0'®) --> "&reg;". % registered trademark
   75code_html(0'¯) --> "&macr;". % spacing macron
   76code_html(0'°) --> "&deg;". % degree
   77code_html(0'±) --> "&plusmn;". % plus-or-minus
   78code_html(0'²) --> "&sup2;". % superscript 2
   79code_html(0'³) --> "&sup3;". % superscript 3
   80code_html(0'´) --> "&acute;". % spacing acute
   81code_html(0'µ) --> "&micro;". % micro
   82code_html(0'¶) --> "&para;". % paragraph
   83code_html(0'·) --> "&middot;". % middle dot
   84code_html(0'¸) --> "&cedil;". % spacing cedilla
   85code_html(0'¹) --> "&sup1;". % superscript 1
   86code_html(0'º) --> "&ordm;". % masculine ordinal indicator
   87code_html(0'») --> "&raquo;". % angle quotation mark (right)
   88code_html(0'¼) --> "&frac14;". % fraction 1/4
   89code_html(0'½) --> "&frac12;". % fraction 1/2
   90code_html(0'¾) --> "&frac34;". % fraction 3/4
   91code_html(0'¿) --> "&iquest;". % inverted question mark
   92code_html(0'×) --> "&times;". % multiplication
   93code_html(0'÷) --> "&divide;". % division
   94code_html(0'À) --> "&Agrave;". % capital a, grave accent
   95code_html(0'Á) --> "&Aacute;". % capital a, acute accent
   96code_html(0'Â) --> "&Acirc;". % capital a, circumflex accent
   97code_html(0'Ã) --> "&Atilde;". % capital a, tilde
   98code_html(0'Ä) --> "&Auml;". % capital a, umlaut mark
   99code_html(0'Å) --> "&Aring;". % capital a, ring
  100code_html(0'Æ) --> "&AElig;". % capital ae
  101code_html(0'Ç) --> "&Ccedil;". % capital c, cedilla
  102code_html(0'È) --> "&Egrave;". % capital e, grave accent
  103code_html(0'É) --> "&Eacute;". % capital e, acute accent
  104code_html(0'Ê) --> "&Ecirc;". % capital e, circumflex accent
  105code_html(0'Ë) --> "&Euml;". % capital e, umlaut mark
  106code_html(0'Ì) --> "&Igrave;". % capital i, grave accent
  107code_html(0'Í) --> "&Iacute;". % capital i, acute accent
  108code_html(0'Î) --> "&Icirc;". % capital i, circumflex accent
  109code_html(0'Ï) --> "&Iuml;". % capital i, umlaut mark
  110code_html(0'Ð) --> "&ETH;". % capital eth, Icelandic
  111code_html(0'Ñ) --> "&Ntilde;". % capital n, tilde
  112code_html(0'Ò) --> "&Ograve;". % capital o, grave accent
  113code_html(0'Ó) --> "&Oacute;". % capital o, acute accent
  114code_html(0'Ô) --> "&Ocirc;". % capital o, circumflex accent
  115code_html(0'Õ) --> "&Otilde;". % capital o, tilde
  116code_html(0'Ö) --> "&Ouml;". % capital o, umlaut mark
  117code_html(0'Ø) --> "&Oslash;". % capital o, slash
  118code_html(0'Ù) --> "&Ugrave;". % capital u, grave accent
  119code_html(0'Ú) --> "&Uacute;". % capital u, acute accent
  120code_html(0'Û) --> "&Ucirc;". % capital u, circumflex accent
  121code_html(0'Ü) --> "&Uuml;". % capital u, umlaut mark
  122code_html(0'Ý) --> "&Yacute;". % capital y, acute accent
  123code_html(0'Þ) --> "&THORN;". % capital THORN, Icelandic
  124code_html(0'ß) --> "&szlig;". % small sharp s, German
  125code_html(0'à) --> "&agrave;". % small a, grave accent
  126code_html(0'á) --> "&aacute;". % small a, acute accent
  127code_html(0'â) --> "&acirc;". % small a, circumflex accent
  128code_html(0'ã) --> "&atilde;". % small a, tilde
  129code_html(0'ä) --> "&auml;". % small a, umlaut mark
  130code_html(0'å) --> "&aring;". % small a, ring
  131code_html(0'æ) --> "&aelig;". % small ae
  132code_html(0'ç) --> "&ccedil;". % small c, cedilla
  133code_html(0'è) --> "&egrave;". % small e, grave accent
  134code_html(0'é) --> "&eacute;". % small e, acute accent
  135code_html(0'ê) --> "&ecirc;". % small e, circumflex accent
  136code_html(0'ë) --> "&euml;". % small e, umlaut mark
  137code_html(0'ì) --> "&igrave;". % small i, grave accent
  138code_html(0'í) --> "&iacute;". % small i, acute accent
  139code_html(0'î) --> "&icirc;". % small i, circumflex accent
  140code_html(0'ï) --> "&iuml;". % small i, umlaut mark
  141code_html(0'ð) --> "&eth;". % small eth, Icelandic
  142code_html(0'ñ) --> "&ntilde;". % small n, tilde
  143code_html(0'ò) --> "&ograve;". % small o, grave accent
  144code_html(0'ó) --> "&oacute;". % small o, acute accent
  145code_html(0'ô) --> "&ocirc;". % small o, circumflex accent
  146code_html(0'õ) --> "&otilde;". % small o, tilde
  147code_html(0'ö) --> "&ouml;". % small o, umlaut mark
  148code_html(0'ø) --> "&oslash;". % small o, slash
  149code_html(0'ù) --> "&ugrave;". % small u, grave accent
  150code_html(0'ú) --> "&uacute;". % small u, acute accent
  151code_html(0'û) --> "&ucirc;". % small u, circumflex accent
  152code_html(0'ü) --> "&uuml;". % small u, umlaut mark
  153code_html(0'ý) --> "&yacute;". % small y, acute accent
  154code_html(0'þ) --> "&thorn;". % small thorn, Icelandic
  155code_html(0'ÿ) --> "&yuml;". % small y, umlaut mark