New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

md2js-loader

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

md2js-loader

Exports Markdown to javascript instructions. Create javascript functions from Markdown templates.

latest
Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

md2js-loader

Exports Markdown to javascript instructions. Create javascript functions from Markdown templates.

GitHub license GitHub issues Twitter

Install

npm i -D md2js-loader

Usage

Add the md2js-loader to your webpack.config.js.

{
  test: /\.(markdown|md)$/,
  use: {
    loader: 'md2js-loader',
    options: {}
  }
}

Now, simply import/require any markdown files. For example:

Example
=======

- 1
- 2
- 3
- 4
const createList = require('./templates/list.markdown');

document.body.appendChild(createList());

this will be converted to the following javascript:

function createNode() {
    var container = document.createDocumentFragment();
    var e_0 = document.createElement("div");
    var e_1 = document.createElement("h1");
    e_1.setAttribute("id", "example");
    e_1.appendChild(document.createTextNode("Example"));
    e_0.appendChild(e_1);
    var e_2 = document.createElement("ul");
    var e_3 = document.createElement("li");
    e_3.appendChild(document.createTextNode("1"));
    e_2.appendChild(e_3);
    var e_4 = document.createElement("li");
    e_4.appendChild(document.createTextNode("2"));
    e_2.appendChild(e_4);
    var e_5 = document.createElement("li");
    e_5.appendChild(document.createTextNode("3"));
    e_2.appendChild(e_5);
    var e_6 = document.createElement("li");
    e_6.appendChild(document.createTextNode("4"));
    e_2.appendChild(e_6);
    e_0.appendChild(e_2);
    container.appendChild(e_0);
    return container;
}

The loader will optimize this code by injecting the following base code into your bundle:

module.exports = {
    document_createDocumentFragment: () => {
        return document.createDocumentFragment();
    },
    document_createElement: name => {
        return document.createElement(name);
    },
    document_createTextNode: text => {
        return document.createTextNode(text);
    },
    appendChild: (parent, child) => {
        parent.appendChild(child);
    },
    setAttribute: (elem, key, value) => {
        elem.setAttribute(key, value);
    }
};

This will enable the compiler to name mangle these function calls.

Keywords

markdown

FAQs

Package last updated on 19 Dec 2018

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