Skip to main content

Converts Markdown to a structured JSON format, ideal for long documents

Project description

Mark Json

The Mark Json library is a markdown to JSON converter that transforms Markdown documents into a structured JSON format, ideal for working with long documents like books.

Installation

Install the library using pip:

pip install mark-json

Basic Usage

Basic conversion example:

from mark_json import from_mark

with open('file.md', 'r', encoding='utf-8') as f:
  markdown_content = f.read()

json = from_mark(markdown_content)

print(json)

Conversion Rules

Frontmatter

The Markdown document MUST start with a frontmatter block that includes:

  • Title: The title of the document.

  • Author: The author of the document.

  • Language: The language of the document.

  • Translator: The translator of the document (if applicable).

  • Date: The publication or creation date of the document.

Sections and content

In the conversion process, each markdown heading represents a section within the document. The depth of each section is determined by the level of the heading.

Content that appears immediately below each heading is considered part of that section. This content is preserved as string in Markdown format in the content field of the section object.

Example Conversion

Markdown

---
title: The Pathway of Life
author: Leo Tolstoy
language: en
translator: Archibald J. Wolfe
date: 1919-01-01
---

# The Pathway of Life

## Force

One of the main causes of human misery is the erroneous idea that some men may by force order or improve the life of others.

### The Inefficiency of Force

The fact that it is possible to make men amenable to justice by the use of force, does not yet prove that it is just to subject people to force.

_Pascal_

JSON

{
  "title": "The Pathway of Life",
  "author": "Leo Tolstoy",
  "language": "en",
  "translator": "Archibald J. Wolfe",
  "date": "1919-01-01",
  "sections": [
    {
      "depth": 1,
      "title": "The Pathway of Life",
      "content": null,
      "position": 1
    },
    {
      "depth": 2,
      "title": "Force",
      "content": "One of the main causes of human misery is the erroneous idea that some men may by force order or improve the life of others.",
      "position": 2
    },
    {
      "depth": 3,
      "title": "The Inefficiency of Force",
      "content": "The fact that it is possible to make men amenable to justice by the use of force, does not yet prove that it is just to subject people to force. _Pascal_",
      "position": 3
    }
  ]
}

Contributions

Open an issue or submit a pull request for suggestions or improvements.

License

This project is licensed under the MIT License.

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

mark_json-0.1.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

mark_json-0.1.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file mark_json-0.1.1.tar.gz.

File metadata

  • Download URL: mark_json-0.1.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for mark_json-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d0d6e59af65bc1e9a3331b9aec33bbe4b2a81bd6cb62fae722db06d2245bafac
MD5 a0f51704654e657e3d4fffefc20de84a
BLAKE2b-256 9779e13cd7d7128598c7b431890e7aca394f09e3698f452ea34868e59ae822e1

See more details on using hashes here.

File details

Details for the file mark_json-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mark_json-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for mark_json-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b8ac9cc8759c9f197818a2220ac6ffa9b309f781767915f649f05b2dee8e21c0
MD5 037deabb55a765cdb9185aad080c8d33
BLAKE2b-256 dfc0a52df9539f7461a19f94833ab2d25ff81d451cbf471328ffd0bb92eebda3

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