Skip to main content

Lossy python to markdown serializer

Project description

markpickle

Lossy serialization of markdown to simple python data types and back. It will create predictable markdown from a python object, but can't turn all markdown files into sensible python objects (for that use a markdown library that creates an AST). I created this because I wanted a way to turn json into Markdown.

For example this

- 1
- 2

becomes the python list [1, 2]

Libraries.io dependency status for latest release Downloads

Installation

pip install markpickle

Capabilities

This is a lossy serialization. Markdown is missing too many concepts to make a high fidelity representation of a python data structure. If you want an object model that faithfully represents each object in a Markdown document, use the AST of mistune or one of the other markdown parsers.

Supported types

  • Scalar values
  • Lists of scalar values
  • Dictionaries with scalar values
  • Lists of dictionaries of scalar values
  • Dictionaries with list values
  • Partial support for blanks/string with leading/trailing whitespace

Not supported

  • Things not ordinarily serializable
  • Markdown that uses more than headers, lists, tables

Serializing

Almost all markdown libraries use it as intended, as a way to generate HTML fragments from untrusted sources for insertion into some other HTML template.

Deserializing

Markdown is deserialized by parsing the document to an abstract syntax tree. This is done by mistune. If the markdown file has the same structure that markpickle uses, then it will create a sensible object. Deserializing a random README.md file is not expected to always work. For that you should use mistune's AST.

Round Tripping

Some but not all data structures will be round-trippable. The goal is that the sort of dicts you get from loading JSON will be round-trippable, provided everything is a string.

Prior Art

People normally want to convert json to markdown. Json looks like python dict, so if you can do that you can probably do both.

Serializing to Markdown

json2md, a node package, will turn json that looks like the HTML document object model into markdown, e.g.

{"h1": "Some Header",
 "p": "Some Text"}

tomark will turn dict into a markdown table. Unmaintained.

pytablewriter also, dict to table, but supports many tabular formats.

Deserializing to Python

I don't know of any libraries that turn markdown into basic python types. At the moment, they all turn markdown into document object model.

mistune will turn markdown into an Abstract Syntax Tree. The AST is faithful representation of the Markdown, including concepts that have no semantic equivalent to python datatypes.

beautifulsoup will let you navigate the HTML DOM. So you can turn the markdown into HTML, then parse with Beautiful Soup.

Documentation

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

markpickle-1.0.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

markpickle-1.0.0-py2.py3-none-any.whl (9.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file markpickle-1.0.0.tar.gz.

File metadata

  • Download URL: markpickle-1.0.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for markpickle-1.0.0.tar.gz
Algorithm Hash digest
SHA256 84d25332f1f956b87701492e6e017b87332f589e45d4ffadbcfa346bc3c7e3c6
MD5 00f99e6258ebf940b631d6e8c654b03b
BLAKE2b-256 b67077837b86e184b098e6a34ddf3b6c0d9974e78c80eb62eeb05c625210a665

See more details on using hashes here.

File details

Details for the file markpickle-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: markpickle-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for markpickle-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 20ae0cb2fa449e6231824de463f5e3c161d72820f75eeb652b66c3c655539ee7
MD5 5b9aa1e9cf7a57f781be7b31cd77b717
BLAKE2b-256 851ce4b825d9b65245c617e55011746fa992997af95e8d9d9e65aecb4da60339

See more details on using hashes here.

Supported by

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