From 8c90f10aaa3b0478e51ccf9b81b53d26b3597d0a Mon Sep 17 00:00:00 2001 From: Chaitanya Date: Thu, 20 Jun 2024 03:46:04 +0530 Subject: [PATCH] PyScript Integrated Component --- _ext/pyscript.py | 49 ++++++++++++++++++++++++++++++++++++++++ _sources/index.rst | 3 ++- _sources/pyComponent.rst | 7 ++++++ conf.py | 3 ++- 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 _ext/pyscript.py create mode 100644 _sources/pyComponent.rst diff --git a/_ext/pyscript.py b/_ext/pyscript.py new file mode 100644 index 0000000000..e3320596d7 --- /dev/null +++ b/_ext/pyscript.py @@ -0,0 +1,49 @@ +from docutils import nodes +from docutils.parsers.rst import Directive + + +class PyScriptDirective(Directive): + has_content = True + + def run(self): + self.assert_has_content() + code = '\n'.join(self.content) + + # Create the necessary HTML and JavaScript code for the PyScript + html = f''' +
+ +
+ ''' + + # Create a raw node that will contain the HTML and JavaScript code + raw_node = nodes.raw('', html, format='html') + + return [raw_node] + + +def setup(app): + app.add_directive('pyscript', PyScriptDirective) \ No newline at end of file diff --git a/_sources/index.rst b/_sources/index.rst index f78eb8314d..280c2fa229 100644 --- a/_sources/index.rst +++ b/_sources/index.rst @@ -31,4 +31,5 @@ Contenidos: :maxdepth: 1 index_es - index_en \ No newline at end of file + index_en + pyComponent \ No newline at end of file diff --git a/_sources/pyComponent.rst b/_sources/pyComponent.rst new file mode 100644 index 0000000000..b76e9274d0 --- /dev/null +++ b/_sources/pyComponent.rst @@ -0,0 +1,7 @@ +------------------- +PyScript Component +------------------- + +.. pyscript:: + + print("Hello, World!") \ No newline at end of file diff --git a/conf.py b/conf.py index 0a68d5a06c..af040df058 100644 --- a/conf.py +++ b/conf.py @@ -17,6 +17,7 @@ # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # sys.path.insert(0, os.path.abspath('../modules')) +sys.path.insert(0, os.path.abspath('_ext')) from runestone import runestone_static_dirs, runestone_extensions, setup import pkg_resources @@ -28,7 +29,7 @@ # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ["sphinx.ext.mathjax"] + runestone_extensions() +extensions = ["sphinx.ext.mathjax", "pyscript"] + runestone_extensions() # ,'runestone.video','runestone.reveal','runestone.poll','runestone.tabbedStuff','runestone.disqus','runestone.codelens','runestone.activecode', 'runestone.assess', 'runestone.animation','runestone.meta', 'runestone.parsons', 'runestone.blockly', 'runestone.livecode','runestone.accessibility']