prosemirror-py-converter


Nameprosemirror-py-converter JSON
Version 0.3 PyPI version JSON
download
home_pagehttps://github.com/ghnjk/prosemirror-py-converter
SummaryPython simple implementation of converting ProseMirror doc to markdown
upload_time2023-08-28 08:13:13
maintainer
docs_urlNone
authorghnjk
requires_python
licenseMIT
keywords prosemirror markdown pmconverter html python-converter
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # prosemirror-py-converter

[中文指引](https://github.com/ghnjk/prosemirror-py-converter/blob/main/README_CN.md)

Python simple implementation of converting ProseMirror doc to markdown

## Core features

- Based on [ProseMirror basic model](https://prosemirror.net/docs/ref/#model)
- Support custom extension
- ProseMirror document converter: Json to Markdown in ProseMirror format
- Mainly used for data analysis and display after spider ProseMirror documents.

## Quick start

- Install prosemirror-py-converter

```
pip3 install prosemirror-py-converter
```

- Convert ProseMirror document to Markdown

```
from pmconverter import prose2markdown

doc = {
     "type": "doc",
     "content": [
         {
             "type": "heading",
             "attrs": {
                 "level": 3
             },
             "content": [
                 {
                     "type": "text",
                     "text": "Example heading."
                 }
             ]
         }
     ]
}
print(prose2markdown(doc))
```

- output markdown

```
### Example heading.
```

## Standard ProseMirror implementation

- [Standard ProseMirror implementation](https://github.com/ghnjk/prosemirror-py-converter/blob/main/pmconverter/prose_mirror_std_models.py)

### mark type list

- link
- bold
- strong
- code
- italic
- strike
- subscript
- superscript
- underline

### node type list

- doc
- heading
- paragraph
- image
- bullet_list
- ordered_list
- table
- blockquote
- code_block
- hard_break
- horizontal_rule

## Custom ProseMirror extension examples

[iwiki doc converter](https://github.com/ghnjk/prosemirror-py-converter/blob/main/pmconverter/extensions/iwiki_models.py)

- custom mark converter example

```
from pmconverter.basic_model import CommonSimpleMark
from pmconverter.model_factory import register_mark_class


class CustomMark(CommonSimpleMark):

    def __init__(self):
        super().__init__()
        self.type = "custom_mark"
        self.md_pre_mark = "<u>"
        self.md_after_mark = "</u>"


register_mark_class("custom_mark", CustomMark)
```

- custom node converter example

```
from pmconverter.basic_model import Node
from pmconverter.model_factory import register_node_class


class CustomeImage(Node):

    def __init__(self):
        super().__init__()
        self.type = "custom_image"

    def convert_to_markdown(self, **kwargs) -> str:
        name = self.get_attr("name", "")
        url = self.get_attr("url", "")
        return f"![{name}]({url})"
        

register_node_class("custom_image", CustomeImage)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ghnjk/prosemirror-py-converter",
    "name": "prosemirror-py-converter",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "prosemirror markdown pmconverter html python-converter",
    "author": "ghnjk",
    "author_email": "ghnjk@foxmail.com",
    "download_url": "https://files.pythonhosted.org/packages/63/10/f70e032d6cf060c3b1acb4ee517b8fde1643ab34ecbf1862c614e23b5ffd/prosemirror-py-converter-0.3.tar.gz",
    "platform": null,
    "description": "# prosemirror-py-converter\n\n[\u4e2d\u6587\u6307\u5f15](https://github.com/ghnjk/prosemirror-py-converter/blob/main/README_CN.md)\n\nPython simple implementation of converting ProseMirror doc to markdown\n\n## Core features\n\n- Based on [ProseMirror basic model](https://prosemirror.net/docs/ref/#model)\n- Support custom extension\n- ProseMirror document converter: Json to Markdown in ProseMirror format\n- Mainly used for data analysis and display after spider ProseMirror documents.\n\n## Quick start\n\n- Install prosemirror-py-converter\n\n```\npip3 install prosemirror-py-converter\n```\n\n- Convert ProseMirror document to Markdown\n\n```\nfrom pmconverter import prose2markdown\n\ndoc = {\n     \"type\": \"doc\",\n     \"content\": [\n         {\n             \"type\": \"heading\",\n             \"attrs\": {\n                 \"level\": 3\n             },\n             \"content\": [\n                 {\n                     \"type\": \"text\",\n                     \"text\": \"Example heading.\"\n                 }\n             ]\n         }\n     ]\n}\nprint(prose2markdown(doc))\n```\n\n- output markdown\n\n```\n### Example heading.\n```\n\n## Standard ProseMirror implementation\n\n- [Standard ProseMirror implementation](https://github.com/ghnjk/prosemirror-py-converter/blob/main/pmconverter/prose_mirror_std_models.py)\n\n### mark type list\n\n- link\n- bold\n- strong\n- code\n- italic\n- strike\n- subscript\n- superscript\n- underline\n\n### node type list\n\n- doc\n- heading\n- paragraph\n- image\n- bullet_list\n- ordered_list\n- table\n- blockquote\n- code_block\n- hard_break\n- horizontal_rule\n\n## Custom ProseMirror extension examples\n\n[iwiki doc converter](https://github.com/ghnjk/prosemirror-py-converter/blob/main/pmconverter/extensions/iwiki_models.py)\n\n- custom mark converter example\n\n```\nfrom pmconverter.basic_model import CommonSimpleMark\nfrom pmconverter.model_factory import register_mark_class\n\n\nclass CustomMark(CommonSimpleMark):\n\n    def __init__(self):\n        super().__init__()\n        self.type = \"custom_mark\"\n        self.md_pre_mark = \"<u>\"\n        self.md_after_mark = \"</u>\"\n\n\nregister_mark_class(\"custom_mark\", CustomMark)\n```\n\n- custom node converter example\n\n```\nfrom pmconverter.basic_model import Node\nfrom pmconverter.model_factory import register_node_class\n\n\nclass CustomeImage(Node):\n\n    def __init__(self):\n        super().__init__()\n        self.type = \"custom_image\"\n\n    def convert_to_markdown(self, **kwargs) -> str:\n        name = self.get_attr(\"name\", \"\")\n        url = self.get_attr(\"url\", \"\")\n        return f\"![{name}]({url})\"\n        \n\nregister_node_class(\"custom_image\", CustomeImage)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python simple implementation of converting ProseMirror doc to markdown",
    "version": "0.3",
    "project_urls": {
        "Homepage": "https://github.com/ghnjk/prosemirror-py-converter"
    },
    "split_keywords": [
        "prosemirror",
        "markdown",
        "pmconverter",
        "html",
        "python-converter"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c2555885cf8bf51245228b4b90fa9e06a926736d6ab4b00c2dfa0619136deabe",
                "md5": "ae745899044c7c249607c958ff26568c",
                "sha256": "2395eb34bb67a7da44443d89755cd3b7d6b74b615c67b9e2c0187d5056164e84"
            },
            "downloads": -1,
            "filename": "prosemirror_py_converter-0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ae745899044c7c249607c958ff26568c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9459,
            "upload_time": "2023-08-28T08:13:12",
            "upload_time_iso_8601": "2023-08-28T08:13:12.267865Z",
            "url": "https://files.pythonhosted.org/packages/c2/55/5885cf8bf51245228b4b90fa9e06a926736d6ab4b00c2dfa0619136deabe/prosemirror_py_converter-0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6310f70e032d6cf060c3b1acb4ee517b8fde1643ab34ecbf1862c614e23b5ffd",
                "md5": "8d24f55103fe94665bac4e24c58bdb6b",
                "sha256": "650be9881beea21e9ac079dfcdad16c8000339906f9024a92a995b1a67be4283"
            },
            "downloads": -1,
            "filename": "prosemirror-py-converter-0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "8d24f55103fe94665bac4e24c58bdb6b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7787,
            "upload_time": "2023-08-28T08:13:13",
            "upload_time_iso_8601": "2023-08-28T08:13:13.738482Z",
            "url": "https://files.pythonhosted.org/packages/63/10/f70e032d6cf060c3b1acb4ee517b8fde1643ab34ecbf1862c614e23b5ffd/prosemirror-py-converter-0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-28 08:13:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ghnjk",
    "github_project": "prosemirror-py-converter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "prosemirror-py-converter"
}
        
Elapsed time: 0.14973s