# 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:
```bash
pip install mark-json
```
## Basic Usage
Basic conversion example:
```python
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
```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
```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](LICENSE).
Raw data
{
"_id": null,
"home_page": "https://github.com/marcmarine/mark-json",
"name": "mark-json",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "markdown md json parser syntax tree",
"author": "Marc Marin\u00e9",
"author_email": "shenobi@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/97/79/e13cd7d7128598c7b431890e7aca394f09e3698f452ea34868e59ae822e1/mark_json-0.1.1.tar.gz",
"platform": null,
"description": "# Mark Json\n\nThe **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.\n\n## Installation\n\nInstall the library using pip:\n\n```bash\npip install mark-json\n```\n\n## Basic Usage\n\nBasic conversion example:\n\n```python\nfrom mark_json import from_mark\n\nwith open('file.md', 'r', encoding='utf-8') as f:\n markdown_content = f.read()\n\njson = from_mark(markdown_content)\n\nprint(json)\n```\n\n## Conversion Rules\n\n### Frontmatter\n\nThe Markdown document MUST start with a frontmatter block that includes:\n\n- **Title**: The title of the document.\n\n- **Author**: The author of the document.\n\n- **Language**: The language of the document.\n\n- **Translator**: The translator of the document (if applicable).\n\n- **Date**: The publication or creation date of the document.\n\n### Sections and content\n\nIn 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.\n\nContent 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.\n\n## Example Conversion\n\n### Markdown\n\n```markdown\n---\ntitle: The Pathway of Life\nauthor: Leo Tolstoy\nlanguage: en\ntranslator: Archibald J. Wolfe\ndate: 1919-01-01\n---\n\n# The Pathway of Life\n\n## Force\n\nOne of the main causes of human misery is the erroneous idea that some men may by force order or improve the life of others.\n\n### The Inefficiency of Force\n\nThe 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.\n\n_Pascal_\n```\n\n### JSON\n\n```json\n{\n \"title\": \"The Pathway of Life\",\n \"author\": \"Leo Tolstoy\",\n \"language\": \"en\",\n \"translator\": \"Archibald J. Wolfe\",\n \"date\": \"1919-01-01\",\n \"sections\": [\n {\n \"depth\": 1,\n \"title\": \"The Pathway of Life\",\n \"content\": null,\n \"position\": 1\n },\n {\n \"depth\": 2,\n \"title\": \"Force\",\n \"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.\",\n \"position\": 2\n },\n {\n \"depth\": 3,\n \"title\": \"The Inefficiency of Force\",\n \"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_\",\n \"position\": 3\n }\n ]\n}\n```\n\n## Contributions\n\nOpen an issue or submit a pull request for suggestions or improvements.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n",
"bugtrack_url": null,
"license": "LICENSE",
"summary": "Converts Markdown to a structured JSON format, ideal for long documents",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/marcmarine/mark-json"
},
"split_keywords": [
"markdown",
"md",
"json",
"parser",
"syntax",
"tree"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "dfc0a52df9539f7461a19f94833ab2d25ff81d451cbf471328ffd0bb92eebda3",
"md5": "037deabb55a765cdb9185aad080c8d33",
"sha256": "b8ac9cc8759c9f197818a2220ac6ffa9b309f781767915f649f05b2dee8e21c0"
},
"downloads": -1,
"filename": "mark_json-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "037deabb55a765cdb9185aad080c8d33",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 3923,
"upload_time": "2024-08-31T17:51:49",
"upload_time_iso_8601": "2024-08-31T17:51:49.470356Z",
"url": "https://files.pythonhosted.org/packages/df/c0/a52df9539f7461a19f94833ab2d25ff81d451cbf471328ffd0bb92eebda3/mark_json-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9779e13cd7d7128598c7b431890e7aca394f09e3698f452ea34868e59ae822e1",
"md5": "a0f51704654e657e3d4fffefc20de84a",
"sha256": "d0d6e59af65bc1e9a3331b9aec33bbe4b2a81bd6cb62fae722db06d2245bafac"
},
"downloads": -1,
"filename": "mark_json-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "a0f51704654e657e3d4fffefc20de84a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3660,
"upload_time": "2024-08-31T17:51:50",
"upload_time_iso_8601": "2024-08-31T17:51:50.919486Z",
"url": "https://files.pythonhosted.org/packages/97/79/e13cd7d7128598c7b431890e7aca394f09e3698f452ea34868e59ae822e1/mark_json-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-31 17:51:50",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "marcmarine",
"github_project": "mark-json",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "mark-json"
}