Python simple implementation of converting ProseMirror doc to markdown
Project description
prosemirror-py-converter
Python simple implementation of converting ProseMirror doc to markdown
Core features
- Based on ProseMirror basic 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
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
- 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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file prosemirror-py-converter-0.3.tar.gz
.
File metadata
- Download URL: prosemirror-py-converter-0.3.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 650be9881beea21e9ac079dfcdad16c8000339906f9024a92a995b1a67be4283 |
|
MD5 | 8d24f55103fe94665bac4e24c58bdb6b |
|
BLAKE2b-256 | 6310f70e032d6cf060c3b1acb4ee517b8fde1643ab34ecbf1862c614e23b5ffd |
File details
Details for the file prosemirror_py_converter-0.3-py3-none-any.whl
.
File metadata
- Download URL: prosemirror_py_converter-0.3-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2395eb34bb67a7da44443d89755cd3b7d6b74b615c67b9e2c0187d5056164e84 |
|
MD5 | ae745899044c7c249607c958ff26568c |
|
BLAKE2b-256 | c2555885cf8bf51245228b4b90fa9e06a926736d6ab4b00c2dfa0619136deabe |