htmltabletomd


Namehtmltabletomd JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/vsavo/htmltabletomd
SummaryConvert html table to markdown table
upload_time2021-03-14 02:21:45
maintainer
docs_urlNone
authorVijeyraj Savoundiraradjou
requires_python>=3.6.1
licenseMIT
keywords markdown tables
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # htmltabletomd

`htmltabletomd` is for converting html tables to markdown.
Additionally, contents inside table cells can be converted to markdown if they contain HTML, 
for which it uses the library `htmltomarkdown` .

## Installation

`pip install htmltabletomd`

## Usage

### Convert HTML table to Markdown table
```python
import htmltabletomd

html_table = """<table>
  <tr>
    <th>Heading 1</th>
    <th>Heading 2</th>
  </tr>
  <tr>
    <td>column 11</td>
    <td>column 12</td>
  </tr>
  <tr>
    <td>column 21</td>
    <td>column 22</td>
  </tr>
</table>
"""

md_table = htmltabletomd.convert_table(html_table)
print(md_table)
```

Output:

```
| Heading 1 | Heading 2 |
| :--- | :--- |
| column 11 | column 12 |
| column 21 | column 22 |
```

### Pass `all_cols_alignment` argument to align text in the columns to the left, right, or center

For the above html table...

```python
md_table = htmltabletomd.convert_table(html_table, all_cols_alignment="right")
print(md_table)
```

Output:

```
| Heading 1 | Heading 2 |
| ---: | ---: |
| column 11 | column 12 |
| column 21 | column 22 |
```

Allowed values: `left`, `right` or `center`.

### Pass `content_conversion_ind` argument to convert html contents inside the table cells to markdown

```python
import htmltabletomd

html_table = """
<table>
  <tr>
    <th>Heading <b>1</b></th>
    <th>Heading <b>2</b></th>
  </tr>
  <tr>
    <td>column <i>11</i></td>
    <td>column <b>12</b></td>
  </tr>
  <tr>
    <td>column 21</td>
    <td>column <b><i>22</i></b></td>
  </tr>
</table>
"""

md_table = htmltabletomd.convert_table(html_table, content_conversion_ind=True)
print(md_table)
```

Output:

```
| Heading __1__ | Heading __2__ |
| :--- | :--- |
| column _11_ | column __12__ |
| column 21 | column ___22___ |
```
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/vsavo/htmltabletomd",
    "name": "htmltabletomd",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6.1",
    "maintainer_email": "",
    "keywords": "markdown tables",
    "author": "Vijeyraj Savoundiraradjou",
    "author_email": "vijeysavy@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/a9/e4/0aaa9345b9c013a0b71ee1526d561dcae08530087034c59d09abb5b86fe1/htmltabletomd-1.0.0.tar.gz",
    "platform": "",
    "description": "# htmltabletomd\n\n`htmltabletomd` is for converting html tables to markdown.\nAdditionally, contents inside table cells can be converted to markdown if they contain HTML, \nfor which it uses the library `htmltomarkdown` .\n\n## Installation\n\n`pip install htmltabletomd`\n\n## Usage\n\n### Convert HTML table to Markdown table\n```python\nimport htmltabletomd\n\nhtml_table = \"\"\"<table>\n  <tr>\n    <th>Heading 1</th>\n    <th>Heading 2</th>\n  </tr>\n  <tr>\n    <td>column 11</td>\n    <td>column 12</td>\n  </tr>\n  <tr>\n    <td>column 21</td>\n    <td>column 22</td>\n  </tr>\n</table>\n\"\"\"\n\nmd_table = htmltabletomd.convert_table(html_table)\nprint(md_table)\n```\n\nOutput:\n\n```\n| Heading 1 | Heading 2 |\n| :--- | :--- |\n| column 11 | column 12 |\n| column 21 | column 22 |\n```\n\n### Pass `all_cols_alignment` argument to align text in the columns to the left, right, or center\n\nFor the above html table...\n\n```python\nmd_table = htmltabletomd.convert_table(html_table, all_cols_alignment=\"right\")\nprint(md_table)\n```\n\nOutput:\n\n```\n| Heading 1 | Heading 2 |\n| ---: | ---: |\n| column 11 | column 12 |\n| column 21 | column 22 |\n```\n\nAllowed values: `left`, `right` or `center`.\n\n### Pass `content_conversion_ind` argument to convert html contents inside the table cells to markdown\n\n```python\nimport htmltabletomd\n\nhtml_table = \"\"\"\n<table>\n  <tr>\n    <th>Heading <b>1</b></th>\n    <th>Heading <b>2</b></th>\n  </tr>\n  <tr>\n    <td>column <i>11</i></td>\n    <td>column <b>12</b></td>\n  </tr>\n  <tr>\n    <td>column 21</td>\n    <td>column <b><i>22</i></b></td>\n  </tr>\n</table>\n\"\"\"\n\nmd_table = htmltabletomd.convert_table(html_table, content_conversion_ind=True)\nprint(md_table)\n```\n\nOutput:\n\n```\n| Heading __1__ | Heading __2__ |\n| :--- | :--- |\n| column _11_ | column __12__ |\n| column 21 | column ___22___ |\n```",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Convert html table to markdown table",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/vsavo/htmltabletomd"
    },
    "split_keywords": [
        "markdown",
        "tables"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a9e40aaa9345b9c013a0b71ee1526d561dcae08530087034c59d09abb5b86fe1",
                "md5": "6d2f7e8c8a6f1db4b3b177f4af0bff4e",
                "sha256": "53e16a63fe97cdf28393dcff01d265bbe675447eac15737bf5823641e6cfa82b"
            },
            "downloads": -1,
            "filename": "htmltabletomd-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6d2f7e8c8a6f1db4b3b177f4af0bff4e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6.1",
            "size": 3801,
            "upload_time": "2021-03-14T02:21:45",
            "upload_time_iso_8601": "2021-03-14T02:21:45.031068Z",
            "url": "https://files.pythonhosted.org/packages/a9/e4/0aaa9345b9c013a0b71ee1526d561dcae08530087034c59d09abb5b86fe1/htmltabletomd-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-03-14 02:21:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vsavo",
    "github_project": "htmltabletomd",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "htmltabletomd"
}
        
Elapsed time: 1.04730s