├── .gitignore ├── LICENSE ├── README.md ├── REFERENCE.txt ├── dev-requirements.txt ├── pyodide_html └── __init__.py ├── scripts └── update_docs.py └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 98 | __pypackages__/ 99 | 100 | # Celery stuff 101 | celerybeat-schedule 102 | celerybeat.pid 103 | 104 | # SageMath parsed files 105 | *.sage.py 106 | 107 | # Environments 108 | .env 109 | .venv 110 | env/ 111 | venv/ 112 | ENV/ 113 | env.bak/ 114 | venv.bak/ 115 | 116 | # Spyder project settings 117 | .spyderproject 118 | .spyproject 119 | 120 | # Rope project settings 121 | .ropeproject 122 | 123 | # mkdocs documentation 124 | /site 125 | 126 | # mypy 127 | .mypy_cache/ 128 | .dmypy.json 129 | dmypy.json 130 | 131 | # Pyre type checker 132 | .pyre/ 133 | 134 | # pytype static type analyzer 135 | .pytype/ 136 | 137 | # Cython debug symbols 138 | cython_debug/ 139 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Xing Han Lu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pyodide HTML 2 | 3 | HTML elements for `pyodide`, implemented as Python functions. 4 | 5 | ## Quickstart 6 | 7 | ```python 8 | import micropip 9 | 10 | micropip.install('pyodide-html') 11 | 12 | import pyodide_html as html 13 | 14 | ele = html.h1('Hello, world!') 15 | 16 | js.document.body.appendChild(ele) 17 | ``` 18 | 19 | ## Motivation 20 | 21 | In `pyodide`, you can create HTML elements using `js.document`, but it is extremely verbose. For example, a range input would look like: 22 | ```python 23 | import js 24 | 25 | ele = js.document.createElement('input') 26 | ele.type = 'range' 27 | ele.min = 0 28 | ele.max = 50 29 | ele.value = 25 30 | ele.step = 1 31 | ``` 32 | 33 | With `pyodide_html`, you can do all this with a single function call: 34 | ```python 35 | import pyodide_html as html 36 | 37 | ele = html.input(type="range", min=0, max=50, value=25, step=1) 38 | ``` 39 | 40 | ## Usage 41 | 42 | All the [HTML tags](https://developer.mozilla.org/en-US/docs/Web/HTML/Element) are implemented as Python functions. For example, `html.h1` creates a `

