SWISH term_singletons/2 and easy text coloring?

I made two SWISH notebooks:

Natural Deduction Minimal Logic with DNE
https://swish.swi-prolog.org/p/glue.p.swinb

Natural Deduction Minimal Logic with RAA
https://swish.swi-prolog.org/p/glue2.p.swinb

Can’t run my code:

image

How give permission, to it? Is it unsafe for some reason?

What would be also swell, if we could have easy
text coloring. How can I do the following:

prove(F) :-
   prove(F,P), !,
   tag('<span style="color: red">'), show(P, 0'x), tag('</span>'),
   write(':'),
   tag('<span style="color: blue">'), write(F), tag('</span>'), nl.

It allows me to do using a library(misc/markup):

image

But how do this in SWISH? Does the server provide some sort of
tag/1 predicate to control the output by injecting the span HTML
element, which we can then use to submit a

CSS-style attribute from the SWISH server to the SWISH client?

Don’t know the whole answer but a possible place to start is library(http/html_write). Using DCG html//1:

?- html(span(style("color:red"), ["\\x: \\y:y*x"]),Out,[]), print_html(Out).
<span style="color:red">\x: \y:y*x</span>
Out = [<, span, ' ', style, '="', "color:red", '"', >, "\\x: \\y:y*x", </, span, >].

Unfortunately when running this on SWISH resulted in:

Sandbox restriction!
Could not derive which predicate may be called fromSearch space too large

but that may be fixable.

I would hope that using print_html/1 on SWISH would properly render the HTML.

I see. But is there a way to stream HTML elements? Now
that Jan W. has implemented event coalescing?

See this other thread:

SWISH - slow printing and missing toplevel bindings
https://swi-prolog.discourse.group/t/swish-slow-printing-and-missing-toplevel-bindings/7490/11

Perhaps I missing your point, but I would think you could use html//1 to produce all of the html tokens for the proof so that only a single output “event” is required.

But I’m out of my depth here as I use DCG’s very little and generate html even less.

(Nothing of importance)

(Nothing of importance)

FWIW, you can have a class in the CSS and then add or remove it dynamically (or you can specify the class= attribute in the tag).

For example, I have this in my CSS file:

.src_hilite {
    background-color: gold;
    cursor: pointer;
}

and then use <div class=src_hilite> to turn it on. (I also do this dynamically using JavaScript; presumably it could also be done with Prolog, but I haven’t yet converted my JavaScript code to Prolog.)

I think that there’s a way to dynamically add CSS items, but I don’t know the details – there’s a “CSSOM” in the DOM, so presumably items can be dynamically added to it.

(Nothing of importance)