0.7.1 • Published 6 years ago

@dumpster/remark-custom-element-to-hast v0.7.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

remark-custom-element-to-hast

npm version

Compile markdown file that contain calls to custom elements into a simplified HAST using remark. The output HAST may later be transformed into react element for example.

Example of usage

const beautify = require("json-beautify");
const unified = require('unified');
const parseMD = require('remark-parse');
const customElementCompiler = require('@dumpster/remark-custom-element-to-hast');

const processor = unified()
  .use(parseMD)
  .use(customElementCompiler, {componentWhitelist: ['MyStuff', 'MyOtherStuff']})
  .process('## Hello world!\n<MyStuff name="Hello">World<MyOtherStuff /></MyStuff>', function (err, file) {
    console.log(beautify(file.contents, null, 2, 100));
  });

The above example will output:

{
  "type": "root",
  "children": [
    {
      "type": "element",
      "tagName": "h2",
      "properties": {},
      "children": [ { "type": "text", "value": "Hello world!" } ]
    },
    { "type": "text", "value": "\n" },
    {
      "type": "element",
      "tagName": "MyStuff",
      "properties": { "name": "Hello" },
      "children": [
        { "type": "text", "value": "World" },
        { "type": "element", "tagName": "MyOtherStuff", "properties": {}, "children": [] }
      ]
    }
  ]
}
0.7.1

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.8

6 years ago

0.5.7

6 years ago

0.5.6

6 years ago

0.5.5

6 years ago

0.5.4

6 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago