simple-html-table


Namesimple-html-table JSON
Version 0.2.0 PyPI version JSON
download
home_page
SummarySimple way to create HTML tables with support for rowspan and colspan attributes.
upload_time2023-07-26 19:22:37
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT
keywords html table
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # simple_html_table

Simple way to create HTML tables with support for rowspan and colspan attributes.

## Usage

simple_html_table defines three classes that represent HTML tables, rows and cells respectively. To use the module,
create a Table instance and pass it a 2D numpy array of strings, or a callable that will take Cell objects and return
strings.:

    from simple_html_table import Table

    contents = [
        ["Head 1", "Head 2", "Head 3", "Head 4"],
        ["(1,1)", "(1,2)", "(1,3)", "(1,4)"],
        ["(2,1)", "(2,2)", "(2,3)", "(2,4)"],
    ]

    table = Table((3, 4), table_contents=np.array(contents))

    table[1, 1].colspan = 2
    table[0, 0].rowspan = 3
    table[0, 1].attrs_dict.update({"style": "{ background: red; }"})
    table[0].header = True
    for cell in table[0]:
        cell.classes = "table_th"

    result = table.render()
    print(result,"\n")

    def content_func(cell: Cell) -> str:
        """Callback function to fill in the table."""
        row, col = cell.location
        return contents[row][col]

    table2 = Table((3, 4), table_contents=content_func)
    result = table2.render()
    print(result)


### Output

>
    <table class='html_table'>
    	<tr class='html_tr'>
    		<th class='table_th' rowspan=3>Head 1</th>
    		<th class='table_th' style='{ background: red; }'>Head 2</th>
    		<th class='table_th'>Head 3</th>
    		<th class='table_th'>Head 4</th>
    	</tr>
    	<tr class='html_tr'>
    		<td class='html_td' colspan=2>(1,2)</td>
    		<td class='html_td'>(1,4)</td>
    	</tr>
    	<tr class='html_tr'>
    		<td class='html_td'>(2,2)</td>
    		<td class='html_td'>(2,3)</td>
    		<td class='html_td'>(2,4)</td>
    	</tr>
    </table>

    <table class='html_table'>
    	<tr class='html_tr'>
    		<td class='html_td'>Head 1</td>
    		<td class='html_td'>Head 2</td>
    		<td class='html_td'>Head 3</td>
    		<td class='html_td'>Head 4</td>
    	</tr>
    	<tr class='html_tr'>
    		<td class='html_td'>(1,1)</td>
    		<td class='html_td'>(1,2)</td>
    		<td class='html_td'>(1,3)</td>
    		<td class='html_td'>(1,4)</td>
    	</tr>
    	<tr class='html_tr'>
    		<td class='html_td'>(2,1)</td>
    		<td class='html_td'>(2,2)</td>
    		<td class='html_td'>(2,3)</td>
    		<td class='html_td'>(2,4)</td>
    	</tr>
    </table>

Table and Row objects implement mutable sequence interfaces, so can be indexed. A Table will except being indexed with
a single integer to return a Row or with a tuple of two integers to return a Cell. A Row can be indexed to return Cell
instances.

Cells know which Row they belong to and Tows know which Table they belong to. This means copying Cells and Rows will
probably mess up unless you explicitly reset the pointers.

Colpan and Rowpans are implemented simply by storing references to the same Cell objects within the Row objects - as a
result, it is always possible to index the Table, but the Cell returned may think it belongs to a different row and
column within the table.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "simple-html-table",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "html,table",
    "author": "",
    "author_email": "Gavin Burnell <g.burnell@leeds.ac.uk>",
    "download_url": "https://files.pythonhosted.org/packages/54/60/3ad7ee26296a598ab3fab7a06abf844ea17d9d518b3418b859d61c904634/simple_html_table-0.2.0.tar.gz",
    "platform": null,
    "description": "# simple_html_table\r\n\r\nSimple way to create HTML tables with support for rowspan and colspan attributes.\r\n\r\n## Usage\r\n\r\nsimple_html_table defines three classes that represent HTML tables, rows and cells respectively. To use the module,\r\ncreate a Table instance and pass it a 2D numpy array of strings, or a callable that will take Cell objects and return\r\nstrings.:\r\n\r\n    from simple_html_table import Table\r\n\r\n    contents = [\r\n        [\"Head 1\", \"Head 2\", \"Head 3\", \"Head 4\"],\r\n        [\"(1,1)\", \"(1,2)\", \"(1,3)\", \"(1,4)\"],\r\n        [\"(2,1)\", \"(2,2)\", \"(2,3)\", \"(2,4)\"],\r\n    ]\r\n\r\n    table = Table((3, 4), table_contents=np.array(contents))\r\n\r\n    table[1, 1].colspan = 2\r\n    table[0, 0].rowspan = 3\r\n    table[0, 1].attrs_dict.update({\"style\": \"{ background: red; }\"})\r\n    table[0].header = True\r\n    for cell in table[0]:\r\n        cell.classes = \"table_th\"\r\n\r\n    result = table.render()\r\n    print(result,\"\\n\")\r\n\r\n    def content_func(cell: Cell) -> str:\r\n        \"\"\"Callback function to fill in the table.\"\"\"\r\n        row, col = cell.location\r\n        return contents[row][col]\r\n\r\n    table2 = Table((3, 4), table_contents=content_func)\r\n    result = table2.render()\r\n    print(result)\r\n\r\n\r\n### Output\r\n\r\n>\r\n    <table class='html_table'>\r\n    \t<tr class='html_tr'>\r\n    \t\t<th class='table_th' rowspan=3>Head 1</th>\r\n    \t\t<th class='table_th' style='{ background: red; }'>Head 2</th>\r\n    \t\t<th class='table_th'>Head 3</th>\r\n    \t\t<th class='table_th'>Head 4</th>\r\n    \t</tr>\r\n    \t<tr class='html_tr'>\r\n    \t\t<td class='html_td' colspan=2>(1,2)</td>\r\n    \t\t<td class='html_td'>(1,4)</td>\r\n    \t</tr>\r\n    \t<tr class='html_tr'>\r\n    \t\t<td class='html_td'>(2,2)</td>\r\n    \t\t<td class='html_td'>(2,3)</td>\r\n    \t\t<td class='html_td'>(2,4)</td>\r\n    \t</tr>\r\n    </table>\r\n\r\n    <table class='html_table'>\r\n    \t<tr class='html_tr'>\r\n    \t\t<td class='html_td'>Head 1</td>\r\n    \t\t<td class='html_td'>Head 2</td>\r\n    \t\t<td class='html_td'>Head 3</td>\r\n    \t\t<td class='html_td'>Head 4</td>\r\n    \t</tr>\r\n    \t<tr class='html_tr'>\r\n    \t\t<td class='html_td'>(1,1)</td>\r\n    \t\t<td class='html_td'>(1,2)</td>\r\n    \t\t<td class='html_td'>(1,3)</td>\r\n    \t\t<td class='html_td'>(1,4)</td>\r\n    \t</tr>\r\n    \t<tr class='html_tr'>\r\n    \t\t<td class='html_td'>(2,1)</td>\r\n    \t\t<td class='html_td'>(2,2)</td>\r\n    \t\t<td class='html_td'>(2,3)</td>\r\n    \t\t<td class='html_td'>(2,4)</td>\r\n    \t</tr>\r\n    </table>\r\n\r\nTable and Row objects implement mutable sequence interfaces, so can be indexed. A Table will except being indexed with\r\na single integer to return a Row or with a tuple of two integers to return a Cell. A Row can be indexed to return Cell\r\ninstances.\r\n\r\nCells know which Row they belong to and Tows know which Table they belong to. This means copying Cells and Rows will\r\nprobably mess up unless you explicitly reset the pointers.\r\n\r\nColpan and Rowpans are implemented simply by storing references to the same Cell objects within the Row objects - as a\r\nresult, it is always possible to index the Table, but the Cell returned may think it belongs to a different row and\r\ncolumn within the table.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Simple way to create HTML tables with support for rowspan and colspan attributes.",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/gb119/simple_html_table"
    },
    "split_keywords": [
        "html",
        "table"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "19904b06e7c802788b1e051abb9673ea97a39a14c7d02ef0c28db1de45a674dd",
                "md5": "678fd9947750776bc432a29eed49a5fe",
                "sha256": "baebafa83ab43e47e6e739895a64e4b047df1a72528ae60c234e212f8d02ab69"
            },
            "downloads": -1,
            "filename": "simple_html_table-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "678fd9947750776bc432a29eed49a5fe",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 8130,
            "upload_time": "2023-07-26T19:22:35",
            "upload_time_iso_8601": "2023-07-26T19:22:35.890711Z",
            "url": "https://files.pythonhosted.org/packages/19/90/4b06e7c802788b1e051abb9673ea97a39a14c7d02ef0c28db1de45a674dd/simple_html_table-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "54603ad7ee26296a598ab3fab7a06abf844ea17d9d518b3418b859d61c904634",
                "md5": "97bc0a496843a89ac2d1ffc215e5bf14",
                "sha256": "8cee525c3df8e96f5120348ccc3588cfc4a29e63d87e8c591eb81e24d3a1e151"
            },
            "downloads": -1,
            "filename": "simple_html_table-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "97bc0a496843a89ac2d1ffc215e5bf14",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 10264,
            "upload_time": "2023-07-26T19:22:37",
            "upload_time_iso_8601": "2023-07-26T19:22:37.266328Z",
            "url": "https://files.pythonhosted.org/packages/54/60/3ad7ee26296a598ab3fab7a06abf844ea17d9d518b3418b859d61c904634/simple_html_table-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-26 19:22:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gb119",
    "github_project": "simple_html_table",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "simple-html-table"
}
        
Elapsed time: 0.13127s