Skip to content

Instantly share code, notes, and snippets.

@attakei
Last active May 8, 2022 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save attakei/2aee35dbffc8509fb4dc04d182fa82ad to your computer and use it in GitHub Desktop.
Save attakei/2aee35dbffc8509fb4dc04d182fa82ad to your computer and use it in GitHub Desktop.
Example of redering HTML from PyScript with docutils
<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