Skip to main content

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

iwiki doc converter

  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prosemirror-py-converter-0.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

prosemirror_py_converter-0.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file prosemirror-py-converter-0.1.tar.gz.

File metadata

File hashes

Hashes for prosemirror-py-converter-0.1.tar.gz
Algorithm Hash digest
SHA256 0b4cc37a9f40f01adc3dc53ea516a1e54e76ae15a02966771192be55d086d3f8
MD5 7ff4b31d10ad9913bdc44fff5236917f
BLAKE2b-256 8458fb43f57bbd1cd7c180df27e7dc339eee84af5cf6ea6c7eb455ac1ddca653

See more details on using hashes here.

File details

Details for the file prosemirror_py_converter-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for prosemirror_py_converter-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1387c10d94236212c8aadaf3e87063828bfaa98b2d62a9234210f9f35d5dbd25
MD5 3238e0f98677b7891672ec529f660102
BLAKE2b-256 707b5b6ff73733d26c6110952edebe46e5324cec5b5132472412616a9600edca

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page