question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] print() doesn't output HTML tags.

See original GitHub issue

print() doesn’t output HTML tags I was experimenting in Pyscript and I tried to print an HTML table, but it didn’t work. It seems to delete the tags and mantain just the plain text.

This is the code that I tried, but it just printed “test” once:

<py-script>
print("<table>")
for i in range (2):
    print("<tr>")
    for j in range (2):
        print("<td>test</td>")
    print("</tr>")
print("</table>")
</py-script>

And this is a screenshot I took of the output: image

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
fpligercommented, May 24, 2022

The “right” or “wrong” to this will always depend on what the use case is. Sometimes you’ll want escaped output and sometimes you won’t.

We just merged #439 which is slightly related to the topic, and here’s a PR that relates to the topic as well but ultimately we need to design a way for users to opt-in/out escaping . At least at the element (<py-script>, <py-repl>) level).

I’m in favor of trying to address this sooner rather than later.

/cc @philippjfr

1reaction
furascommented, May 21, 2022

Some workaround is to use some replacement for tags in text - ie. use {{ }} instead of < > and later replace it back with < >

print( "{{b}}Hello World{{/b}}".replace("{{", "<").replace("}}", ">") )
print( "{{h1}}Hello World{{/h1}}".replace("{{", "<").replace("}}", ">") )

or more universal - using function for this

def HTML(text):
     return text.replace("{{", "<").replace("}}", ">")

print( HTML("{{b}}Hello World{{/b}}") )
print( HTML("{{h1}}Hello World{{/h1}}) )

pyscript.write(some_id, HTML("{{h1}}Hello World{{/h1}}) )

document.getElementById(some_id).innerHTML = HTML("{{h1}}Hello World{{/h1}})
Read more comments on GitHub >

github_iconTop Results From Across the Web

res.write not working properly. It's showing output including ...
But I am getting different output than expected. My output contains text including HTML tags. Here's my code. const express = require('express'); ...
Read more >
problem with out.print and jstl - Oracle Communities
when i print a jstl tag using the out.print() the tag is not rendered but when i view the html source in browser...
Read more >
1.5 Print broke - shows html tags in Reporting | Telerik Forums
Since the new printing is based on the Image report rendering engine, it cannot render HTML. So this seems to be a kind...
Read more >
Debugging HTML - Learn web development | MDN
Let's review the problems: The paragraph and list item elements have no closing tags. Looking at the image above, this doesn't seem to...
Read more >
HTML text format doesn't work in view print preview - Get help
I'm using the html() function in formulas to make selected text bold ... shots of the formula text with html code, and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found