Parcourir la source

add: html output support RequireJS && compatible with IPython.display.HTML

wangweimin il y a 5 ans
Parent
commit
f96f69d10c
4 fichiers modifiés avec 12 ajouts et 2 suppressions
  1. 2 0
      pywebio/html/index.html
  2. 0 0
      pywebio/html/js/require.min.js
  3. 8 2
      pywebio/output.py
  4. 2 0
      setup.py

+ 2 - 0
pywebio/html/index.html

@@ -52,6 +52,8 @@
 
 <script src="js/pywebio.js"></script>
 
+<script src="js/require.min.js"></script> <!-- JS module loader -->
+
 <script>
 
     /*

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
pywebio/html/js/require.min.js


+ 8 - 2
pywebio/output.py

@@ -26,6 +26,7 @@ r"""输出内容到用户浏览器
 --------------
 .. autofunction:: put_text
 .. autofunction:: put_markdown
+.. autofunction:: put_html
 .. autofunction:: put_code
 .. autofunction:: put_table
 .. autofunction:: table_cell_buttons
@@ -161,11 +162,16 @@ def put_text(text, inline=False, anchor=None, before=None, after=None):
 
 def put_html(html, anchor=None, before=None, after=None):
     """
-    输出文本内容
+    输出Html内容。
+
+    与支持通过Html输出内容到 `Jupyter Notebook <https://nbviewer.jupyter.org/github/ipython/ipython/blob/master/examples/IPython%20Kernel/Rich%20Output.ipynb#HTML>` 的库兼容。
 
-    :param str html: html内容
+    :param html: html字符串或 实现了 `IPython.display.HTML` 接口的类的实例
     :param str anchor, before, after: 与 `put_text` 函数的同名参数含义一致
     """
+    if hasattr(html, '__html__'):
+        html = html.__html__()
+
     _put_content('html', content=html, anchor=anchor, before=before, after=after)
 
 

+ 2 - 0
setup.py

@@ -1,4 +1,5 @@
 from setuptools import setup, find_packages
+
 from pywebio import version
 
 setup(
@@ -37,6 +38,7 @@ setup(
             "html/js/bs-custom-file-input.min.js",
             "html/js/popper.min.js",
             "html/js/jquery.toast.min.js",
+            "html/js/require.min.js",
             "html/index_cdn.html",
             "html/index.html",
         ],

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff