0.0.15 • Published 8 months ago

@memochou1993/json2markdown v0.0.15

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

JSON2Markdown

A simple JSON to Markdown converter that transforms JSON data into Markdown format. It can be used for transforming structured data into a readable format.

Demo

JSON2Markdown Renderer

Getting Started

Using with ES Modules

To get started with ES Modules, simply import the module and use it in your code:

import { Converter } from '@memochou1993/json2markdown';

const output = Converter.toMarkdown({
  'Hello, World!': 'It works!',
});

// Output:
// # Hello, World!\n\nIt works!\n\n

Using with UMD Modules

Alternatively, if you're using UMD modules, include the script in your HTML file and use it in your code:

<script src="https://unpkg.com/@memochou1993/json2markdown/dist/index.umd.js"></script>
<script>
const output = window.JSON2Markdown.Converter.toMarkdown({
  'Hello, World!': 'It works!',
});

// Output:
// # Hello, World!\n\nIt works!\n\n
</script>

Usage

Basic Usage

The Converter can be initialized with either a JSON string or an object, where both the keys and values will be converted into Markdown elements.

const converter = new Converter({
  'Hello, World!': 'It works!',
});

const output = converter.toMarkdown();

// Output:
// # Hello, World!\n\nIt works!\n\n

Callback Function

The callback function in the toMarkdown method allows you to transform generated Markdown elements during the conversion process. It is called for each element, giving you the opportunity to modify its properties before returning it.

const converter = new Converter({
  'Hello, World!': 'It works!',
});

const output = converter.toMarkdown((element) => {
  if (element.tag === 'heading') {
    element.level += 1;
  }
  return element;
});

// Output:
// ## Hello, World!\n\nIt works!\n\n

Available Tags

NameDescription
ARepresents an anchor (a) tag.
BRRepresents a line break (br) tag.
HEADINGRepresents a heading (heading) tag.
IMGRepresents an image (img) tag.
LIRepresents a list item (li) tag.
PRepresents a paragraph (p) tag.
PRERepresents a preformatted text (pre) tag.
TDRepresents table data (td) tag.
TRRepresents a table row (tr) tag.

Development

To start a local development server, run:

npm run dev

Testing

To run the tests for this package, run:

npm run test
0.0.10

10 months ago

0.0.11

10 months ago

0.0.12

10 months ago

0.0.13

10 months ago

0.0.14

10 months ago

0.0.15

8 months ago

0.0.9

10 months ago

0.0.8

11 months ago

0.0.5

11 months ago

0.0.4

11 months ago

0.0.7

11 months ago

0.0.6

11 months ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago