Last active
February 8, 2025 15:27
-
-
Save attakei/2aee35dbffc8509fb4dc04d182fa82ad to your computer and use it in GitHub Desktop.
Example of redering HTML from PyScript with docutils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script defer src="https://pyscript.net/alpha/pyscript.js"></script> | |
<py-env> | |
- docutils | |
- BeautifulSoup4 | |
</py-env> | |
<py-script output="output"> | |
from bs4 import BeautifulSoup | |
from docutils.core import publish_string | |
from js import document | |
source = """ | |
Hello world | |
=========== | |
Overview | |
-------- | |
This is example to render HTML from reST source by with PyScript with docutils. | |
List definition | |
--------------- | |
* Bullet one | |
* Bullet two | |
""" | |
out = publish_string(source=source, writer_name="html5") | |
soup = BeautifulSoup(out, "html.parser") | |
document.querySelector("#loading").remove() | |
print("\n".join([str(elm) for elm in soup.main.children])) | |
</py-script> | |
</head> | |
<body> | |
<main> | |
<div id="output" class="content"> | |
<p id="loading">Please wait...</p> | |
</div> | |
</main> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment