Socket
Socket
Sign inDemoInstall

@jwerre/markdown_to_array

Package Overview
Dependencies
12
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @jwerre/markdown_to_array

Convert markdown text to a simplified DOM array. Previously markdown_to_html


Version published
Weekly downloads
2
increased by100%
Maintainers
1
Install size
1.06 MB
Created
Weekly downloads
 

Readme

Source

Markdown to Array

Convert markdown text to a simplified DOM array.

Install

npm install --save @jwerre/markdown_to_array
NOTE: use @jwerre/markdown_to_array instead of markdown_to_array

Example


MdToArray = require('markdown_to_array')
const md = `\
This is *italics* and this is **bold**.

- list item 1
- list item 2
- list item 3

Here is a [hyperlink](https://example.com)!

Here are some **images**: ![some alt text](https://example.com/img1.png)

![](https://example.com/img2.png)`;

const mdDom = new MdToArray(md);
const parsed = mdDom.parse();
console.log(parsed);
Result:
[
  [
    { text: 'This is ', tag: 'P', P: true },
    { text: 'italics', tag: 'EM', EM: true },
    { text: ' and this is ', tag: 'P', P: true },
    { text: 'bold', tag: 'STRONG', STRONG: true },
    { text: '.', tag: 'P', P: true }
  ],
  [
    { text: 'list item 1', tag: 'LI', LI: true },
    { text: 'list item 2', tag: 'LI', LI: true },
    { text: 'list item 3', tag: 'LI', LI: true }
  ],
  [
    { text: 'Here is a ', tag: 'P', P: true },
    {
      text: 'hyperlink',
      tag: 'A',
      A: true,
      href: 'https://example.com'
    },
    { text: '!', tag: 'P', P: true }
  ],
  [
    { text: 'Here are some ', tag: 'P', P: true },
    { text: 'images', tag: 'STRONG', STRONG: true },
    { text: ': ', tag: 'P', P: true },
    {
      tag: 'IMG',
      IMG: true,
      src: 'https://example.com/img1.png',
      alt: 'some alt text'
    }
  ],
  [
    {
      tag: 'IMG',
      IMG: true,
      src: 'https://example.com/img2.png',
      alt: ''
    }
  ]
]

Keywords

FAQs

Last updated on 18 Feb 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc