Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mark-json

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mark-json

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

  • 0.1.1
  • PyPI
  • Socket score

Maintainers
1

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.

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc