1:- module(javascript_utils, [javascript_friendly_html/2]).
7:- use_module(library(http/html_write)). 8 9:- html_meta javascript_friendly_html(html, -).
It's fairly common to stuff html into a javascript string. This bit handles javascript's lack of heredoc syntax. */
21javascript_friendly_html(HTML, FriendlyHTML) :- 22 phrase(html(HTML), Tokens), 23 with_output_to(codes(RawCodes), print_html(Tokens)), 24 js_friendly(RawCodes, Codes), 25 atom_codes(FriendlyHTML, Codes). 26 27js_friendly([], []). 28% Line feeds are skipped. 29js_friendly([10 | RT] , T) :- 30 js_friendly(RT, T). 31% Carriage returns are skipped. 32js_friendly([13 | RT], T) :- 33 js_friendly(RT, T). 34% Double quotes are escaped by backslashes. 35js_friendly([34 | RT], [92 , 34 | T]) :- 36 js_friendly(RT, T). 37% Apostrophes are escaped by backslashes. 38js_friendly([39 | RT], [92 , 39 | T]) :- 39 js_friendly(RT, T). 40js_friendly([RH | RT], [RH | T]) :- 41 js_friendly(RT, T)
Javascript handling utilities
6/29/2013 renamed to avoid colliding with library javascript
*/