Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/balmacefa/md_metadata_parser
md metada parser, tree node model
https://github.com/balmacefa/md_metadata_parser
Last synced: about 2 months ago
JSON representation
md metada parser, tree node model
- Host: GitHub
- URL: https://github.com/balmacefa/md_metadata_parser
- Owner: balmacefa
- License: mit
- Created: 2020-12-23T02:26:05.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-01-04T00:56:47.000Z (about 4 years ago)
- Last Synced: 2024-10-19T21:01:00.073Z (3 months ago)
- Language: JavaScript
- Size: 282 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# md_metadata_parser [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
> md YAML metada parser## Motivation
md_metadata_parser insert [YAML](https://github.com/eemeli/yaml) metadata as Markdown comment.You can hide metadata to the render consumer, and use the same .md file to store data for later processing - consumption.
md_metadata_parser can parse from md to json and vice versa.
# Table of contents
* [Installation](#installation)
* [Usage](#usage)
- [Example](#example)
- [API](#api)
* [`parseMd2Json({'mdData', ...});`](#-parsemd2json---mddata-------)
* [`parseJson2Md({'json', ...});`](#-parsejson2md---json-------)
- [Structure](#structure)
* [1. Node tag](#1-node-tag)
* [2. Metadata tag](#2-metadata-tag)
* [3. Content tag](#3-content-tag)
* [4. Children tag](#4-children-tag)
* [md structure example](#md-structure-example)
* [json (parsed from md👆) structure example](#json--parsed-from-md----structure-example)
* [License](#license)Table of contents generated with markdown-toc
## Installation
```sh
$ npm install --save md_metadata_parser
```## Usage
```js
const mdMetadataParser = require('md_metadata_parser');var mdData = fs.readFileSync("md_path.md", "utf8");
// parse the md file to json object
var resultTree = mdMetadataParser.parseMd2Json({ mdData });// parse the json object to md
var outputMD = mdMetadataParser.parseJson2Md({ rootNode: resultTree });
```# Example
See https://github.com/balmacefa/md_metadata_parser/blob/main/test/index.test.js
# API
## `parseMd2Json({'mdData', ...});`
parse the md data to json format| Option | Default value | Description |
| ------ | ------------- | ----------- |
| `mdData` | null | The md data to be parse |
| `startFormatNode` | ```` | Open node tag
| `endFormatNode` | ```` | Close node tag
| `startFormatMetadata` | ```` | Close metadata tag
| `startFormatContent` | ```` | Open content tag
| `endFormatContent` | ```` | Close content tag
| `startFormatChildren` | ```` | Open children tag
| `endFormatChildren` | ```` | Close children tag## `parseJson2Md({'json', ...});`
parse the md data to json format| Option | Default value | Description |
| ------ | ------------- | ----------- |
| `json` | null | (JSON object) The json data to be parse |
| `startFormatNode` | ```` | Open node tag
| `endFormatNode` | ```` | Close node tag
| `startFormatMetadata` | ```` | Close metadata tag
| `startFormatContent` | ```` | Open content tag
| `endFormatContent` | ```` | Close content tag
| `startFormatChildren` | ```` | Open children tag
| `endFormatChildren` | ```` | Close children tag# Structure
There are 4 tags for describe the data Structure
## 1. Node tag
md: ``This will be the **json object** container, all the others tags have to be inside,
> Everything outside will be ignored.md: ``
## 2. Metadata tag
md: ``## 3. Content tag
md: ``This the render md content
json attribute: "content"
md: ``
## 4. Children tag
md: ``Array of **Node tag** ( recursive )
json attribute: "children"
md: ``
# Structure example
## md
```# Content 1
Content 1
Content 1a
## Content 2
Content 2```
## json
(parsed from md👆)
```
[
{
"metadata": {
"id": 1,
"description": 1111,
},
"content": "# Content 1\nContent 1",
"children": [
{
"metadata": { "id": "01a", "description": "1a" },
"content": "Content 1a"
}
]
},
{
"metadata": { "id": 2, "description": 2222 },
"content": "## Content 2\nContent 2"
},
]
```
## LicenseMIT © [balmacefa](https://github.com/balmacefa)
[npm-image]: https://badge.fury.io/js/md_metadata_parser.svg
[npm-url]: https://npmjs.org/package/md_metadata_parser
[travis-image]: https://travis-ci.com/balmacefa/md_metadata_parser.svg?branch=master
[travis-url]: https://travis-ci.com/balmacefa/md_metadata_parser
[daviddm-image]: https://david-dm.org/balmacefa/md_metadata_parser.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/balmacefa/md_metadata_parser