` element, `html.input` creates an `` element, and so on. 43 | 44 | The signature of the function is: 45 | ```python 46 | html.element(*children, **props) 47 | ``` 48 | 49 | which is equivalent to calling `*children`. 50 | 51 | Every element has an `add` method that lets you add new, or update existing children or props. It has the following signature: 52 | ```python 53 | html.element(*children, **props).add(*children, **props) 54 | ``` 55 | 56 | This is convenient if you want to initialize an element with certain `props`, then add/update the `children` or `props` later using `add`. For example: 57 | 58 | ```python 59 | import pyodide_html as html 60 | 61 | # initialize your element 62 | ele = html.div(className="container") 63 | 64 | # Add children 65 | ele.add( 66 | html.h1("My header"), 67 | html.p("Some paragraph here"), 68 | # ... 69 | ) 70 | 71 | # You can add new props: 72 | ele.add(style="background-color: lightgray") 73 | 74 | # You can also update existing props: 75 | ele.add(style="background-color: lightblue") 76 | ``` 77 | 78 | You can also chain `add` calls: 79 | ```python 80 | ele.add(style="...").add(className="...").add(html.div("a child")) 81 | ``` 82 | 83 | Note that `add` modifies an element in-place. 84 | 85 | ## Documentation 86 | 87 | See [REFERENCE.txt](./REFERENCE.txt) ([GitHub Link](https://github.com/xhlulu/pyodide-html/blob/main/REFERENCE.txt)) for the API reference. 88 | 89 | ## Contributing/Development 90 | 91 | After cloning this repo, start with: 92 | ``` 93 | pip install -r dev-requirements.txt 94 | ``` 95 | 96 | You can then make the desired changes -------------------------------------------------------------------------------- /REFERENCE.txt: -------------------------------------------------------------------------------- 1 | Python Library Documentation: package pyodide_html 2 | 3 | NAME 4 | pyodide_html 5 | 6 | PACKAGE CONTENTS 7 | 8 | 9 | FUNCTIONS 10 | a(*children, **props) 11 | Creates the 'a' HTML element. It's equivalent to calling '*children'. 12 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 13 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a 14 | 15 | abbr(*children, **props) 16 | Creates the 'abbr' HTML element. It's equivalent to calling '*children'. 17 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 18 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/abbr 19 | 20 | address(*children, **props) 21 | Creates the 'address' HTML element. It's equivalent to calling '
*children
'. 22 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 23 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/address 24 | 25 | area(*children, **props) 26 | Creates the 'area' HTML element. It's equivalent to calling '*children'. 27 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 28 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/area 29 | 30 | article(*children, **props) 31 | Creates the 'article' HTML element. It's equivalent to calling '
*children
'. 32 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 33 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/article 34 | 35 | aside(*children, **props) 36 | Creates the 'aside' HTML element. It's equivalent to calling ''. 37 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 38 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/aside 39 | 40 | audio(*children, **props) 41 | Creates the 'audio' HTML element. It's equivalent to calling ''. 42 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 43 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio 44 | 45 | b(*children, **props) 46 | Creates the 'b' HTML element. It's equivalent to calling '*children'. 47 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 48 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/b 49 | 50 | bdi(*children, **props) 51 | Creates the 'bdi' HTML element. It's equivalent to calling '*children'. 52 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 53 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/bdi 54 | 55 | bdo(*children, **props) 56 | Creates the 'bdo' HTML element. It's equivalent to calling '*children'. 57 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 58 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/bdo 59 | 60 | blockquote(*children, **props) 61 | Creates the 'blockquote' HTML element. It's equivalent to calling '
*children
'. 62 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 63 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/blockquote 64 | 65 | body(*children, **props) 66 | Creates the 'body' HTML element. It's equivalent to calling '*children'. 67 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 68 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body 69 | 70 | br(*children, **props) 71 | Creates the 'br' HTML element. It's equivalent to calling '
*children
'. 72 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 73 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/br 74 | 75 | build_element(tag) 76 | Builds an element from a tag name. 77 | 78 | button(*children, **props) 79 | Creates the 'button' HTML element. It's equivalent to calling ''. 80 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 81 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button 82 | 83 | canvas(*children, **props) 84 | Creates the 'canvas' HTML element. It's equivalent to calling '*children'. 85 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 86 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas 87 | 88 | caption(*children, **props) 89 | Creates the 'caption' HTML element. It's equivalent to calling '*children'. 90 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 91 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption 92 | 93 | cite(*children, **props) 94 | Creates the 'cite' HTML element. It's equivalent to calling '*children'. 95 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 96 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/cite 97 | 98 | code(*children, **props) 99 | Creates the 'code' HTML element. It's equivalent to calling '*children'. 100 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 101 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/code 102 | 103 | col(*children, **props) 104 | Creates the 'col' HTML element. It's equivalent to calling '*children'. 105 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 106 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/col 107 | 108 | colgroup(*children, **props) 109 | Creates the 'colgroup' HTML element. It's equivalent to calling '*children'. 110 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 111 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/colgroup 112 | 113 | data(*children, **props) 114 | Creates the 'data' HTML element. It's equivalent to calling '*children'. 115 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 116 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/data 117 | 118 | datalist(*children, **props) 119 | Creates the 'datalist' HTML element. It's equivalent to calling '*children'. 120 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 121 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist 122 | 123 | dd(*children, **props) 124 | Creates the 'dd' HTML element. It's equivalent to calling '
*children
'. 125 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 126 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dd 127 | 128 | del(*children, **props) 129 | Creates the 'del' HTML element. It's equivalent to calling '*children'. 130 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 131 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/del 132 | 133 | details(*children, **props) 134 | Creates the 'details' HTML element. It's equivalent to calling '
*children
'. 135 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 136 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details 137 | 138 | dfn(*children, **props) 139 | Creates the 'dfn' HTML element. It's equivalent to calling '*children'. 140 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 141 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dfn 142 | 143 | dialog(*children, **props) 144 | Creates the 'dialog' HTML element. It's equivalent to calling '*children'. 145 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 146 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog 147 | 148 | div(*children, **props) 149 | Creates the 'div' HTML element. It's equivalent to calling '
*children
'. 150 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 151 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div 152 | 153 | dl(*children, **props) 154 | Creates the 'dl' HTML element. It's equivalent to calling '
*children
'. 155 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 156 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dl 157 | 158 | dt(*children, **props) 159 | Creates the 'dt' HTML element. It's equivalent to calling '
*children
'. 160 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 161 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dt 162 | 163 | em(*children, **props) 164 | Creates the 'em' HTML element. It's equivalent to calling '*children'. 165 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 166 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/em 167 | 168 | embed(*children, **props) 169 | Creates the 'embed' HTML element. It's equivalent to calling '*children'. 170 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 171 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed 172 | 173 | fieldset(*children, **props) 174 | Creates the 'fieldset' HTML element. It's equivalent to calling '
*children
'. 175 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 176 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/fieldset 177 | 178 | figcaption(*children, **props) 179 | Creates the 'figcaption' HTML element. It's equivalent to calling '
*children
'. 180 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 181 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figcaption 182 | 183 | figure(*children, **props) 184 | Creates the 'figure' HTML element. It's equivalent to calling '
*children
'. 185 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 186 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/figure 187 | 188 | footer(*children, **props) 189 | Creates the 'footer' HTML element. It's equivalent to calling ''. 190 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 191 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/footer 192 | 193 | form(*children, **props) 194 | Creates the 'form' HTML element. It's equivalent to calling '
*children
'. 195 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 196 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form 197 | 198 | h1(*children, **props) 199 | Creates the 'h1' HTML element. It's equivalent to calling '

*children

'. 200 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 201 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h1 202 | 203 | h2(*children, **props) 204 | Creates the 'h2' HTML element. It's equivalent to calling '

*children

'. 205 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 206 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h2 207 | 208 | h3(*children, **props) 209 | Creates the 'h3' HTML element. It's equivalent to calling '

*children

'. 210 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 211 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h3 212 | 213 | h4(*children, **props) 214 | Creates the 'h4' HTML element. It's equivalent to calling '

*children

'. 215 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 216 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h4 217 | 218 | h5(*children, **props) 219 | Creates the 'h5' HTML element. It's equivalent to calling '
*children
'. 220 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 221 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h5 222 | 223 | h6(*children, **props) 224 | Creates the 'h6' HTML element. It's equivalent to calling '
*children
'. 225 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 226 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h6 227 | 228 | head(*children, **props) 229 | Creates the 'head' HTML element. It's equivalent to calling '*children'. 230 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 231 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head 232 | 233 | header(*children, **props) 234 | Creates the 'header' HTML element. It's equivalent to calling '
*children
'. 235 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 236 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/header 237 | 238 | hr(*children, **props) 239 | Creates the 'hr' HTML element. It's equivalent to calling '
*children'. 240 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 241 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/hr 242 | 243 | i(*children, **props) 244 | Creates the 'i' HTML element. It's equivalent to calling '*children'. 245 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 246 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/i 247 | 248 | iframe(*children, **props) 249 | Creates the 'iframe' HTML element. It's equivalent to calling ''. 250 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 251 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe 252 | 253 | img(*children, **props) 254 | Creates the 'img' HTML element. It's equivalent to calling '*children'. 255 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 256 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img 257 | 258 | input(*children, **props) 259 | Creates the 'input' HTML element. It's equivalent to calling '*children'. 260 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 261 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input 262 | 263 | ins(*children, **props) 264 | Creates the 'ins' HTML element. It's equivalent to calling '*children'. 265 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 266 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ins 267 | 268 | js() 269 | 270 | kbd(*children, **props) 271 | Creates the 'kbd' HTML element. It's equivalent to calling '*children'. 272 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 273 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/kbd 274 | 275 | label(*children, **props) 276 | Creates the 'label' HTML element. It's equivalent to calling ''. 277 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 278 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label 279 | 280 | legend(*children, **props) 281 | Creates the 'legend' HTML element. It's equivalent to calling '*children'. 282 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 283 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/legend 284 | 285 | li(*children, **props) 286 | Creates the 'li' HTML element. It's equivalent to calling '
  • *children
  • '. 287 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 288 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li 289 | 290 | link(*children, **props) 291 | Creates the 'link' HTML element. It's equivalent to calling '*children'. 292 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 293 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link 294 | 295 | main(*children, **props) 296 | Creates the 'main' HTML element. It's equivalent to calling '
    *children
    '. 297 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 298 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/main 299 | 300 | map(*children, **props) 301 | Creates the 'map' HTML element. It's equivalent to calling '*children'. 302 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 303 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/map 304 | 305 | mark(*children, **props) 306 | Creates the 'mark' HTML element. It's equivalent to calling '*children'. 307 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 308 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/mark 309 | 310 | math(*children, **props) 311 | Creates the 'math' HTML element. It's equivalent to calling '*children'. 312 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 313 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/math 314 | 315 | menu(*children, **props) 316 | Creates the 'menu' HTML element. It's equivalent to calling '*children'. 317 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 318 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/menu 319 | 320 | meta(*children, **props) 321 | Creates the 'meta' HTML element. It's equivalent to calling '*children'. 322 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 323 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta 324 | 325 | meter(*children, **props) 326 | Creates the 'meter' HTML element. It's equivalent to calling '*children'. 327 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 328 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meter 329 | 330 | nav(*children, **props) 331 | Creates the 'nav' HTML element. It's equivalent to calling ''. 332 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 333 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/nav 334 | 335 | noscript(*children, **props) 336 | Creates the 'noscript' HTML element. It's equivalent to calling ''. 337 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 338 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript 339 | 340 | object(*children, **props) 341 | Creates the 'object' HTML element. It's equivalent to calling '*children'. 342 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 343 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object 344 | 345 | ol(*children, **props) 346 | Creates the 'ol' HTML element. It's equivalent to calling '
      *children
    '. 347 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 348 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol 349 | 350 | optgroup(*children, **props) 351 | Creates the 'optgroup' HTML element. It's equivalent to calling '*children'. 352 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 353 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/optgroup 354 | 355 | option(*children, **props) 356 | Creates the 'option' HTML element. It's equivalent to calling ''. 357 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 358 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option 359 | 360 | output(*children, **props) 361 | Creates the 'output' HTML element. It's equivalent to calling '*children'. 362 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 363 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/output 364 | 365 | p(*children, **props) 366 | Creates the 'p' HTML element. It's equivalent to calling '

    *children

    '. 367 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 368 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/p 369 | 370 | param(*children, **props) 371 | Creates the 'param' HTML element. It's equivalent to calling '*children'. 372 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 373 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/param 374 | 375 | picture(*children, **props) 376 | Creates the 'picture' HTML element. It's equivalent to calling '*children'. 377 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 378 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture 379 | 380 | portal(*children, **props) 381 | Creates the 'portal' HTML element. It's equivalent to calling '*children'. 382 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 383 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/portal 384 | 385 | pre(*children, **props) 386 | Creates the 'pre' HTML element. It's equivalent to calling '
    *children
    '. 387 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 388 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/pre 389 | 390 | progress(*children, **props) 391 | Creates the 'progress' HTML element. It's equivalent to calling '*children'. 392 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 393 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress 394 | 395 | q(*children, **props) 396 | Creates the 'q' HTML element. It's equivalent to calling '*children'. 397 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 398 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/q 399 | 400 | rp(*children, **props) 401 | Creates the 'rp' HTML element. It's equivalent to calling '*children'. 402 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 403 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rp 404 | 405 | rt(*children, **props) 406 | Creates the 'rt' HTML element. It's equivalent to calling '*children'. 407 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 408 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/rt 409 | 410 | ruby(*children, **props) 411 | Creates the 'ruby' HTML element. It's equivalent to calling '*children'. 412 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 413 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ruby 414 | 415 | s(*children, **props) 416 | Creates the 's' HTML element. It's equivalent to calling '*children'. 417 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 418 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/s 419 | 420 | samp(*children, **props) 421 | Creates the 'samp' HTML element. It's equivalent to calling '*children'. 422 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 423 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/samp 424 | 425 | script(*children, **props) 426 | Creates the 'script' HTML element. It's equivalent to calling ''. 427 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 428 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script 429 | 430 | section(*children, **props) 431 | Creates the 'section' HTML element. It's equivalent to calling '
    *children
    '. 432 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 433 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/section 434 | 435 | select(*children, **props) 436 | Creates the 'select' HTML element. It's equivalent to calling ''. 437 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 438 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select 439 | 440 | slot(*children, **props) 441 | Creates the 'slot' HTML element. It's equivalent to calling '*children'. 442 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 443 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/slot 444 | 445 | small(*children, **props) 446 | Creates the 'small' HTML element. It's equivalent to calling '*children'. 447 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 448 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/small 449 | 450 | source(*children, **props) 451 | Creates the 'source' HTML element. It's equivalent to calling '*children'. 452 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 453 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/source 454 | 455 | span(*children, **props) 456 | Creates the 'span' HTML element. It's equivalent to calling '*children'. 457 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 458 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/span 459 | 460 | strong(*children, **props) 461 | Creates the 'strong' HTML element. It's equivalent to calling '*children'. 462 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 463 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/strong 464 | 465 | style(*children, **props) 466 | Creates the 'style' HTML element. It's equivalent to calling ''. 467 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 468 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style 469 | 470 | sub(*children, **props) 471 | Creates the 'sub' HTML element. It's equivalent to calling '*children'. 472 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 473 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sub 474 | 475 | summary(*children, **props) 476 | Creates the 'summary' HTML element. It's equivalent to calling '*children'. 477 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 478 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/summary 479 | 480 | sup(*children, **props) 481 | Creates the 'sup' HTML element. It's equivalent to calling '*children'. 482 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 483 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/sup 484 | 485 | svg(*children, **props) 486 | Creates the 'svg' HTML element. It's equivalent to calling '*children'. 487 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 488 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/svg 489 | 490 | table(*children, **props) 491 | Creates the 'table' HTML element. It's equivalent to calling '*children
    '. 492 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 493 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table 494 | 495 | tbody(*children, **props) 496 | Creates the 'tbody' HTML element. It's equivalent to calling '*children'. 497 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 498 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody 499 | 500 | td(*children, **props) 501 | Creates the 'td' HTML element. It's equivalent to calling '*children'. 502 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 503 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td 504 | 505 | template(*children, **props) 506 | Creates the 'template' HTML element. It's equivalent to calling ''. 507 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 508 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template 509 | 510 | textarea(*children, **props) 511 | Creates the 'textarea' HTML element. It's equivalent to calling ''. 512 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 513 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea 514 | 515 | tfoot(*children, **props) 516 | Creates the 'tfoot' HTML element. It's equivalent to calling '*children'. 517 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 518 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tfoot 519 | 520 | th(*children, **props) 521 | Creates the 'th' HTML element. It's equivalent to calling '*children'. 522 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 523 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th 524 | 525 | thead(*children, **props) 526 | Creates the 'thead' HTML element. It's equivalent to calling '*children'. 527 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 528 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/thead 529 | 530 | time(*children, **props) 531 | Creates the 'time' HTML element. It's equivalent to calling ''. 532 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 533 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/time 534 | 535 | title(*children, **props) 536 | Creates the 'title' HTML element. It's equivalent to calling '*children'. 537 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 538 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title 539 | 540 | tr(*children, **props) 541 | Creates the 'tr' HTML element. It's equivalent to calling '*children'. 542 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 543 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tr 544 | 545 | track(*children, **props) 546 | Creates the 'track' HTML element. It's equivalent to calling '*children'. 547 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 548 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track 549 | 550 | u(*children, **props) 551 | Creates the 'u' HTML element. It's equivalent to calling '*children'. 552 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 553 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/u 554 | 555 | ul(*children, **props) 556 | Creates the 'ul' HTML element. It's equivalent to calling ''. 557 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 558 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ul 559 | 560 | var(*children, **props) 561 | Creates the 'var' HTML element. It's equivalent to calling '*children'. 562 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 563 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/var 564 | 565 | video(*children, **props) 566 | Creates the 'video' HTML element. It's equivalent to calling ''. 567 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 568 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video 569 | 570 | wbr(*children, **props) 571 | Creates the 'wbr' HTML element. It's equivalent to calling '*children'. 572 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 573 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/wbr -------------------------------------------------------------------------------- /dev-requirements.txt: -------------------------------------------------------------------------------- 1 | -e . 2 | black -------------------------------------------------------------------------------- /pyodide_html/__init__.py: -------------------------------------------------------------------------------- 1 | from textwrap import dedent 2 | 3 | try: 4 | import js 5 | except ImportError: 6 | print( 7 | "Unable to import 'js'. This module will not work without pyodide. Make sure you are importing this inside pyodide and try again." 8 | ) 9 | 10 | def js(): 11 | return "js" 12 | 13 | js.document = lambda: "document" 14 | js.document.createElement = lambda x: (lambda y: "element") 15 | 16 | 17 | def __to_camel_case(snake_str): 18 | components = snake_str.split("_") 19 | # We capitalize the first letter of each component except the first one 20 | # with the 'title' method and join them together. 21 | return components[0] + "".join(x.title() for x in components[1:]) 22 | 23 | 24 | def build_element(tag): 25 | """ 26 | Builds an element from a tag name. 27 | """ 28 | 29 | def add_method(self, *children, **props): 30 | props = {__to_camel_case(k): v for k, v in props.items()} 31 | 32 | for key, value in props.items(): 33 | setattr(self, key, value) 34 | 35 | self.append(*children) 36 | 37 | return self 38 | 39 | def initial_add(*children, **props): 40 | ele = js.document.createElement(tag) 41 | ele.add = add_method.__get__(ele, ele.__class__) 42 | 43 | return ele.add(*children, **props) 44 | 45 | initial_add.__name__ = tag 46 | initial_add.__qualname__ = tag 47 | initial_add.__doc__ = dedent( 48 | f""" 49 | Creates the '{tag}' HTML element. It's equivalent to calling '<{tag} **props>*children'. 50 | Values in `**props` will be converted from 'snake_case' to 'camelCase'. 51 | For more information, please visit: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/{tag} 52 | """ 53 | ) 54 | 55 | return initial_add 56 | 57 | 58 | def __create_tags(): 59 | accepted_tags = ( 60 | "head link meta style title body " 61 | # content sectioning 62 | "address article aside footer header h1 h2 h3 h4 h5 h6 main nav section " 63 | # text content 64 | "blockquote dd div dl dt figcaption figure hr li ol p pre table ul " 65 | # inline text semantics 66 | "a abbr b bdi bdo br cite code data dfn em i kbd mark q rp rt ruby s samp small span strong sub sup time u var wbr " 67 | # image and multimedia 68 | "area audio img map track video " 69 | # embedded content 70 | "embed iframe object param picture portal source " 71 | # svg and mathML 72 | "svg math " 73 | # scripting 74 | "canvas noscript script " 75 | # demarcating edits 76 | "del ins " 77 | # table content 78 | "caption col colgroup table tbody td tfoot th thead tr " 79 | # forms 80 | "button datalist fieldset form input label legend meter optgroup option output progress select textarea " 81 | # interactive elements 82 | "details dialog menu summary " 83 | # web components 84 | "slot template " 85 | ) 86 | 87 | for tag in accepted_tags.strip().split(): 88 | ele = build_element(tag) 89 | globals()[tag] = ele 90 | 91 | 92 | __create_tags() 93 | -------------------------------------------------------------------------------- /scripts/update_docs.py: -------------------------------------------------------------------------------- 1 | import pydoc 2 | 3 | import pyodide_html as html 4 | 5 | 6 | generated = pydoc.render_doc(html, renderer=pydoc.plaintext) 7 | generated = generated.split("\nFILE\n")[0].strip() 8 | 9 | with open("REFERENCE.txt", "w") as f: 10 | f.write(generated) -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | 3 | with open("README.md", "r", encoding="utf-8") as fh: 4 | long_description = fh.read() 5 | 6 | setuptools.setup( 7 | name="pyodide-html", 8 | version="0.1.0", 9 | author="Xing Han Lu", 10 | author_email="github@xinghanlu.com", 11 | description="HTML elements for pyodide, implemented as Python functions", 12 | long_description=long_description, 13 | long_description_content_type="text/markdown", 14 | url="https://github.com/xhlulu/pyodide-html", 15 | classifiers=[ 16 | "Programming Language :: Python :: 3", 17 | "License :: OSI Approved :: MIT License", 18 | "Operating System :: OS Independent", 19 | ], 20 | packages=setuptools.find_packages(), 21 | python_requires=">=3.6", 22 | install_requires=[], 23 | ) 24 | --------------------------------------------------------------------------------